13 #include <sys/utsname.h>
36 perror(
"Could not allocate memory for the trace header!");
42 perror(
"Could not use uname()!");
50 "%s %s %s %s %s", uts.sysname, uts.nodename, uts.release, uts.version,
59 char* filename = strrchr(trace->
filename,
'/');
87 perror(
"Could not allocate memory for the trace!");
98 char* str = getenv(
"LITL_BUFFER_SIZE");
109 perror(
"Could not allocate memory for the threads!");
117 perror(
"Could not allocate memory for a thread\n");
130 assert(pthread_key_create(&trace->
index, NULL ) == 0);
135 str = getenv(
"LITL_BUFFER_FLUSH");
137 if(strcmp(str,
"0") == 0)
146 str = getenv(
"LITL_THREAD_SAFETY");
147 if (str && (strcmp(str,
"0") == 0))
157 str = getenv(
"LITL_TID_RECORDING");
158 if (str && (strcmp(str,
"0") == 0))
248 "Warning: changing the trace file name to %s after some events have been saved in file %s\n",
254 if (filename == NULL )
255 sprintf(filename,
"/tmp/%s_%s", getenv(
"USER"),
"litl_log_1");
257 if (asprintf(&trace->
filename,
"%s", filename) == -1) {
258 perror(
"Error: Cannot set the filename for recording events!\n");
285 if ((trace->
f_handle = open(trace->
filename, O_WRONLY | O_CREAT | O_EXCL, 0644))
288 if(errno == EEXIST) {
291 perror(
"Cannot delete trace file");
294 if ((trace->
f_handle = open(trace->
filename, O_WRONLY | O_CREAT | O_EXCL, 0644))
296 perror(
"Cannot open trace file");
300 fprintf(stderr,
"Cannot open %s\n", trace->
filename);
312 lseek(trace->
f_handle, 0, SEEK_SET);
315 __litl_write_get_header_size(trace)) == -1) {
317 "Flushing the buffer. Could not write measured data to the trace file!");
329 __litl_open_new_file(trace);
335 __litl_write_add_trace_header(trace);
346 trace->
buffers[i]->
offset = __litl_write_get_header_size(trace)
358 thread_pair->
tid = 0;
362 __litl_write_update_header(trace);
448 int res __attribute__ ((__unused__));
458 __litl_write_flush_header(trace);
464 __litl_write_flush_thread_header(trace, index, header_size);
466 __litl_write_update_thread_header(trace, index, header_size);
470 __litl_write_probe_offset(trace, index);
473 __litl_write_get_buffer_size(trace, index)) == -1) {
475 "Flushing the buffer. Could not write measured data to the trace file!");
480 trace->
general_offset += __litl_write_get_buffer_size(trace, index);
503 int thread_id = *pos;
504 pthread_setspecific(trace->
index, pos);
513 perror(
"LiTL failed to reallocate memory for threads!\n");
523 perror(
"Could not allocate memory for a thread\n!");
546 int mmap_flags = MAP_SHARED|MAP_ANONYMOUS;
550 mmap_flags |= MAP_POPULATE;
555 PROT_READ|PROT_WRITE,
565 if(length> 1024*1024)
576 perror(
"Could not allocate memory buffer for the thread\n!");
604 __litl_write_allocate_buffer(trace);
605 p_index = pthread_getspecific(trace->
index);
617 litl_size_t used_memory= __litl_write_get_buffer_size(trace, index);
619 if (used_memory+event_size < trace->buffer_size) {
625 cur_ptr->
code = code;
626 cur_ptr->
type = type;
642 fprintf(stderr,
"Unknown event type %d\n", type);
652 __litl_write_flush_buffer(trace, index);
673 unsigned nb_params) {
685 litl_t *cur_ptr = __litl_write_probe_reg_common(trace, code, 0);
694 litl_t *cur_ptr = __litl_write_probe_reg_common(trace, code, 1);
706 litl_t *cur_ptr = __litl_write_probe_reg_common(trace, code, 2);
720 litl_t *cur_ptr = __litl_write_probe_reg_common(trace, code, 3);
735 litl_t *cur_ptr = __litl_write_probe_reg_common(trace, code, 4);
752 litl_t *cur_ptr = __litl_write_probe_reg_common(trace, code, 5);
770 litl_t *cur_ptr = __litl_write_probe_reg_common(trace, code, 6);
790 litl_t *cur_ptr = __litl_write_probe_reg_common(trace, code, 7);
811 litl_t *cur_ptr = __litl_write_probe_reg_common(trace, code, 8);
834 litl_t *cur_ptr = __litl_write_probe_reg_common(trace, code, 9);
858 litl_t *cur_ptr = __litl_write_probe_reg_common(trace, code, 10);
886 for (i = 0; i < size; i++) {
903 __litl_write_flush_buffer(trace, i);
void litl_time_initialize()
Initializes the timing mechanism.
litl_timing_method_t litl_get_time
Calls the selected timing method and get the current time in ns.
#define LITL_OFFSET_CODE
Defines the code of an event of type offset.
uint64_t litl_param_t
A data type for the non-optimized storage of parameters.
litl_type_t
The enumeration of event types.
uint8_t litl_data_t
A data type for the optimized storage of parameters.
uint32_t litl_size_t
An auxiliary data type for storing data.
uint8_t * litl_buffer_t
A data type for storing sets of events.
#define LITL_MAX_PARAMS
Defines the maximum number of parameters.
uint16_t litl_med_size_t
An auxiliary data type for the optimized storage of data.
#define NBTHREADS
Defines the maximum number of threads (pairs of tid and offset) stored in one data slot.
uint64_t litl_tid_t
A data type for storing thread IDs.
uint32_t litl_code_t
A data type for storing events codes.
#define CUR_TID
A current thread ID.
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_pause_recording(litl_write_trace_t *trace)
Pauses the event recording.
void litl_write_buffer_flush_on(litl_write_trace_t *trace)
Enable buffer flush. By default, it is disabled.
void litl_write_finalize_trace(litl_write_trace_t *trace)
Finalizes the trace.
void litl_write_tid_recording_off(litl_write_trace_t *trace)
Disable recording tid. By default, it is enabled.
void litl_write_resume_recording(litl_write_trace_t *trace)
Resumes the event recording.
void litl_write_buffer_flush_off(litl_write_trace_t *trace)
Disable buffer flush.
void litl_write_set_filename(litl_write_trace_t *trace, char *filename)
Sets a new name for the trace file.
void litl_write_thread_safety_on(litl_write_trace_t *trace)
Enable thread safety.
litl_write_trace_t * litl_write_init_trace(const litl_size_t buf_size)
Initializes the trace buffer.
void litl_write_thread_safety_off(litl_write_trace_t *trace)
Disable thread safety. By default, it is enabled.
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_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_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_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.
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_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_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.
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.
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_t * litl_write_probe_reg_0(litl_write_trace_t *trace, litl_code_t code)
Records a regular event without parameters.
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_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.
litl_timer Provides a set of functions for measuring time
litl_write Provides a set of functions for recording events in a trace file
A general structure of LiTL event type.
union litl_t::@0 parameters
struct litl_t::@0::@1 regular
struct litl_t::@0::@2 raw
struct litl_t::@0::@3 packed
A data structure for pairs (tid, offset) stored in the trace header.
litl_data_t already_flushed
A data structure for recording events.
litl_data_t allow_thread_safety
pthread_mutex_t lock_litl_flush
litl_offset_t general_offset
litl_data_t allow_buffer_flush
litl_write_buffer_t ** buffers
litl_data_t is_litl_initialized
litl_param_t threads_offset
litl_data_t is_header_flushed
volatile litl_data_t is_recording_paused
litl_data_t allow_tid_recording
litl_data_t is_buffer_full
litl_size_t nb_allocated_buffers
litl_size_t header_offset
pthread_mutex_t lock_buffer_init
litl_med_size_t nb_threads
litl_med_size_t header_nb_threads