X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=lttv%2Flttv%2Fprint.c;h=aa21f77bf3c18531515539bdf37d9cfb0e318087;hb=6db3427f29cace9a1addac5a6277bbc1ce666002;hp=53873d22f19b70bf2577927cd0d26db93fe12dfc;hpb=14bc9b7c68fe5eb3d0177ed45bfced546957fdce;p=lttv.git diff --git a/lttv/lttv/print.c b/lttv/lttv/print.c index 53873d22..aa21f77b 100644 --- a/lttv/lttv/print.c +++ b/lttv/lttv/print.c @@ -32,8 +32,10 @@ #include #include #include +#ifdef BABEL_CLEANUP #include #include +#endif #include #include #include @@ -41,269 +43,477 @@ #include #include #include +#include #include #include - +#include +#include +#ifdef BABEL_CLEANUP static inline void print_enum_events(LttEvent *e, struct marker_field *f, - guint64 value, GString *s, LttvTracefileState *tfs) + guint64 value, GString *s, LttvTracefileState *tfs) { - LttTracefile *tf = tfs->parent.tf; - struct marker_info *info = marker_get_info_from_id(tf->mdata, e->event_id); - LttvTraceState *ts = (LttvTraceState*)(tfs->parent.t_context); - - if (tf->name == LTT_CHANNEL_KERNEL) { - if (info->name == LTT_EVENT_SYSCALL_ENTRY - && f->name == LTT_FIELD_SYSCALL_ID) { - g_string_append_printf(s, " [%s]", - g_quark_to_string(ts->syscall_names[value])); - } else if ((info->name == LTT_EVENT_SOFT_IRQ_ENTRY - || info->name == LTT_EVENT_SOFT_IRQ_EXIT - || info->name == LTT_EVENT_SOFT_IRQ_RAISE) - && f->name == LTT_FIELD_SOFT_IRQ_ID) { - g_string_append_printf(s, " [%s]", - g_quark_to_string(ts->soft_irq_names[value])); - } else if (info->name == LTT_EVENT_KPROBE - && f->name == LTT_FIELD_IP) { -#if (__SIZEOF_LONG__ == 4) - GQuark symbol = (GQuark)g_hash_table_lookup(ts->kprobe_hash, - (gconstpointer)&value); + LttvTraceState *ts = (LttvTraceState*)(tfs->parent.t_context); + LttvNameTables *nt = ts->name_tables; + + if (tf->name == LTT_CHANNEL_KERNEL) { + if (info->name == LTT_EVENT_SYSCALL_ENTRY + && f->name == LTT_FIELD_SYSCALL_ID) { + g_string_append_printf(s, " [%s]", + g_quark_to_string(nt->syscall_names[value])); + } else if ((info->name == LTT_EVENT_SOFT_IRQ_ENTRY + || info->name == LTT_EVENT_SOFT_IRQ_EXIT + || info->name == LTT_EVENT_SOFT_IRQ_RAISE) + && f->name == LTT_FIELD_SOFT_IRQ_ID) { + g_string_append_printf(s, " [%s]", + g_quark_to_string(nt->soft_irq_names[value])); + } else if (info->name == LTT_EVENT_KPROBE + && f->name == LTT_FIELD_IP) { +#if (__WORDSIZE == 32) + GQuark symbol = (GQuark)g_hash_table_lookup(nt->kprobe_hash, + (gconstpointer)&value); #else - GQuark symbol = (GQuark)g_hash_table_lookup(ts->kprobe_hash, - (gconstpointer)value); + GQuark symbol = (GQuark)(unsigned long)g_hash_table_lookup(nt->kprobe_hash, + (gconstpointer)value); #endif - if (symbol) - g_string_append_printf(s, " [%s]", g_quark_to_string(symbol)); - } - } + if (symbol) + g_string_append_printf(s, " [%s]", g_quark_to_string(symbol)); + } + } } void lttv_print_field(LttEvent *e, struct marker_field *f, GString *s, - gboolean field_names, LttvTracefileState *tfs) + gboolean field_names, LttvTracefileState *tfs) { - GQuark name; - guint64 value; - - //int nb, i; - - switch(f->type) { - case LTT_TYPE_SIGNED_INT: - if(field_names) { - name = f->name; - if(name) - g_string_append_printf(s, "%s = ", g_quark_to_string(name)); - } - value = ltt_event_get_long_int(e,f); - //g_string_append_printf(s, "%lld", value); - g_string_append_printf(s, f->fmt->str, value); - //g_string_append_printf(s, type->fmt, ltt_event_get_long_int(e,f)); - print_enum_events(e, f, value, s, tfs); - break; - - case LTT_TYPE_UNSIGNED_INT: - if(field_names) { - name = f->name; - if(name) - g_string_append_printf(s, "%s = ", g_quark_to_string(name)); - } - value = ltt_event_get_long_unsigned(e,f); - //g_string_append_printf(s, "%llu", value); - g_string_append_printf(s, f->fmt->str, value); - print_enum_events(e, f, value, s, tfs); - //g_string_append_printf(s, type->fmt, ltt_event_get_long_unsigned(e,f)); - break; - + GQuark name; + guint64 value; + + //int nb, i; + + switch(f->type) { + case LTT_TYPE_SIGNED_INT: + if(field_names) { + name = f->name; + if(name) + g_string_append_printf(s, "%s = ", g_quark_to_string(name)); + } + value = ltt_event_get_long_int(e,f); + //g_string_append_printf(s, "%lld", value); + g_string_append_printf(s, f->fmt->str, value); + //g_string_append_printf(s, type->fmt, ltt_event_get_long_int(e,f)); + print_enum_events(e, f, value, s, tfs); + break; + + case LTT_TYPE_UNSIGNED_INT: + if(field_names) { + name = f->name; + if(name) + g_string_append_printf(s, "%s = ", g_quark_to_string(name)); + } + value = ltt_event_get_long_unsigned(e,f); + //g_string_append_printf(s, "%llu", value); + g_string_append_printf(s, f->fmt->str, value); + print_enum_events(e, f, value, s, tfs); + //g_string_append_printf(s, type->fmt, ltt_event_get_long_unsigned(e,f)); + break; + #if 0 - case LTT_CHAR: - case LTT_UCHAR: - { - unsigned car = ltt_event_get_unsigned(e,f); - if(field_names) { - name = ltt_field_name(f); - if(name) - g_string_append_printf(s, "%s = ", g_quark_to_string(name)); - } - if(isprint(car)) { - if(field_names) { - name = ltt_field_name(f); - if(name) - g_string_append_printf(s, "%s = ", g_quark_to_string(name)); - } - //g_string_append_printf(s, "%c", car); - g_string_append_printf(s, type->fmt, car); - } else { - g_string_append_printf(s, "\\%x", car); - } - } - break; - case LTT_FLOAT: - if(field_names) { - name = ltt_field_name(f); - if(name) - g_string_append_printf(s, "%s = ", g_quark_to_string(name)); - } - //g_string_append_printf(s, "%g", ltt_event_get_double(e,f)); - g_string_append_printf(s, type->fmt, ltt_event_get_double(e,f)); - break; + case LTT_CHAR: + case LTT_UCHAR: + { + unsigned car = ltt_event_get_unsigned(e,f); + if(field_names) { + name = ltt_field_name(f); + if(name) + g_string_append_printf(s, "%s = ", g_quark_to_string(name)); + } + if(isprint(car)) { + if(field_names) { + name = ltt_field_name(f); + if(name) + g_string_append_printf(s, "%s = ", g_quark_to_string(name)); + } + //g_string_append_printf(s, "%c", car); + g_string_append_printf(s, type->fmt, car); + } else { + g_string_append_printf(s, "\\%x", car); + } + } + break; + case LTT_FLOAT: + if(field_names) { + name = ltt_field_name(f); + if(name) + g_string_append_printf(s, "%s = ", g_quark_to_string(name)); + } + //g_string_append_printf(s, "%g", ltt_event_get_double(e,f)); + g_string_append_printf(s, type->fmt, ltt_event_get_double(e,f)); + break; #endif - case LTT_TYPE_POINTER: - if(field_names) { - name = f->name; - if(name) - g_string_append_printf(s, "%s = ", g_quark_to_string(name)); - } - g_string_append_printf(s, "0x%" PRIx64, ltt_event_get_long_unsigned(e,f)); - //g_string_append_printf(s, type->fmt, ltt_event_get_long_unsigned(e,f)); - break; - - case LTT_TYPE_STRING: - if(field_names) { - name = f->name; - if(name) - g_string_append_printf(s, "%s = ", g_quark_to_string(name)); - } - g_string_append_printf(s, "\"%s\"", ltt_event_get_string(e,f)); - break; + case LTT_TYPE_POINTER: + if(field_names) { + name = f->name; + if(name) + g_string_append_printf(s, "%s = ", g_quark_to_string(name)); + } + g_string_append_printf(s, "0x%" PRIx64, ltt_event_get_long_unsigned(e,f)); + //g_string_append_printf(s, type->fmt, ltt_event_get_long_unsigned(e,f)); + break; + + case LTT_TYPE_STRING: + if(field_names) { + name = f->name; + if(name) + g_string_append_printf(s, "%s = ", g_quark_to_string(name)); + } + g_string_append_printf(s, "\"%s\"", ltt_event_get_string(e,f)); + break; #if 0 - case LTT_ENUM: - { - GQuark value = ltt_enum_string_get(type, ltt_event_get_unsigned(e,f)); - if(field_names) { - name = ltt_field_name(f); - if(name) - g_string_append_printf(s, "%s = ", g_quark_to_string(name)); - } - if(value) - g_string_append_printf(s, "%s", g_quark_to_string(value)); - else - g_string_append_printf(s, "%lld", ltt_event_get_long_int(e,f)); - } - break; - - case LTT_ARRAY: - case LTT_SEQUENCE: - if(field_names) { - name = ltt_field_name(f); - if(name) - g_string_append_printf(s, "%s = ", g_quark_to_string(name)); - } - // g_string_append_printf(s, "{ "); - //Insert header - g_string_append_printf(s, type->header);//tested, works fine. - - - nb = ltt_event_field_element_number(e,f); - for(i = 0 ; i < nb ; i++) { - LttField *child = ltt_event_field_element_select(e,f,i); - lttv_print_field(e, child, s, field_names, i); + case LTT_ENUM: + { + GQuark value = ltt_enum_string_get(type, ltt_event_get_unsigned(e,f)); + if(field_names) { + name = ltt_field_name(f); + if(name) + g_string_append_printf(s, "%s = ", g_quark_to_string(name)); + } + if(value) + g_string_append_printf(s, "%s", g_quark_to_string(value)); + else + g_string_append_printf(s, "%lld", ltt_event_get_long_int(e,f)); + } + break; + + case LTT_ARRAY: + case LTT_SEQUENCE: + if(field_names) { + name = ltt_field_name(f); + if(name) + g_string_append_printf(s, "%s = ", g_quark_to_string(name)); + } + // g_string_append_printf(s, "{ "); + //Insert header + g_string_append_printf(s, type->header);//tested, works fine. + + + nb = ltt_event_field_element_number(e,f); + for(i = 0 ; i < nb ; i++) { + LttField *child = ltt_event_field_element_select(e,f,i); + lttv_print_field(e, child, s, field_names, i); if(iseparator); - } - //g_string_append_printf(s, " }"); - //Insert footer - g_string_append_printf(s, type->footer);//tested, works fine. - break; - - case LTT_STRUCT: - if(field_names) { - name = ltt_field_name(f); - if(name) - g_string_append_printf(s, "%s = ", g_quark_to_string(name)); - } - // g_string_append_printf(s, "{ "); - //Insert header - g_string_append_printf(s, type->header); - - nb = ltt_type_member_number(type); - for(i = 0 ; i < nb ; i++) { - LttField *element; - element = ltt_field_member(f,i); - lttv_print_field(e, element, s, field_names, i); + g_string_append_printf(s,type->separator); + } + //g_string_append_printf(s, " }"); + //Insert footer + g_string_append_printf(s, type->footer);//tested, works fine. + break; + + case LTT_STRUCT: + if(field_names) { + name = ltt_field_name(f); + if(name) + g_string_append_printf(s, "%s = ", g_quark_to_string(name)); + } + // g_string_append_printf(s, "{ "); + //Insert header + g_string_append_printf(s, type->header); + + nb = ltt_type_member_number(type); + for(i = 0 ; i < nb ; i++) { + LttField *element; + element = ltt_field_member(f,i); + lttv_print_field(e, element, s, field_names, i); if(i < nb-1) - g_string_append_printf(s,type->separator); - } - //g_string_append_printf(s, " }"); - //Insert footer - g_string_append_printf(s, type->footer); - break; - - case LTT_UNION: - if(field_names) { - name = ltt_field_name(f); - if(name) - g_string_append_printf(s, "%s = ", g_quark_to_string(name)); - } - // g_string_append_printf(s, "{ "); - g_string_append_printf(s, type->header); - - nb = ltt_type_member_number(type); - for(i = 0 ; i < nb ; i++) { - LttField *element; - element = ltt_field_member(f,i); - lttv_print_field(e, element, s, field_names, i); + g_string_append_printf(s,type->separator); + } + //g_string_append_printf(s, " }"); + //Insert footer + g_string_append_printf(s, type->footer); + break; + + case LTT_UNION: + if(field_names) { + name = ltt_field_name(f); + if(name) + g_string_append_printf(s, "%s = ", g_quark_to_string(name)); + } + // g_string_append_printf(s, "{ "); + g_string_append_printf(s, type->header); + + nb = ltt_type_member_number(type); + for(i = 0 ; i < nb ; i++) { + LttField *element; + element = ltt_field_member(f,i); + lttv_print_field(e, element, s, field_names, i); if(iseparator); - } - // g_string_append_printf(s, " }"); - g_string_append_printf(s, type->footer); - break; + g_string_append_printf(s, type->separator); + } + // g_string_append_printf(s, " }"); + g_string_append_printf(s, type->footer); + break; +#endif + case LTT_TYPE_COMPACT: + g_error("compact type printing not implemented"); + break; + case LTT_TYPE_NONE: + break; + } +} +#endif +int getProcessInfosFromEvent(LttvEvent *event, GString* processInfos) +{ + int pid=0, tid=0, ppid=0; + char *procname; + struct definition *scope; + unsigned long timestamp; + + int ret = 0; + + gboolean noError = TRUE; + + guint cpu; + LttvTraceState *state = event->state; + LttvProcessState *process; + struct bt_ctf_event *ctf_event = event->bt_event; + + cpu = lttv_traceset_get_cpuid_from_event(event); + + process = state->running_process[cpu]; + + timestamp = bt_ctf_get_timestamp(ctf_event); + + pid = process->pid; + tid = process->tgid; + ppid = process->ppid; + procname = g_quark_to_string(process->name); + if (timestamp == -1ULL) { + noError = FALSE; + } +#if 0 + if (noError) { + scope = bt_ctf_get_top_level_scope(ctf_event, BT_STREAM_EVENT_CONTEXT); + if (bt_ctf_field_get_error()) { + noError = FALSE; + } + } + if (noError) { + pid = bt_ctf_get_int64(bt_ctf_get_field(ctf_event, scope, "_pid")); + if (bt_ctf_field_get_error()) { + noError = FALSE; + } + } + if (noError) { + tid = bt_ctf_get_int64(bt_ctf_get_field(ctf_event, scope, "_tid")); + if (bt_ctf_field_get_error()) { + noError = FALSE; + } + } + if (noError) { + ppid = bt_ctf_get_int64(bt_ctf_get_field(ctf_event, scope, "_ppid")); + if (bt_ctf_field_get_error()) { + noError = FALSE; + } + } + if (noError) { + procname = bt_ctf_get_char_array(bt_ctf_get_field(ctf_event, scope, "_procname")); + if (bt_ctf_field_get_error()) { + noError = FALSE; + } + } #endif - case LTT_TYPE_COMPACT: - g_error("compact type printing not implemented"); - break; - case LTT_TYPE_NONE: - break; - } + if (noError||1) { + g_string_append_printf(processInfos, "%u, %u, %s, %u", pid, tid, procname, ppid); + } + else { + ret = -1; + } + + return ret; +} + +static +int getCPUIdFromEvent(LttvEvent *event, GString* cpuId_str) +{ + gint cpuid; + + cpuid = lttv_traceset_get_cpuid_from_event(event); + if (cpuid < 0) { + return -1; + } + g_string_append_printf(cpuId_str, "%u", cpuid); + return 0; +} + +int getFields(struct bt_ctf_event *ctf_event, struct definition const *fields, GString* fieldsStr) +{ + enum ctf_type_id fieldType = bt_ctf_field_type(fields); + int ret = 0, isSigned = -1, len = 0, i = 0; + struct definition *index_def; + switch (fieldType) { + case CTF_TYPE_INTEGER: + isSigned = bt_ctf_get_int_signedness(fields); + if (isSigned == 1) { + g_string_append_printf(fieldsStr, "%lu", bt_ctf_get_int64(fields)); + } + else if (isSigned == 0) { + g_string_append_printf(fieldsStr, "%llu", bt_ctf_get_uint64(fields)); + } + break; + case CTF_TYPE_STRING: + g_string_append_printf(fieldsStr, "%s", bt_ctf_get_string(fields)); + break; + + case CTF_TYPE_ARRAY: + g_string_append_printf(fieldsStr, "[ "); + len = bt_ctf_get_array_len(fields); + if (index_def = bt_ctf_get_index(ctf_event, fields, i)) { + for (i = 0; i < len; i++) { + if (i > 0) { + g_string_append_printf(fieldsStr, ", "); + } + bt_ctf_field_type(bt_ctf_get_index(ctf_event, fields, i)); + g_string_append_printf(fieldsStr, " "); + g_string_append_printf(fieldsStr, "[%d] = "); + getFields(ctf_event, bt_ctf_get_index(ctf_event, fields, i), fieldsStr); + } + } + else { + g_string_append_printf(fieldsStr, "%s", bt_ctf_get_char_array(fields)); + } + g_string_append_printf(fieldsStr, " ]"); + + break; + case CTF_TYPE_UNKNOWN: + default: + break; + } + return ret; +} + +int getFieldsFromEvent(struct bt_ctf_event *ctf_event, GString* fields, gboolean field_names) +{ + struct definition const * const *list = NULL; + unsigned int count; + int i = 0, j = 0, ret = 0; + gboolean noError = TRUE; + struct definition *scope; + scope = bt_ctf_get_top_level_scope(ctf_event, BT_EVENT_FIELDS); + + if (!scope) { + noError = FALSE; + } + if (noError) { + ret = bt_ctf_get_field_list(ctf_event, scope, &list, &count); + if (ret < 0) { + noError = TRUE; + } + else { + for (i = 0; i < count; i++) { + if (i > 0) { + g_string_append_printf(fields, ", "); + } + const char *name = bt_ctf_field_name(list[i]); + if (field_names) { + g_string_append_printf(fields, "%s = ", name); + } + getFields(ctf_event, list[i] ,fields); + if (bt_ctf_field_get_error()) { + continue; + } + } + } + } + if (!noError) { + ret = -1; + } + return ret; } -void lttv_event_to_string(LttEvent *e, GString *s, - gboolean mandatory_fields, gboolean field_names, LttvTracefileState *tfs) +void lttv_event_to_string(LttvEvent *event, GString *a_string, + gboolean field_names, gboolean long_version) +{ + GString* processInfos = g_string_new(""); + GString* fields = g_string_new(""); + GString* cpuId_str = g_string_new(""); + + getProcessInfosFromEvent(event, processInfos); + getFieldsFromEvent(event->bt_event, fields, field_names); + getCPUIdFromEvent(event, cpuId_str); + + g_string_set_size(a_string,0); + if(long_version){ + g_string_append_printf(a_string, "%llu %s: ", + bt_ctf_get_timestamp(event->bt_event), + bt_ctf_event_name(event->bt_event)); + } + g_string_append_printf(a_string, "{ %s }", cpuId_str->str); + + if (strcmp("", processInfos->str) < 0) { + g_string_append_printf(a_string, ", { %s }", processInfos->str); + } + if (strcmp("", fields->str) < 0) { + g_string_append_printf(a_string, ", { %s }", fields->str); + } + + g_string_free(fields, TRUE); + g_string_free(processInfos, TRUE); + g_string_free(cpuId_str, TRUE); +} +void lttv_event_get_name(LttvEvent *event,GString *a_string) +{ + g_string_set_size(a_string,0); + g_string_append_printf(a_string, " %s", bt_ctf_event_name(event->bt_event)); +} +#ifdef BABEL_CLEANUP +void lttv_event_to_string(LttEvent *e, GString *s, gboolean mandatory_fields, + gboolean field_names, LttvTracefileState *tfs) { - struct marker_field *field; - struct marker_info *info; - - LttTime time; - - guint cpu = tfs->cpu; - LttvTraceState *ts = (LttvTraceState*)tfs->parent.t_context; - LttvProcessState *process = ts->running_process[cpu]; - - s = g_string_set_size(s,0); - - info = marker_get_info_from_id(tfs->parent.tf->mdata, e->event_id); - - if(mandatory_fields) { - time = ltt_event_time(e); - g_string_append_printf(s,"%s.%s: %ld.%09ld (%s/%s_%u)", - g_quark_to_string(ltt_tracefile_name(tfs->parent.tf)), - g_quark_to_string(info->name), (long)time.tv_sec, time.tv_nsec, - g_quark_to_string( - ltt_trace_name(ltt_tracefile_get_trace(tfs->parent.tf))), - g_quark_to_string(ltt_tracefile_name(tfs->parent.tf)), cpu); - /* Print the process id and the state/interrupt type of the process */ - g_string_append_printf(s,", %u, %u, %s, %s, %u, 0x%" PRIx64", %s", - process->pid, - process->tgid, - g_quark_to_string(process->name), - g_quark_to_string(process->brand), - process->ppid, - process->current_function, - g_quark_to_string(process->state->t)); - } - - if(marker_get_num_fields(info) == 0) return; - g_string_append_printf(s, " "); - g_string_append_printf(s, "{ "); - for (field = marker_get_field(info, 0); - field != marker_get_field(info, marker_get_num_fields(info)); - field++) { - if(field != marker_get_field(info, 0)) - g_string_append_printf(s, ", "); - lttv_print_field(e, field, s, field_names, tfs); - } - g_string_append_printf(s, " }"); + struct marker_field *field; + struct marker_info *info; + + LttTime time; + + guint cpu = tfs->cpu; + LttvTraceState *ts = (LttvTraceState*)tfs->parent.t_context; + LttvProcessState *process = ts->running_process[cpu]; + + s = g_string_set_size(s,0); + + info = marker_get_info_from_id(tfs->parent.tf->mdata, e->event_id); + + if(mandatory_fields) { + time = ltt_event_time(e); + g_string_append_printf(s,"%s.%s: %ld.%09ld (%s/%s_%u)", + g_quark_to_string(ltt_tracefile_name(tfs->parent.tf)), + g_quark_to_string(info->name), (long)time.tv_sec, time.tv_nsec, + g_quark_to_string( + ltt_trace_name(ltt_tracefile_get_trace(tfs->parent.tf))), + g_quark_to_string(ltt_tracefile_name(tfs->parent.tf)), cpu); + /* Print the process id and the state/interrupt type of the process */ + g_string_append_printf(s,", %u, %u, %s, %s, %u, 0x%" PRIx64", %s", + process->pid, + process->tgid, + g_quark_to_string(process->name), + g_quark_to_string(process->brand), + process->ppid, + process->current_function, + g_quark_to_string(process->state->t)); + } + + if(marker_get_num_fields(info) == 0) return; + g_string_append_printf(s, " "); + g_string_append_printf(s, "{ "); + for (field = marker_get_field(info, 0); + field != marker_get_field(info, marker_get_num_fields(info)); + field++) { + if(field != marker_get_field(info, 0)) + g_string_append_printf(s, ", "); + lttv_print_field(e, field, s, field_names, tfs); + } + g_string_append_printf(s, " }"); } +#endif /* BABEL_CLEANUP */ static void init() { @@ -314,6 +524,6 @@ static void destroy() } LTTV_MODULE("print", "Print events", \ - "Produce a detailed text printout of events", \ - init, destroy) + "Produce a detailed text printout of events", \ + init, destroy)