#include <unistd.h>
#include <math.h>
#include <glib.h>
+#include <glib/gprintf.h>
#include <malloc.h>
#include <sys/mman.h>
#include <string.h>
+#include <ctype.h>
+#include <inttypes.h>
// For realpath
#include <limits.h>
#include <ltt/ltt-types.h>
#include <ltt/marker.h>
+/* from marker.c */
+extern long marker_update_fields_offsets(struct marker_info *info, const char *data);
+
/* Tracefile names used in this file */
GQuark LTT_TRACEFILE_NAME_METADATA;
//void set_fields_offsets(LttTracefile *tf, LttEventType *event_type);
//size_t get_fields_offsets(LttTracefile *tf, LttEventType *event_type, void *data);
-#if 0
-/* get the size of the field type according to
- * The facility size information. */
-static inline void preset_field_type_size(LttTracefile *tf,
- LttEventType *event_type,
- off_t offset_root, off_t offset_parent,
- enum field_status *fixed_root, enum field_status *fixed_parent,
- LttField *field);
-#endif //0
-
/* map a fixed size or a block information from the file (fd) */
static gint map_block(LttTracefile * tf, guint block_num);
*
* Return value : 0 success, 1 bad tracefile
*/
-static int parse_trace_header(void *header, LttTracefile *tf, LttTrace *t)
+static int parse_trace_header(ltt_subbuffer_header_t *header,
+ LttTracefile *tf, LttTrace *t)
{
- guint32 *magic_number = (guint32*)header;
- struct ltt_trace_header_any *any = (struct ltt_trace_header_any *)header;
-
- if(*magic_number == LTT_MAGIC_NUMBER)
+ if (header->magic_number == LTT_MAGIC_NUMBER)
tf->reverse_bo = 0;
- else if(*magic_number == LTT_REV_MAGIC_NUMBER)
+ else if(header->magic_number == LTT_REV_MAGIC_NUMBER)
tf->reverse_bo = 1;
else /* invalid magic number, bad tracefile ! */
return 1;
-
+
+ if(t) {
+ t->ltt_major_version = header->major_version;
+ t->ltt_minor_version = header->minor_version;
+ t->arch_size = header->arch_size;
+ }
+ tf->alignment = header->alignment;
+
/* Get float byte order : might be different from int byte order
* (or is set to 0 if the trace has no float (kernel trace)) */
- tf->float_word_order = any->float_word_order;
- tf->alignment = any->alignment;
+ tf->float_word_order = 0;
- if(t) {
- t->arch_type = ltt_get_uint32(LTT_GET_BO(tf),
- &any->arch_type);
- t->arch_variant = ltt_get_uint32(LTT_GET_BO(tf),
- &any->arch_variant);
- t->arch_size = any->arch_size;
- t->ltt_major_version = any->major_version;
- t->ltt_minor_version = any->minor_version;
- t->flight_recorder = any->flight_recorder;
- }
-
- switch(any->major_version) {
+ switch(header->major_version) {
case 0:
case 1:
g_warning("Unsupported trace version : %hhu.%hhu",
- any->major_version, any->minor_version);
+ header->major_version, header->minor_version);
return 1;
break;
case 2:
- switch(any->minor_version) {
- case 0:
+ switch(header->minor_version) {
+ case 3:
{
- struct ltt_trace_header_2_0 *vheader =
- (struct ltt_trace_header_2_0 *)header;
- tf->buffer_header_size =
- sizeof(struct ltt_block_start_header)
- + sizeof(struct ltt_trace_header_2_0);
- tf->tscbits = vheader->tscbits;
- tf->eventbits = vheader->eventbits;
+ struct ltt_subbuffer_header_2_3 *vheader = header;
+ tf->buffer_header_size = ltt_subbuffer_header_size();
+ tf->tscbits = 27;
+ tf->eventbits = 5;
tf->tsc_mask = ((1ULL << tf->tscbits) - 1);
tf->tsc_mask_next_bit = (1ULL << tf->tscbits);
if(father_trace) {
t->start_freq = father_trace->start_freq;
t->freq_scale = father_trace->freq_scale;
- }
- else {
+ } else {
father_trace = t;
}
t->start_tsc = ltt_get_uint64(LTT_GET_BO(tf),
- &vheader->start_tsc);
- t->start_monotonic = ltt_get_uint64(LTT_GET_BO(tf),
- &vheader->start_monotonic);
+ &vheader->cycle_count_begin);
+ t->start_monotonic = 0;
t->start_time.tv_sec = ltt_get_uint64(LTT_GET_BO(tf),
&vheader->start_time_sec);
t->start_time.tv_nsec = ltt_get_uint64(LTT_GET_BO(tf),
t->start_time_from_tsc = ltt_time_from_uint64(
(double)t->start_tsc
- * (1000000000.0 / tf->trace->freq_scale)
+ * 1000000000.0 * tf->trace->freq_scale
/ (double)t->start_freq);
}
}
break;
default:
g_warning("Unsupported trace version : %hhu.%hhu",
- any->major_version, any->minor_version);
+ header->major_version, header->minor_version);
return 1;
}
break;
default:
g_warning("Unsupported trace version : %hhu.%hhu",
- any->major_version, any->minor_version);
+ header->major_version, header->minor_version);
return 1;
}
-
-
return 0;
}
static gint ltt_tracefile_open(LttTrace *t, gchar * fileName, LttTracefile *tf)
{
struct stat lTDFStat; /* Trace data file status */
- struct ltt_block_start_header *header;
+ ltt_subbuffer_header_t *header;
int page_size = getpagesize();
//open the file
// Is the file large enough to contain a trace
if(lTDFStat.st_size <
- (off_t)(sizeof(struct ltt_block_start_header)
- + sizeof(struct ltt_trace_header_any))){
+ (off_t)(ltt_subbuffer_header_size())){
g_print("The input data file %s does not contain a trace\n", fileName);
goto close_file;
}
/* Temporarily map the buffer start header to get trace information */
/* Multiple of pages aligned head */
tf->buffer.head = mmap(0,
- PAGE_ALIGN(sizeof(struct ltt_block_start_header)
- + sizeof(struct ltt_trace_header_any)), PROT_READ,
+ PAGE_ALIGN(ltt_subbuffer_header_size()), PROT_READ,
MAP_PRIVATE, tf->fd, 0);
if(tf->buffer.head == MAP_FAILED) {
perror("Error in allocating memory for buffer of tracefile");
}
g_assert( ( (gulong)tf->buffer.head&(8-1) ) == 0); // make sure it's aligned.
- header = (struct ltt_block_start_header*)tf->buffer.head;
+ header = (ltt_subbuffer_header_t *)tf->buffer.head;
- if(parse_trace_header(header->trace, tf, NULL)) {
+ if(parse_trace_header(header, tf, NULL)) {
g_warning("parse_trace_header error");
goto unmap_file;
}
tf->file_size = lTDFStat.st_size;
tf->buf_size = ltt_get_uint32(LTT_GET_BO(tf), &header->buf_size);
tf->num_blocks = tf->file_size / tf->buf_size;
+ tf->events_lost = 0;
+ tf->subbuf_corrupt = 0;
if(munmap(tf->buffer.head,
- PAGE_ALIGN(sizeof(struct ltt_block_start_header)
- + sizeof(struct ltt_trace_header_any)))) {
- g_warning("unmap size : %u\n",
- PAGE_ALIGN(sizeof(struct ltt_block_start_header)
- + sizeof(struct ltt_trace_header_any)));
+ PAGE_ALIGN(ltt_subbuffer_header_size()))) {
+ g_warning("unmap size : %zu\n",
+ PAGE_ALIGN(ltt_subbuffer_header_size()));
perror("munmap error");
g_assert(0);
}
/* Error */
unmap_file:
if(munmap(tf->buffer.head,
- PAGE_ALIGN(sizeof(struct ltt_block_start_header)
- + sizeof(struct ltt_trace_header_any)))) {
- g_warning("unmap size : %u\n",
- PAGE_ALIGN(sizeof(struct ltt_block_start_header)
- + sizeof(struct ltt_trace_header_any)));
+ PAGE_ALIGN(ltt_subbuffer_header_size()))) {
+ g_warning("unmap size : %zu\n",
+ PAGE_ALIGN(ltt_subbuffer_header_size()));
perror("munmap error");
g_assert(0);
}
/* Search for something like : .*_.*
*
* The left side is the name, the right side is the number.
+ * Exclude leading /.
+ * Exclude flight- prefix.
*/
static int get_tracefile_name_number(gchar *raw_name,
gchar *endptr;
gchar *tmpptr;
+ /* skip leading / */
+ for(i = 0; i < raw_name_len-1;i++) {
+ if(raw_name[i] != '/')
+ break;
+ }
+ raw_name = &raw_name[i];
+ raw_name_len = strlen(raw_name);
+
for(i=raw_name_len-1;i>=0;i--) {
if(raw_name[i] == '_') break;
}
if(cpu_num == LONG_MIN || cpu_num == LONG_MAX)
return -1; /* underflow / overflow */
+ if (!strncmp(raw_name, "flight-", sizeof("flight-") - 1)) {
+ raw_name += sizeof("flight-") - 1;
+ underscore_pos -= sizeof("flight-") - 1;
+ }
strncpy(char_name, raw_name, underscore_pos);
char_name[underscore_pos] = '\0';
-
*name = g_quark_from_string(char_name);
*num = cpu_num;
}
GArray *group,
struct compute_tracefile_group_args *args)
{
- int i;
+ unsigned int i;
LttTracefile *tf;
for(i=0; i<group->len; i++) {
static void ltt_tracefile_group_destroy(gpointer data)
{
GArray *group = (GArray *)data;
- int i;
+ unsigned int i;
LttTracefile *tf;
+ if (group->len > 0)
+ destroy_marker_data(g_array_index (group, LttTracefile, 0).mdata);
for(i=0; i<group->len; i++) {
tf = &g_array_index (group, LttTracefile, i);
if(tf->cpu_online)
g_array_free(group, TRUE);
}
-static gboolean ltt_tracefile_group_has_cpu_online(gpointer data)
+static __attribute__ ((__unused__)) gboolean ltt_tracefile_group_has_cpu_online(gpointer data)
{
GArray *group = (GArray *)data;
- int i;
+ unsigned int i;
LttTracefile *tf;
for(i=0; i<group->len; i++) {
DIR *dir = opendir(root_path);
struct dirent *entry;
struct stat stat_buf;
- int ret;
+ int ret, i;
+ struct marker_data *mdata;
gchar path[PATH_MAX];
int path_len;
g_debug("Tracefile name is %s and number is %u",
g_quark_to_string(name), num);
-
+
+ mdata = NULL;
tmp_tf.cpu_online = 1;
tmp_tf.cpu_num = num;
tmp_tf.name = name;
group = g_array_sized_new (FALSE, TRUE, sizeof(LttTracefile), 10);
g_datalist_id_set_data_full(&trace->tracefiles, name,
group, ltt_tracefile_group_destroy);
+ mdata = allocate_marker_data();
+ if (!mdata)
+ g_error("Error in allocating marker data");
}
/* Add the per cpu tracefile to the named group */
unsigned int old_len = group->len;
if(num+1 > old_len)
group = g_array_set_size(group, num+1);
+
+ g_assert(group->len > 0);
+ if (!mdata)
+ mdata = g_array_index (group, LttTracefile, 0).mdata;
+
g_array_index (group, LttTracefile, num) = tmp_tf;
g_array_index (group, LttTracefile, num).event.tracefile =
&g_array_index (group, LttTracefile, num);
+ for (i = 0; i < group->len; i++)
+ g_array_index (group, LttTracefile, i).mdata = mdata;
}
}
static int ltt_process_metadata_tracefile(LttTracefile *tf)
{
int err;
- guint i;
while(1) {
err = ltt_tracefile_read_seek(tf);
goto event_id_error;
} else {
char *pos;
- const char *marker_name, *format;
+ const char *channel_name, *marker_name, *format;
uint16_t id;
guint8 int_size, long_size, pointer_size, size_t_size, alignment;
switch((enum marker_id)tf->event.event_id) {
case MARKER_ID_SET_MARKER_ID:
- marker_name = pos = tf->event.data;
- g_debug("Doing MARKER_ID_SET_MARKER_ID of marker %s", marker_name);
+ channel_name = pos = tf->event.data;
+ pos += strlen(channel_name) + 1;
+ marker_name = pos;
+ g_debug("Doing MARKER_ID_SET_MARKER_ID of marker %s.%s",
+ channel_name, marker_name);
pos += strlen(marker_name) + 1;
pos += ltt_align((size_t)pos, sizeof(guint16), tf->alignment);
id = ltt_get_uint16(LTT_GET_BO(tf), pos);
- g_debug("In MARKER_ID_SET_MARKER_ID of marker %s id %hu",
- marker_name, id);
+ g_debug("In MARKER_ID_SET_MARKER_ID of marker %s.%s id %hu",
+ channel_name, marker_name, id);
pos += sizeof(guint16);
int_size = *(guint8*)pos;
pos += sizeof(guint8);
pos += sizeof(guint8);
alignment = *(guint8*)pos;
pos += sizeof(guint8);
- marker_id_event(tf->trace, g_quark_from_string(marker_name),
+ marker_id_event(tf->trace,
+ g_quark_from_string(channel_name),
+ g_quark_from_string(marker_name),
id, int_size, long_size,
pointer_size, size_t_size, alignment);
break;
case MARKER_ID_SET_MARKER_FORMAT:
- marker_name = pos = tf->event.data;
- g_debug("Doing MARKER_ID_SET_MARKER_FORMAT of marker %s",
- marker_name);
+ channel_name = pos = tf->event.data;
+ pos += strlen(channel_name) + 1;
+ marker_name = pos;
+ g_debug("Doing MARKER_ID_SET_MARKER_FORMAT of marker %s.%s",
+ channel_name, marker_name);
pos += strlen(marker_name) + 1;
format = pos;
pos += strlen(format) + 1;
- marker_format_event(tf->trace, g_quark_from_string(marker_name),
+ marker_format_event(tf->trace,
+ g_quark_from_string(channel_name),
+ g_quark_from_string(marker_name),
format);
/* get information from dictionary TODO */
break;
LttTrace * t;
LttTracefile *tf;
GArray *group;
- int i, ret;
- struct ltt_block_start_header *header;
+ unsigned int i;
+ int ret;
+ ltt_subbuffer_header_t *header;
DIR *dir;
struct dirent *entry;
- guint control_found = 0;
struct stat stat_buf;
gchar path[PATH_MAX];
perror(path);
continue;
}
- if(S_ISDIR(stat_buf.st_mode)) {
- if(strcmp(entry->d_name, "control") == 0) {
- control_found = 1;
- }
- }
}
closedir(dir);
- if(!control_found) goto find_error;
-
/* Open all the tracefiles */
if(open_tracefiles(t, abs_path, "")) {
g_warning("Error opening tracefile %s", abs_path);
goto find_error;
}
- /* Parse each trace control/metadata_N files : get runtime fac. info */
+ /* Parse each trace metadata_N files : get runtime fac. info */
group = g_datalist_id_get_data(&t->tracefiles, LTT_TRACEFILE_NAME_METADATA);
if(group == NULL) {
- g_error("Trace %s has no metadata tracefile", abs_path);
- g_assert(0);
- goto metadata_error;
+ g_warning("Trace %s has no metadata tracefile", abs_path);
+ goto find_error;
}
- /* Get the trace information for the control/metadata_0 tracefile */
+ /*
+ * Get the trace information for the metadata_0 tracefile.
+ * Getting a correct trace start_time and start_tsc is insured by the fact
+ * that no subbuffers are supposed to be lost in the metadata channel.
+ * Therefore, the first subbuffer contains the start_tsc timestamp in its
+ * buffer header.
+ */
g_assert(group->len > 0);
tf = &g_array_index (group, LttTracefile, 0);
- header = (struct ltt_block_start_header*)tf->buffer.head;
- g_assert(parse_trace_header(header->trace,
- tf, t) == 0);
+ header = (ltt_subbuffer_header_t *)tf->buffer.head;
+ ret = parse_trace_header(header, tf, t);
+ g_assert(!ret);
t->num_cpu = group->len;
- ret = allocate_marker_data(t);
- if (ret)
- g_error("Error in allocating marker data");
+ //ret = allocate_marker_data(t);
+ //if (ret)
+ // g_error("Error in allocating marker data");
for(i=0; i<group->len; i++) {
tf = &g_array_index (group, LttTracefile, i);
if (tf->cpu_online)
if(ltt_process_metadata_tracefile(tf))
- goto metadata_error;
+ goto find_error;
+ // goto metadata_error;
}
return t;
/* Error handling */
-metadata_error:
- destroy_marker_data(t);
+//metadata_error:
+// destroy_marker_data(t);
find_error:
g_datalist_clear(&t->tracefiles);
open_error:
(struct tracefile_time_span_get_args*)user_data;
GArray *group = (GArray *)data;
- int i;
+ unsigned int i;
LttTracefile *tf;
LttTime tmp_start;
LttTime tmp_end;
if(tsc > tf->trace->start_tsc) {
time = ltt_time_from_uint64(
(double)(tsc - tf->trace->start_tsc)
- * (1000000000.0 / tf->trace->freq_scale)
+ * 1000000000.0 * tf->trace->freq_scale
/ (double)tf->trace->start_freq);
time = ltt_time_add(tf->trace->start_time_from_tsc, time);
} else {
time = ltt_time_from_uint64(
(double)(tf->trace->start_tsc - tsc)
- * (1000000000.0 / tf->trace->freq_scale)
+ * 1000000000.0 * tf->trace->freq_scale
/ (double)tf->trace->start_freq);
time = ltt_time_sub(tf->trace->start_time_from_tsc, time);
}
unsigned int offset = 0;
int i, j;
- g_printf("Event header (tracefile %s offset %llx):\n",
+ g_printf("Event header (tracefile %s offset %" PRIx64 "):\n",
g_quark_to_string(ev->tracefile->long_name),
- ((uint64_t)ev->tracefile->buffer.index * ev->tracefile->buf_size)
- + (long)start_pos - (long)ev->tracefile->buffer.head);
+ ((uint64_t)ev->tracefile->buffer.index * ev->tracefile->buf_size)
+ + (long)start_pos - (long)ev->tracefile->buffer.head);
while (offset < (long)end_pos - (long)start_pos) {
g_printf("%8lx", (long)start_pos - (long)ev->tracefile->buffer.head + offset);
static gint map_block(LttTracefile * tf, guint block_num)
{
int page_size = getpagesize();
- struct ltt_block_start_header *header;
+ ltt_subbuffer_header_t *header;
g_assert(block_num < tf->num_blocks);
tf->buffer.index = block_num;
- header = (struct ltt_block_start_header*)tf->buffer.head;
+ header = (ltt_subbuffer_header_t *)tf->buffer.head;
tf->buffer.begin.cycle_count = ltt_get_uint64(LTT_GET_BO(tf),
- &header->begin.cycle_count);
- tf->buffer.begin.freq = ltt_get_uint64(LTT_GET_BO(tf),
- &header->begin.freq);
- if(tf->buffer.begin.freq == 0)
- tf->buffer.begin.freq = tf->trace->start_freq;
+ &header->cycle_count_begin);
+ tf->buffer.begin.freq = tf->trace->start_freq;
tf->buffer.begin.timestamp = ltt_interpolate_time_from_tsc(tf,
tf->buffer.begin.cycle_count);
tf->buffer.end.cycle_count = ltt_get_uint64(LTT_GET_BO(tf),
- &header->end.cycle_count);
- tf->buffer.end.freq = ltt_get_uint64(LTT_GET_BO(tf),
- &header->end.freq);
- if(tf->buffer.end.freq == 0)
- tf->buffer.end.freq = tf->trace->start_freq;
+ &header->cycle_count_end);
+ tf->buffer.end.freq = tf->trace->start_freq;
tf->buffer.lost_size = ltt_get_uint32(LTT_GET_BO(tf),
&header->lost_size);
tf->event.block = block_num;
tf->event.offset = 0;
+ if (header->events_lost) {
+ g_warning("%d events lost so far in tracefile %s at block %u",
+ (guint)header->events_lost,
+ g_quark_to_string(tf->long_name),
+ block_num);
+ tf->events_lost = header->events_lost;
+ }
+ if (header->subbuf_corrupt) {
+ g_warning("%d subbuffer(s) corrupted so far in tracefile %s at block %u",
+ (guint)header->subbuf_corrupt,
+ g_quark_to_string(tf->long_name),
+ block_num);
+ tf->subbuf_corrupt = header->subbuf_corrupt;
+ }
+
return 0;
map_error:
if (!max(ev->event_size, ev->data_size))
return;
- g_printf("Event data (tracefile %s offset %llx):\n",
- g_quark_to_string(ev->tracefile->long_name),
- ((uint64_t)ev->tracefile->buffer.index * ev->tracefile->buf_size)
- + (long)ev->data - (long)ev->tracefile->buffer.head);
+ g_printf("Event data (tracefile %s offset %" PRIx64 "):\n",
+ g_quark_to_string(ev->tracefile->long_name),
+ ((uint64_t)ev->tracefile->buffer.index * ev->tracefile->buf_size)
+ + (long)ev->data - (long)ev->tracefile->buffer.head);
while (offset < max(ev->event_size, ev->data_size)) {
g_printf("%8lx", (long)ev->data + offset
void ltt_update_event_size(LttTracefile *tf)
{
off_t size = 0;
- char *tscdata;
struct marker_info *info;
-
- switch((enum marker_id)tf->event.event_id) {
- case MARKER_ID_SET_MARKER_ID:
- size = strlen((char*)tf->event.data) + 1;
- g_debug("marker %s id set", (char*)tf->event.data);
- size += ltt_align(size, sizeof(guint16), tf->alignment);
- size += sizeof(guint16);
- size += sizeof(guint8);
- size += sizeof(guint8);
- size += sizeof(guint8);
- size += sizeof(guint8);
- size += sizeof(guint8);
- break;
- case MARKER_ID_SET_MARKER_FORMAT:
- g_debug("marker %s format set", (char*)tf->event.data);
- size = strlen((char*)tf->event.data) + 1;
- size += strlen((char*)tf->event.data + size) + 1;
- break;
+
+ if (tf->name == LTT_TRACEFILE_NAME_METADATA) {
+ switch((enum marker_id)tf->event.event_id) {
+ case MARKER_ID_SET_MARKER_ID:
+ size = strlen((char*)tf->event.data) + 1;
+ g_debug("marker %s id set", (char*)tf->event.data + size);
+ size += strlen((char*)tf->event.data + size) + 1;
+ size += ltt_align(size, sizeof(guint16), tf->alignment);
+ size += sizeof(guint16);
+ size += sizeof(guint8);
+ size += sizeof(guint8);
+ size += sizeof(guint8);
+ size += sizeof(guint8);
+ size += sizeof(guint8);
+ break;
+ case MARKER_ID_SET_MARKER_FORMAT:
+ size = strlen((char*)tf->event.data) + 1;
+ g_debug("marker %s format set", (char*)tf->event.data);
+ size += strlen((char*)tf->event.data + size) + 1;
+ size += strlen((char*)tf->event.data + size) + 1;
+ break;
+ }
}
- info = marker_get_info_from_id(tf->trace, tf->event.event_id);
+ info = marker_get_info_from_id(tf->mdata, tf->event.event_id);
if (tf->event.event_id >= MARKER_CORE_IDS)
g_assert(info != NULL);
*/
if (likely(info && info->fields)) {
/* alignment */
- tf->event.data += ltt_align((off_t)tf->event.data, info->largest_align,
+ tf->event.data += ltt_align((off_t)(unsigned long)tf->event.data,
+ info->largest_align,
info->alignment);
/* size, dynamically computed */
if (info->size != -1)
size = info->size;
else
- size = marker_update_fields_offsets(marker_get_info_from_id(tf->trace,
+ size = marker_update_fields_offsets(marker_get_info_from_id(tf->mdata,
tf->event.event_id), tf->event.data);
}
if (a_event_debug)
print_debug_event_data(&tf->event);
- /* Having a marker load or marker format event out of the metadata
- * tracefiles is a serious bug. */
- switch((enum marker_id)tf->event.event_id) {
- case MARKER_ID_SET_MARKER_ID:
- case MARKER_ID_SET_MARKER_FORMAT:
- if (tf->name != g_quark_from_string("/control/metadata"))
- g_error("Trace inconsistency : metadata event found in data "
- "tracefile %s", g_quark_to_string(tf->long_name));
- }
-
if (tf->event.data_size != tf->event.event_size) {
- struct marker_info *info = marker_get_info_from_id(tf->trace,
+ struct marker_info *info = marker_get_info_from_id(tf->mdata,
tf->event.event_id);
+ if (!info)
+ g_error("Undescribed event %hhu in channel %s", tf->event.event_id,
+ g_quark_to_string(tf->name));
g_error("Kernel/LTTV event size differs for event %s: kernel %u, LTTV %u",
g_quark_to_string(info->name),
tf->event.event_size, tf->event.data_size);
return ENOPROTOOPT;
}
-#if 0
-/*****************************************************************************
- *Function name
- * set_fields_offsets : set the precomputable offset of the fields
- *Input params
- * tracefile : opened trace file
- * event_type : the event type
- ****************************************************************************/
-
-void set_fields_offsets(LttTracefile *tf, LttEventType *event_type)
-{
- LttField *field = event_type->root_field;
- enum field_status fixed_root = FIELD_FIXED, fixed_parent = FIELD_FIXED;
-
- if(likely(field))
- preset_field_type_size(tf, event_type, 0, 0,
- &fixed_root, &fixed_parent,
- field);
-
-}
-#endif //0
-
-
-/*****************************************************************************
- *Function name
- * get_alignment : Get the alignment needed for a field.
- *Input params
- * field : field
- *
- * returns : The size on which it must be aligned.
- *
- ****************************************************************************/
-#if 0
-off_t get_alignment(LttField *field)
-{
- LttType *type = &field->field_type;
-
- switch(type->type_class) {
- case LTT_INT_FIXED:
- case LTT_UINT_FIXED:
- case LTT_POINTER:
- case LTT_CHAR:
- case LTT_UCHAR:
- case LTT_SHORT:
- case LTT_USHORT:
- case LTT_INT:
- case LTT_UINT:
- case LTT_LONG:
- case LTT_ULONG:
- case LTT_SIZE_T:
- case LTT_SSIZE_T:
- case LTT_OFF_T:
- case LTT_FLOAT:
- case LTT_ENUM:
- /* Align offset on type size */
- g_assert(field->field_size != 0);
- return field->field_size;
- break;
- case LTT_STRING:
- return 1;
- break;
- case LTT_ARRAY:
- g_assert(type->fields->len == 1);
- {
- LttField *child = &g_array_index(type->fields, LttField, 0);
- return get_alignment(child);
- }
- break;
- case LTT_SEQUENCE:
- g_assert(type->fields->len == 2);
- {
- off_t localign = 1;
- LttField *child = &g_array_index(type->fields, LttField, 0);
-
- localign = max(localign, get_alignment(child));
-
- child = &g_array_index(type->fields, LttField, 1);
- localign = max(localign, get_alignment(child));
-
- return localign;
- }
- break;
- case LTT_STRUCT:
- case LTT_UNION:
- {
- guint i;
- off_t localign = 1;
-
- for(i=0; i<type->fields->len; i++) {
- LttField *child = &g_array_index(type->fields, LttField, i);
- localign = max(localign, get_alignment(child));
- }
- return localign;
- }
- break;
- case LTT_NONE:
- default:
- g_error("get_alignment : unknown type");
- return -1;
- }
-}
-
-#endif //0
-
-/*****************************************************************************
- *Function name
- * field_compute_static_size : Determine the size of fields known by their
- * sole definition. Unions, arrays and struct sizes might be known, but
- * the parser does not give that information.
- *Input params
- * tf : tracefile
- * field : field
- *
- ****************************************************************************/
-#if 0
-void field_compute_static_size(LttFacility *fac, LttField *field)
-{
- LttType *type = &field->field_type;
-
- switch(type->type_class) {
- case LTT_INT_FIXED:
- case LTT_UINT_FIXED:
- case LTT_POINTER:
- case LTT_CHAR:
- case LTT_UCHAR:
- case LTT_SHORT:
- case LTT_USHORT:
- case LTT_INT:
- case LTT_UINT:
- case LTT_LONG:
- case LTT_ULONG:
- case LTT_SIZE_T:
- case LTT_SSIZE_T:
- case LTT_OFF_T:
- case LTT_FLOAT:
- case LTT_ENUM:
- case LTT_STRING:
- /* nothing to do */
- break;
- case LTT_ARRAY:
- /* note this : array type size is the number of elements in the array,
- * while array field size of the length of the array in bytes */
- g_assert(type->fields->len == 1);
- {
- LttField *child = &g_array_index(type->fields, LttField, 0);
- field_compute_static_size(fac, child);
-
- if(child->field_size != 0) {
- field->field_size = type->size * child->field_size;
- field->dynamic_offsets = g_array_sized_new(FALSE, TRUE,
- sizeof(off_t), type->size);
- } else {
- field->field_size = 0;
- }
- }
- break;
- case LTT_SEQUENCE:
- g_assert(type->fields->len == 2);
- {
- off_t local_offset = 0;
- LttField *child = &g_array_index(type->fields, LttField, 1);
- field_compute_static_size(fac, child);
- field->field_size = 0;
- type->size = 0;
- if(child->field_size != 0) {
- field->dynamic_offsets = g_array_sized_new(FALSE, TRUE,
- sizeof(off_t), SEQUENCE_AVG_ELEMENTS);
- }
- }
- break;
- case LTT_STRUCT:
- case LTT_UNION:
- {
- guint i;
- for(i=0;i<type->fields->len;i++) {
- LttField *child = &g_array_index(type->fields, LttField, i);
- field_compute_static_size(fac, child);
- if(child->field_size != 0) {
- type->size += ltt_align(type->size, get_alignment(child),
- fac->alignment);
- type->size += child->field_size;
- } else {
- /* As soon as we find a child with variable size, we have
- * a variable size */
- type->size = 0;
- break;
- }
- }
- field->field_size = type->size;
- }
- break;
- default:
- g_error("field_static_size : unknown type");
- }
-
-}
-#endif //0
-
-
-/*****************************************************************************
- *Function name
- * precompute_fields_offsets : set the precomputable offset of the fields
- *Input params
- * fac : facility
- * field : the field
- * offset : pointer to the current offset, must be incremented
- *
- * return : 1 : found a variable length field, stop the processing.
- * 0 otherwise.
- ****************************************************************************/
-
-#if 0
-gint precompute_fields_offsets(LttFacility *fac, LttField *field, off_t *offset, gint is_compact)
-{
- LttType *type = &field->field_type;
-
- if(unlikely(is_compact)) {
- g_assert(field->field_size != 0);
- /* FIXME THIS IS A HUUUUUGE hack :
- * offset is between the compact_data field in struct LttEvent
- * and the address of the field root in the memory map.
- * ark. Both will stay at the same addresses while the event
- * is readable, so it's ok.
- */
- field->offset_root = 0;
- field->fixed_root = FIELD_FIXED;
- return 0;
- }
-
- switch(type->type_class) {
- case LTT_INT_FIXED:
- case LTT_UINT_FIXED:
- case LTT_POINTER:
- case LTT_CHAR:
- case LTT_UCHAR:
- case LTT_SHORT:
- case LTT_USHORT:
- case LTT_INT:
- case LTT_UINT:
- case LTT_LONG:
- case LTT_ULONG:
- case LTT_SIZE_T:
- case LTT_SSIZE_T:
- case LTT_OFF_T:
- case LTT_FLOAT:
- case LTT_ENUM:
- g_assert(field->field_size != 0);
- /* Align offset on type size */
- *offset += ltt_align(*offset, get_alignment(field),
- fac->alignment);
- /* remember offset */
- field->offset_root = *offset;
- field->fixed_root = FIELD_FIXED;
- /* Increment offset */
- *offset += field->field_size;
- return 0;
- break;
- case LTT_STRING:
- field->offset_root = *offset;
- field->fixed_root = FIELD_FIXED;
- return 1;
- break;
- case LTT_ARRAY:
- g_assert(type->fields->len == 1);
- {
- LttField *child = &g_array_index(type->fields, LttField, 0);
-
- *offset += ltt_align(*offset, get_alignment(field),
- fac->alignment);
-
- /* remember offset */
- field->offset_root = *offset;
- field->array_offset = *offset;
- field->fixed_root = FIELD_FIXED;
-
- /* Let the child be variable */
- //precompute_fields_offsets(tf, child, offset);
-
- if(field->field_size != 0) {
- /* Increment offset */
- /* field_size is the array size in bytes */
- *offset += field->field_size;
- return 0;
- } else {
- return 1;
- }
- }
- break;
- case LTT_SEQUENCE:
- g_assert(type->fields->len == 2);
- {
- LttField *child;
- guint ret;
-
- *offset += ltt_align(*offset, get_alignment(field),
- fac->alignment);
-
- /* remember offset */
- field->offset_root = *offset;
- field->fixed_root = FIELD_FIXED;
-
- child = &g_array_index(type->fields, LttField, 0);
- ret = precompute_fields_offsets(fac, child, offset, is_compact);
- g_assert(ret == 0); /* Seq len cannot have variable len */
-
- child = &g_array_index(type->fields, LttField, 1);
- *offset += ltt_align(*offset, get_alignment(child),
- fac->alignment);
- field->array_offset = *offset;
- /* Let the child be variable. */
- //ret = precompute_fields_offsets(fac, child, offset);
-
- /* Cannot precompute fields offsets of sequence members, and has
- * variable length. */
- return 1;
- }
- break;
- case LTT_STRUCT:
- {
- LttField *child;
- guint i;
- gint ret=0;
-
- *offset += ltt_align(*offset, get_alignment(field),
- fac->alignment);
- /* remember offset */
- field->offset_root = *offset;
- field->fixed_root = FIELD_FIXED;
-
- for(i=0; i< type->fields->len; i++) {
- child = &g_array_index(type->fields, LttField, i);
- ret = precompute_fields_offsets(fac, child, offset, is_compact);
-
- if(ret) break;
- }
- return ret;
- }
- break;
- case LTT_UNION:
- {
- LttField *child;
- guint i;
- gint ret=0;
-
- *offset += ltt_align(*offset, get_alignment(field),
- fac->alignment);
- /* remember offset */
- field->offset_root = *offset;
- field->fixed_root = FIELD_FIXED;
-
- for(i=0; i< type->fields->len; i++) {
- *offset = field->offset_root;
- child = &g_array_index(type->fields, LttField, i);
- ret = precompute_fields_offsets(fac, child, offset, is_compact);
-
- if(ret) break;
- }
- *offset = field->offset_root + field->field_size;
- return ret;
- }
-
- break;
- case LTT_NONE:
- default:
- g_error("precompute_fields_offsets : unknown type");
- return 1;
- }
-
-}
-
-#endif //0
-
-#if 0
-/*****************************************************************************
- *Function name
- * precompute_offsets : set the precomputable offset of an event type
- *Input params
- * tf : tracefile
- * event : event type
- *
- ****************************************************************************/
-void precompute_offsets(LttFacility *fac, LttEventType *event)
-{
- guint i;
- off_t offset = 0;
- gint ret;
-
- /* First, compute the size of fixed size fields. Will determine size for
- * arrays, struct and unions, which is not done by the parser */
- for(i=0; i<event->fields->len; i++) {
- LttField *field = &g_array_index(event->fields, LttField, i);
- field_compute_static_size(fac, field);
- }
-
- /* Precompute all known offsets */
- for(i=0; i<event->fields->len; i++) {
- LttField *field = &g_array_index(event->fields, LttField, i);
- if(event->has_compact_data && i == 0)
- ret = precompute_fields_offsets(fac, field, &offset, 1);
- else
- ret = precompute_fields_offsets(fac, field, &offset, 0);
- if(ret) break;
- }
-}
-#endif //0
-
-
-
-/*****************************************************************************
- *Function name
- * preset_field_type_size : set the fixed sizes of the field type
- *Input params
- * tf : tracefile
- * event_type : event type
- * offset_root : offset from the root
- * offset_parent : offset from the parent
- * fixed_root : Do we know a fixed offset to the root ?
- * fixed_parent : Do we know a fixed offset to the parent ?
- * field : field
- ****************************************************************************/
-
-
-
-// preset the fixed size offsets. Calculate them just like genevent-new : an
-// increment of a *to value that represents the offset from the start of the
-// event data.
-// The preset information is : offsets up to (and including) the first element
-// of variable size. All subsequent fields must be flagged "VARIABLE OFFSET".
-#if 0
-void preset_field_type_size(LttTracefile *tf, LttEventType *event_type,
- off_t offset_root, off_t offset_parent,
- enum field_status *fixed_root, enum field_status *fixed_parent,
- LttField *field)
-{
- enum field_status local_fixed_root, local_fixed_parent;
- guint i;
- LttType *type;
-
- g_assert(field->fixed_root == FIELD_UNKNOWN);
- g_assert(field->fixed_parent == FIELD_UNKNOWN);
- g_assert(field->fixed_size == FIELD_UNKNOWN);
-
- type = field->field_type;
-
- field->fixed_root = *fixed_root;
- if(field->fixed_root == FIELD_FIXED)
- field->offset_root = offset_root;
- else
- field->offset_root = 0;
-
- field->fixed_parent = *fixed_parent;
- if(field->fixed_parent == FIELD_FIXED)
- field->offset_parent = offset_parent;
- else
- field->offset_parent = 0;
-
- size_t current_root_offset;
- size_t current_offset;
- enum field_status current_child_status, final_child_status;
- size_t max_size;
-
- switch(type->type_class) {
- case LTT_INT_FIXED:
- case LTT_UINT_FIXED:
- case LTT_CHAR:
- case LTT_UCHAR:
- case LTT_SHORT:
- case LTT_USHORT:
- case LTT_INT:
- case LTT_UINT:
- case LTT_FLOAT:
- case LTT_ENUM:
- field->field_size = ltt_type_size(tf->trace, type);
- field->fixed_size = FIELD_FIXED;
- break;
- case LTT_POINTER:
- field->field_size = (off_t)event_type->facility->pointer_size;
- field->fixed_size = FIELD_FIXED;
- break;
- case LTT_LONG:
- case LTT_ULONG:
- field->field_size = (off_t)event_type->facility->long_size;
- field->fixed_size = FIELD_FIXED;
- break;
- case LTT_SIZE_T:
- case LTT_SSIZE_T:
- case LTT_OFF_T:
- field->field_size = (off_t)event_type->facility->size_t_size;
- field->fixed_size = FIELD_FIXED;
- break;
- case LTT_SEQUENCE:
- local_fixed_root = FIELD_VARIABLE;
- local_fixed_parent = FIELD_VARIABLE;
- preset_field_type_size(tf, event_type,
- 0, 0,
- &local_fixed_root, &local_fixed_parent,
- field->child[0]);
- field->fixed_size = FIELD_VARIABLE;
- field->field_size = 0;
- *fixed_root = FIELD_VARIABLE;
- *fixed_parent = FIELD_VARIABLE;
- break;
- case LTT_STRING:
- field->fixed_size = FIELD_VARIABLE;
- field->field_size = 0;
- *fixed_root = FIELD_VARIABLE;
- *fixed_parent = FIELD_VARIABLE;
- break;
- case LTT_ARRAY:
- local_fixed_root = FIELD_VARIABLE;
- local_fixed_parent = FIELD_VARIABLE;
- preset_field_type_size(tf, event_type,
- 0, 0,
- &local_fixed_root, &local_fixed_parent,
- field->child[0]);
- field->fixed_size = field->child[0]->fixed_size;
- if(field->fixed_size == FIELD_FIXED) {
- field->field_size = type->element_number * field->child[0]->field_size;
- } else {
- field->field_size = 0;
- *fixed_root = FIELD_VARIABLE;
- *fixed_parent = FIELD_VARIABLE;
- }
- break;
- case LTT_STRUCT:
- current_root_offset = field->offset_root;
- current_offset = 0;
- current_child_status = FIELD_FIXED;
- for(i=0;i<type->element_number;i++) {
- preset_field_type_size(tf, event_type,
- current_root_offset, current_offset,
- fixed_root, ¤t_child_status,
- field->child[i]);
- if(current_child_status == FIELD_FIXED) {
- current_root_offset += field->child[i]->field_size;
- current_offset += field->child[i]->field_size;
- } else {
- current_root_offset = 0;
- current_offset = 0;
- }
- }
- if(current_child_status != FIELD_FIXED) {
- *fixed_parent = current_child_status;
- field->field_size = 0;
- field->fixed_size = current_child_status;
- } else {
- field->field_size = current_offset;
- field->fixed_size = FIELD_FIXED;
- }
- break;
- case LTT_UNION:
- current_root_offset = field->offset_root;
- current_offset = 0;
- max_size = 0;
- final_child_status = FIELD_FIXED;
- for(i=0;i<type->element_number;i++) {
- enum field_status current_root_child_status = FIELD_FIXED;
- enum field_status current_child_status = FIELD_FIXED;
- preset_field_type_size(tf, event_type,
- current_root_offset, current_offset,
- ¤t_root_child_status, ¤t_child_status,
- field->child[i]);
- if(current_child_status != FIELD_FIXED)
- final_child_status = current_child_status;
- else
- max_size = max(max_size, field->child[i]->field_size);
- }
- if(final_child_status != FIELD_FIXED) {
- g_error("LTTV does not support variable size fields in unions.");
- /* This will stop the application. */
- *fixed_root = final_child_status;
- *fixed_parent = final_child_status;
- field->field_size = 0;
- field->fixed_size = current_child_status;
- } else {
- field->field_size = max_size;
- field->fixed_size = FIELD_FIXED;
- }
- break;
- case LTT_NONE:
- g_error("unexpected type NONE");
- break;
- }
-
-}
-#endif //0
-
-/*****************************************************************************
- *Function name
- * check_fields_compatibility : Check for compatibility between two fields :
- * do they use the same inner structure ?
- *Input params
- * event_type1 : event type
- * event_type2 : event type
- * field1 : field
- * field2 : field
- *Returns : 0 if identical
- * 1 if not.
- ****************************************************************************/
-// this function checks for equality of field types. Therefore, it does not use
-// per se offsets. For instance, an aligned version of a structure is
-// compatible with an unaligned version of the same structure.
-#if 0
-gint check_fields_compatibility(LttEventType *event_type1,
- LttEventType *event_type2,
- LttField *field1, LttField *field2)
-{
- guint different = 0;
- LttType *type1;
- LttType *type2;
-
- if(field1 == NULL) {
- if(field2 == NULL) goto end;
- else {
- different = 1;
- goto end;
- }
- } else if(field2 == NULL) {
- different = 1;
- goto end;
- }
-
- type1 = &field1->field_type;
- type2 = &field2->field_type;
-
- if(type1->type_class != type2->type_class) {
- different = 1;
- goto end;
- }
- if(type1->network != type2->network) {
- different = 1;
- goto end;
- }
-
- switch(type1->type_class) {
- case LTT_INT_FIXED:
- case LTT_UINT_FIXED:
- case LTT_POINTER:
- case LTT_CHAR:
- case LTT_UCHAR:
- case LTT_SHORT:
- case LTT_USHORT:
- case LTT_INT:
- case LTT_UINT:
- case LTT_LONG:
- case LTT_ULONG:
- case LTT_SIZE_T:
- case LTT_SSIZE_T:
- case LTT_OFF_T:
- case LTT_FLOAT:
- case LTT_ENUM:
- if(field1->field_size != field2->field_size)
- different = 1;
- break;
- case LTT_STRING:
- break;
- case LTT_ARRAY:
- {
- LttField *child1 = &g_array_index(type1->fields, LttField, 0);
- LttField *child2 = &g_array_index(type2->fields, LttField, 0);
-
- if(type1->size != type2->size)
- different = 1;
- if(check_fields_compatibility(event_type1, event_type2, child1, child2))
- different = 1;
- }
- break;
- case LTT_SEQUENCE:
- {
- LttField *child1 = &g_array_index(type1->fields, LttField, 1);
- LttField *child2 = &g_array_index(type2->fields, LttField, 1);
-
- if(check_fields_compatibility(event_type1, event_type2, child1, child2))
- different = 1;
- }
- break;
- case LTT_STRUCT:
- case LTT_UNION:
- {
- LttField *child;
- guint i;
-
- if(type1->fields->len != type2->fields->len) {
- different = 1;
- goto end;
- }
-
- for(i=0; i< type1->fields->len; i++) {
- LttField *child1;
- LttField *child2;
- child1 = &g_array_index(type1->fields, LttField, i);
- child2 = &g_array_index(type2->fields, LttField, i);
- different = check_fields_compatibility(event_type1,
- event_type2, child1, child2);
-
- if(different) break;
- }
- }
- break;
- case LTT_NONE:
- default:
- g_error("check_fields_compatibility : unknown type");
- }
-
-end:
- return different;
-}
-#endif //0
-
-#if 0
-gint check_fields_compatibility(LttEventType *event_type1,
- LttEventType *event_type2,
- LttField *field1, LttField *field2)
-{
- guint different = 0;
- guint i;
- LttType *type1;
- LttType *type2;
-
- if(field1 == NULL) {
- if(field2 == NULL) goto end;
- else {
- different = 1;
- goto end;
- }
- } else if(field2 == NULL) {
- different = 1;
- goto end;
- }
-
- g_assert(field1->fixed_root != FIELD_UNKNOWN);
- g_assert(field2->fixed_root != FIELD_UNKNOWN);
- g_assert(field1->fixed_parent != FIELD_UNKNOWN);
- g_assert(field2->fixed_parent != FIELD_UNKNOWN);
- g_assert(field1->fixed_size != FIELD_UNKNOWN);
- g_assert(field2->fixed_size != FIELD_UNKNOWN);
-
- type1 = field1->field_type;
- type2 = field2->field_type;
-
- if(type1->type_class != type2->type_class) {
- different = 1;
- goto end;
- }
- if(type1->element_name != type2->element_name) {
- different = 1;
- goto end;
- }
-
- switch(type1->type_class) {
- case LTT_INT_FIXED:
- case LTT_UINT_FIXED:
- case LTT_POINTER:
- case LTT_CHAR:
- case LTT_UCHAR:
- case LTT_SHORT:
- case LTT_USHORT:
- case LTT_INT:
- case LTT_UINT:
- case LTT_FLOAT:
- case LTT_POINTER:
- case LTT_LONG:
- case LTT_ULONG:
- case LTT_SIZE_T:
- case LTT_SSIZE_T:
- case LTT_OFF_T:
- if(field1->field_size != field2->field_size) {
- different = 1;
- goto end;
- }
- break;
- case LTT_ENUM:
- if(type1->element_number != type2->element_number) {
- different = 1;
- goto end;
- }
- for(i=0;i<type1->element_number;i++) {
- if(type1->enum_strings[i] != type2->enum_strings[i]) {
- different = 1;
- goto end;
- }
- }
- break;
- case LTT_SEQUENCE:
- /* Two elements : size and child */
- g_assert(type1->element_number != type2->element_number);
- for(i=0;i<type1->element_number;i++) {
- if(check_fields_compatibility(event_type1, event_type2,
- field1->child[0], field2->child[0])) {
- different = 1;
- goto end;
- }
- }
- break;
- case LTT_STRING:
- break;
- case LTT_ARRAY:
- if(field1->field_size != field2->field_size) {
- different = 1;
- goto end;
- }
- /* Two elements : size and child */
- g_assert(type1->element_number != type2->element_number);
- for(i=0;i<type1->element_number;i++) {
- if(check_fields_compatibility(event_type1, event_type2,
- field1->child[0], field2->child[0])) {
- different = 1;
- goto end;
- }
- }
- break;
- case LTT_STRUCT:
- case LTT_UNION:
- if(type1->element_number != type2->element_number) {
- different = 1;
- break;
- }
- for(i=0;i<type1->element_number;i++) {
- if(check_fields_compatibility(event_type1, event_type2,
- field1->child[0], field2->child[0])) {
- different = 1;
- goto end;
- }
- }
- break;
- }
-end:
- return different;
-}
-#endif //0
-
/*****************************************************************************
*Function name
return t->start_time_from_tsc;
}
-static LttTracefile *ltt_tracefile_new()
+static __attribute__ ((__unused__)) LttTracefile *ltt_tracefile_new()
{
LttTracefile *tf;
tf = g_new(LttTracefile, 1);
return tf;
}
-static void ltt_tracefile_destroy(LttTracefile *tf)
+static __attribute__ ((__unused__)) void ltt_tracefile_destroy(LttTracefile *tf)
{
g_free(tf);
}
-static void ltt_tracefile_copy(LttTracefile *dest, const LttTracefile *src)
+static __attribute__ ((__unused__)) void ltt_tracefile_copy(LttTracefile *dest, const LttTracefile *src)
{
*dest = *src;
}
static __attribute__((constructor)) void init(void)
{
- LTT_TRACEFILE_NAME_METADATA = g_quark_from_string("/control/metadata");
+ LTT_TRACEFILE_NAME_METADATA = g_quark_from_string("metadata");
}