#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;
break;
case 2:
switch(header->minor_version) {
- case 1:
+ case 3:
{
- struct ltt_subbuffer_header_2_1 *vheader = header;
+ struct ltt_subbuffer_header_2_3 *vheader = header;
tf->buffer_header_size = ltt_subbuffer_header_size();
tf->tscbits = 27;
tf->eventbits = 5;
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);
}
}
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(ltt_subbuffer_header_size()))) {
- g_warning("unmap size : %u\n",
+ g_warning("unmap size : %zu\n",
PAGE_ALIGN(ltt_subbuffer_header_size()));
perror("munmap error");
g_assert(0);
unmap_file:
if(munmap(tf->buffer.head,
PAGE_ALIGN(ltt_subbuffer_header_size()))) {
- g_warning("unmap size : %u\n",
+ 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,
{
guint raw_name_len = strlen(raw_name);
gchar char_name[PATH_MAX];
- int i;
+ unsigned int i;
int underscore_pos;
long int cpu_num;
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;
+ 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;
+ 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 = (ltt_subbuffer_header_t *)tf->buffer.head;
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);
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 (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 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");
}