13 #include <sys/utsname.h> 35 perror(
"Could not allocate memory for the trace header!");
41 perror(
"Could not use uname()!");
49 "%s %s %s %s %s", uts.sysname, uts.nodename, uts.release, uts.version,
58 char* filename = strrchr(trace->
filename,
'/');
86 perror(
"Could not allocate memory for the trace!");
97 char* str = getenv(
"LITL_BUFFER_SIZE");
108 perror(
"Could not allocate memory for the threads!");
116 perror(
"Could not allocate memory for a thread\n");
129 assert(pthread_key_create(&trace->
index, NULL ) == 0);
134 str = getenv(
"LITL_BUFFER_FLUSH");
136 if(strcmp(str,
"0") == 0)
145 str = getenv(
"LITL_THREAD_SAFETY");
146 if (str && (strcmp(str,
"0") == 0))
156 str = getenv(
"LITL_TID_RECORDING");
157 if (str && (strcmp(str,
"0") == 0))
247 "Warning: changing the trace file name to %s after some events have been saved in file %s\n",
253 if (filename == NULL )
254 sprintf(filename,
"/tmp/%s_%s", getenv(
"USER"),
"litl_log_1");
256 if (asprintf(&trace->
filename,
"%s", filename) == -1) {
257 perror(
"Error: Cannot set the filename for recording events!\n");
284 if ((trace->
f_handle = open(trace->
filename, O_WRONLY | O_CREAT | O_EXCL, 0644))
287 if(errno == EEXIST) {
290 perror(
"Cannot delete trace file");
293 if ((trace->
f_handle = open(trace->
filename, O_WRONLY | O_CREAT | O_EXCL, 0644))
295 perror(
"Cannot open trace file");
299 fprintf(stderr,
"Cannot open %s\n", trace->
filename);
311 lseek(trace->
f_handle, 0, SEEK_SET);
314 __litl_write_get_header_size(trace)) == -1) {
316 "Flushing the buffer. Could not write measured data to the trace file!");
328 __litl_open_new_file(trace);
334 __litl_write_add_trace_header(trace);
345 trace->
buffers[i]->
offset = __litl_write_get_header_size(trace)
357 thread_pair->
tid = 0;
361 __litl_write_update_header(trace);
447 int res __attribute__ ((__unused__));
457 __litl_write_flush_header(trace);
463 __litl_write_flush_thread_header(trace, index, header_size);
465 __litl_write_update_thread_header(trace, index, header_size);
469 __litl_write_probe_offset(trace, index);
472 __litl_write_get_buffer_size(trace, index)) == -1) {
474 "Flushing the buffer. Could not write measured data to the trace file!");
479 trace->
general_offset += __litl_write_get_buffer_size(trace, index);
502 pthread_setspecific(trace->
index, pos);
511 perror(
"LiTL failed to reallocate memory for threads!\n");
521 perror(
"Could not allocate memory for a thread\n!");
539 perror(
"Could not allocate memory buffer for the thread\n!");
565 __litl_write_allocate_buffer(trace);
566 p_index = pthread_getspecific(trace->
index);
573 litl_size_t used_memory= __litl_write_get_buffer_size(trace, index);
575 if (used_memory+event_size < trace->buffer_size) {
581 cur_ptr->
code = code;
582 cur_ptr->
type = type;
598 fprintf(stderr,
"Unknown event type %d\n", type);
608 __litl_write_flush_buffer(trace, index);
629 unsigned nb_params) {
641 litl_t *cur_ptr = __litl_write_probe_reg_common(trace, code, 0);
650 litl_t *cur_ptr = __litl_write_probe_reg_common(trace, code, 1);
662 litl_t *cur_ptr = __litl_write_probe_reg_common(trace, code, 2);
676 litl_t *cur_ptr = __litl_write_probe_reg_common(trace, code, 3);
691 litl_t *cur_ptr = __litl_write_probe_reg_common(trace, code, 4);
708 litl_t *cur_ptr = __litl_write_probe_reg_common(trace, code, 5);
726 litl_t *cur_ptr = __litl_write_probe_reg_common(trace, code, 6);
746 litl_t *cur_ptr = __litl_write_probe_reg_common(trace, code, 7);
767 litl_t *cur_ptr = __litl_write_probe_reg_common(trace, code, 8);
790 litl_t *cur_ptr = __litl_write_probe_reg_common(trace, code, 9);
814 litl_t *cur_ptr = __litl_write_probe_reg_common(trace, code, 10);
842 for (i = 0; i < size; i++) {
859 __litl_write_flush_buffer(trace, i);
struct litl_t::@0::@1 regular
litl_t * 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.
litl_type_t
The enumeration of event types.
struct litl_t::@0::@2 raw
litl_data_t is_buffer_full
#define LITL_MAX_PARAMS
Defines the maximum number of parameters.
void litl_write_buffer_flush_on(litl_write_trace_t *trace)
Enable buffer flush. By default, it is disabled.
litl_write_buffer_t ** buffers
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)
Enable thread safety.
litl_t * 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.
volatile litl_data_t is_recording_paused
litl_t * 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.
void litl_write_thread_safety_off(litl_write_trace_t *trace)
Disable thread safety. By default, it is enabled.
#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.
litl_t * 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_t * 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.
litl_size_t header_offset
litl_size_t nb_allocated_buffers
A data structure for recording events.
litl_data_t allow_thread_safety
litl_t * 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_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_t * 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.
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)
Disable recording tid. By default, it is enabled.
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 param_size)
For internal use only. Allocates an event.
litl_t * 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.
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.
litl_t * 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.
#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_resume_recording(litl_write_trace_t *trace)
Resumes the event recording.
struct litl_t::@0::@3 packed
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.
litl_t * 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.
litl_t * 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 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)
Enable recording tid.
void litl_write_buffer_flush_off(litl_write_trace_t *trace)
Disable buffer flush.
litl_t * litl_write_probe_reg_0(litl_write_trace_t *trace, litl_code_t code)
Records a regular event without parameters.
void litl_write_pause_recording(litl_write_trace_t *trace)
Pauses the event recording.
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