13 #include <sys/utsname.h>
33 perror(
"Could not allocate memory for the trace header!");
39 perror(
"Could not use uname()!");
47 "%s %s %s %s %s", uts.sysname, uts.nodename, uts.release, uts.version,
56 char* filename = strrchr(trace->
filename,
'/');
79 pthread_key_create(&trace->
index, NULL );
91 perror(
"Could not allocate memory for the trace!");
102 char* str = getenv(
"LITL_BUFFER_SIZE");
113 perror(
"Could not allocate memory for the threads!");
121 perror(
"Could not allocate memory for a thread\n");
137 __litl_write_init_var(trace);
139 trace->
index_once = (pthread_once_t) PTHREAD_ONCE_INIT;
144 str = getenv(
"LITL_BUFFER_FLUSH");
145 if (str && (strcmp(str,
"off") == 0))
152 str = getenv(
"LITL_THREAD_SAFETY");
153 if (str && (strcmp(str,
"off") == 0))
164 str = getenv(
"LITL_TID_RECORDING");
165 if (str && (strcmp(str,
"off") == 0))
257 "Warning: changing the trace file name to %s after some events have been saved in file %s\n",
263 if (filename == NULL )
264 sprintf(filename,
"/tmp/%s_%s", getenv(
"USER"),
"litl_log_1");
266 if (asprintf(&trace->
filename,
"%s", filename) == -1) {
267 perror(
"Error: Cannot set the filename for recording events!\n");
297 int res __attribute__ ((__unused__));
310 fprintf(stderr,
"Cannot open %s\n", trace->
filename);
318 __litl_write_add_trace_header(trace);
329 trace->
buffers[i]->
offset = __litl_write_get_header_size(trace)
345 __litl_write_get_header_size(trace)) == -1) {
347 "Flushing the buffer. Could not write measured data to the trace file!");
413 __litl_write_probe_offset(trace, index);
415 __litl_write_get_buffer_size(trace, index)) == -1) {
417 "Flushing the buffer. Could not write measured data to the trace file!");
422 trace->
general_offset += __litl_write_get_buffer_size(trace, index);
445 pthread_setspecific(trace->
index, pos);
454 perror(
"LiTL failed to reallocate memory for threads!\n");
464 perror(
"Could not allocate memory for a thread\n!");
481 perror(
"Could not allocate memory buffer for the thread\n!");
504 __litl_write_allocate_buffer(trace);
505 p_index = pthread_getspecific(trace->
index);
512 if (__litl_write_get_buffer_size(trace, index) < trace->
buffer_size) {
519 cur_ptr->
code = code;
520 cur_ptr->
type = type;
533 fprintf(stderr,
"Unknown event type %d\n", type);
540 __litl_write_flush_buffer(trace, index);
560 if (pthread_getspecific(trace->
index) == NULL )
561 __litl_write_allocate_buffer(trace);
565 if (__litl_write_get_buffer_size(trace, index) < trace->
buffer_size) {
569 cur_ptr->
code = code;
574 __litl_write_flush_buffer(trace, index);
590 if (pthread_getspecific(trace->
index) == NULL )
591 __litl_write_allocate_buffer(trace);
595 if (__litl_write_get_buffer_size(trace, index) < trace->
buffer_size) {
599 cur_ptr->
code = code;
605 __litl_write_flush_buffer(trace, index);
621 if (pthread_getspecific(trace->
index) == NULL )
622 __litl_write_allocate_buffer(trace);
626 if (__litl_write_get_buffer_size(trace, index) < trace->
buffer_size) {
630 cur_ptr->
code = code;
637 __litl_write_flush_buffer(trace, index);
654 if (pthread_getspecific(trace->
index) == NULL )
655 __litl_write_allocate_buffer(trace);
659 if (__litl_write_get_buffer_size(trace, index) < trace->
buffer_size) {
663 cur_ptr->
code = code;
671 __litl_write_flush_buffer(trace, index);
688 if (pthread_getspecific(trace->
index) == NULL )
689 __litl_write_allocate_buffer(trace);
693 if (__litl_write_get_buffer_size(trace, index) < trace->
buffer_size) {
697 cur_ptr->
code = code;
706 __litl_write_flush_buffer(trace, index);
724 if (pthread_getspecific(trace->
index) == NULL )
725 __litl_write_allocate_buffer(trace);
729 if (__litl_write_get_buffer_size(trace, index) < trace->
buffer_size) {
733 cur_ptr->
code = code;
743 __litl_write_flush_buffer(trace, index);
761 if (pthread_getspecific(trace->
index) == NULL )
762 __litl_write_allocate_buffer(trace);
766 if (__litl_write_get_buffer_size(trace, index) < trace->
buffer_size) {
770 cur_ptr->
code = code;
781 __litl_write_flush_buffer(trace, index);
801 if (pthread_getspecific(trace->
index) == NULL )
802 __litl_write_allocate_buffer(trace);
806 if (__litl_write_get_buffer_size(trace, index) < trace->
buffer_size) {
810 cur_ptr->
code = code;
822 __litl_write_flush_buffer(trace, index);
842 if (pthread_getspecific(trace->
index) == NULL )
843 __litl_write_allocate_buffer(trace);
847 if (__litl_write_get_buffer_size(trace, index) < trace->
buffer_size) {
851 cur_ptr->
code = code;
864 __litl_write_flush_buffer(trace, index);
866 param6, param7, param8);
885 if (pthread_getspecific(trace->
index) == NULL )
886 __litl_write_allocate_buffer(trace);
890 if (__litl_write_get_buffer_size(trace, index) < trace->
buffer_size) {
894 cur_ptr->
code = code;
908 __litl_write_flush_buffer(trace, index);
910 param6, param7, param8, param9);
929 if (pthread_getspecific(trace->
index) == NULL )
930 __litl_write_allocate_buffer(trace);
934 if (__litl_write_get_buffer_size(trace, index) < trace->
buffer_size) {
938 cur_ptr->
code = code;
953 __litl_write_flush_buffer(trace, index);
955 param6, param7, param8, param9, param10);
975 if (pthread_getspecific(trace->
index) == NULL )
976 __litl_write_allocate_buffer(trace);
986 if (__litl_write_get_buffer_size(trace, index) < trace->
buffer_size) {
988 cur_ptr->
code = code;
992 for (i = 0; i < size; i++)
998 __litl_write_flush_buffer(trace, index);
1012 __litl_write_flush_buffer(trace, i);
void litl_write_probe_reg_7(litl_write_trace_t *trace, litl_code_t code, litl_param_t param1, litl_param_t param2, litl_param_t param3, litl_param_t param4, litl_param_t param5, litl_param_t param6, litl_param_t param7)
Records a regular event with 7 parameters.
struct litl_t::@0::@1 regular
void litl_write_probe_raw(litl_write_trace_t *trace, litl_code_t code, litl_size_t size, litl_data_t data[])
Records an event with data in a string format.
litl_type_t
The enumeration of event types.
struct litl_t::@0::@2 raw
litl_data_t is_buffer_full
void litl_write_probe_reg_0(litl_write_trace_t *trace, litl_code_t code)
Records a regular event without parameters.
#define LITL_MAX_PARAMS
Defines the maximum number of parameters.
void litl_write_buffer_flush_on(litl_write_trace_t *trace)
Activates buffer flush.
litl_write_buffer_t ** buffers
void litl_write_probe_reg_5(litl_write_trace_t *trace, litl_code_t code, litl_param_t param1, litl_param_t param2, litl_param_t param3, litl_param_t param4, litl_param_t param5)
Records a regular event with 5 parameters.
litl_data_t is_header_flushed
uint64_t litl_param_t
A data type for the non-optimized storage of parameters.
void litl_write_thread_safety_on(litl_write_trace_t *trace)
Activates thread safety.
volatile litl_data_t is_recording_paused
void litl_write_thread_safety_off(litl_write_trace_t *trace)
Deactivates thread safety. By default, it is activated.
#define NBTHREADS
Defines the maximum number of threads (pairs of tid and offset) stored in one data slot...
litl_timing_method_t litl_get_time
Calls the selected timing method and get the current time in ns.
void litl_write_probe_reg_4(litl_write_trace_t *trace, litl_code_t code, litl_param_t param1, litl_param_t param2, litl_param_t param3, litl_param_t param4)
Records a regular event with 4 parameters.
litl_size_t header_offset
litl_size_t nb_allocated_buffers
A data structure for recording events.
litl_data_t allow_thread_safety
litl_data_t is_litl_initialized
litl_write_trace_t * litl_write_init_trace(const litl_size_t buf_size)
Initializes the trace buffer.
A general structure of LiTL event type.
union litl_t::@0 parameters
litl_med_size_t nb_threads
uint8_t * litl_buffer_t
A data type for storing sets of events.
litl_data_t allow_tid_recording
litl_param_t threads_offset
void litl_write_tid_recording_off(litl_write_trace_t *trace)
Deactivates recording tid. By default, it is activated.
void litl_write_probe_reg_2(litl_write_trace_t *trace, litl_code_t code, litl_param_t param1, litl_param_t param2)
Records a regular event with 2 parameters.
void litl_write_probe_reg_8(litl_write_trace_t *trace, litl_code_t code, litl_param_t param1, litl_param_t param2, litl_param_t param3, litl_param_t param4, litl_param_t param5, litl_param_t param6, litl_param_t param7, litl_param_t param8)
Records a regular event with 8 parameters.
litl_offset_t general_offset
void litl_write_finalize_trace(litl_write_trace_t *trace)
Finalizes the trace.
#define CUR_TID
A current thread ID.
litl_t * __litl_write_get_event(litl_write_trace_t *trace, litl_type_t type, litl_code_t code, int size)
For internal use only. Allocates an event.
void litl_write_probe_reg_1(litl_write_trace_t *trace, litl_code_t code, litl_param_t param1)
Records a regular event with 1 parameter.
uint16_t litl_med_size_t
An auxiliary data type for the optimized storage of data.
pthread_mutex_t lock_buffer_init
pthread_mutex_t lock_litl_flush
A data structure for pairs (tid, offset) stored in the trace header.
uint64_t litl_tid_t
A data type for storing thread IDs.
#define LITL_OFFSET_CODE
Defines the code of an event of type offset.
litl_med_size_t header_nb_threads
uint8_t litl_data_t
A data type for the optimized storage of parameters.
void litl_time_initialize()
Initializes the timing mechanism.
void litl_write_probe_reg_3(litl_write_trace_t *trace, litl_code_t code, litl_param_t param1, litl_param_t param2, litl_param_t param3)
Records a regular event with 3 parameters.
void litl_write_resume_recording(litl_write_trace_t *trace)
Resumes the event recording.
struct litl_t::@0::@3 packed
void litl_write_probe_reg_10(litl_write_trace_t *trace, litl_code_t code, litl_param_t param1, litl_param_t param2, litl_param_t param3, litl_param_t param4, litl_param_t param5, litl_param_t param6, litl_param_t param7, litl_param_t param8, litl_param_t param9, litl_param_t param10)
Records a regular event with 10 parameters.
uint32_t litl_size_t
An auxiliary data type for storing data.
void litl_write_set_filename(litl_write_trace_t *trace, char *filename)
Sets a new name for the trace file.
pthread_once_t index_once
litl_data_t already_flushed
litl_data_t allow_buffer_flush
uint64_t litl_offset_t
A data type for storing offsets.
void litl_write_tid_recording_on(litl_write_trace_t *trace)
Activates recording tid.
void litl_write_buffer_flush_off(litl_write_trace_t *trace)
Deactivates buffer flush. By default, it is activated.
void litl_write_pause_recording(litl_write_trace_t *trace)
Pauses the event recording.
void litl_write_probe_reg_9(litl_write_trace_t *trace, litl_code_t code, litl_param_t param1, litl_param_t param2, litl_param_t param3, litl_param_t param4, litl_param_t param5, litl_param_t param6, litl_param_t param7, litl_param_t param8, litl_param_t param9)
Records a regular event with 9 parameters.
void litl_write_probe_reg_6(litl_write_trace_t *trace, litl_code_t code, litl_param_t param1, litl_param_t param2, litl_param_t param3, litl_param_t param4, litl_param_t param5, litl_param_t param6)
Records a regular event with 6 parameters.
uint32_t litl_code_t
A data type for storing events codes.
litl_timer Provides a set of functions for measuring time
litl_write Provides a set of functions for recording events in a trace file