X-Git-Url: http://git.liburcu.org/?a=blobdiff_plain;f=lttv%2Flttv%2Fprint.c;h=57936e648c89c1ce38e977668a472f872a802d46;hb=b9ce0bad7daf7c0a2333c91fdb1e35d602afe17f;hp=d54f5f0dd65d4240cd045f69388e3780a585b66d;hpb=90e19f82bca635a1ba52b8a50b64e484bd19c14f;p=lttv.git diff --git a/lttv/lttv/print.c b/lttv/lttv/print.c index d54f5f0d..57936e64 100644 --- a/lttv/lttv/print.c +++ b/lttv/lttv/print.c @@ -13,8 +13,8 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, - * MA 02111-1307, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. */ /* print.c @@ -32,23 +32,22 @@ #include #include #include +#ifdef BABEL_CLEANUP #include #include +#endif #include -#include -#include -#include #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) { - 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); LttvNameTables *nt = ts->name_tables; @@ -257,7 +256,214 @@ void lttv_print_field(LttEvent *e, struct marker_field *f, GString *s, break; } } +#endif +int getProcessInfosFromEvent(LttvEvent *event, GString* processInfos) +{ + int pid=0, tid=0, ppid=0; + const char *procname; + + 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 + if (noError||1) { + g_string_append_printf(processInfos, "%u, %u, %s, %u. %s, %s", pid, tid, procname, ppid, g_quark_to_string(process->state->t), g_quark_to_string(process->state->s)); + } + 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 bt_definition const *fields, GString* fieldsStr) +{ + enum ctf_type_id fieldType = bt_ctf_field_type(bt_ctf_get_decl_from_def(fields)); + int ret = 0, isSigned = -1, len = 0, i = 0; + const struct bt_definition *index_def; + switch (fieldType) { + case CTF_TYPE_INTEGER: + isSigned = bt_ctf_get_int_signedness(bt_ctf_get_decl_from_def(fields)); + if (isSigned == 1) { + g_string_append_printf(fieldsStr, "%lu", bt_ctf_get_int64(fields)); + } + else if (isSigned == 0) { + g_string_append_printf(fieldsStr, "%" PRIu64 , 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(bt_ctf_get_decl_from_def(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] = ",i); + 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: + g_string_append_printf(fieldsStr, "TYPE UNKNOWN"); + default: + g_string_append_printf(fieldsStr, "TYPE UNIMP %i",fieldType ); + break; + } + return ret; +} + +int getFieldsFromEvent(struct bt_ctf_event *ctf_event, GString* fields, gboolean field_names) +{ + struct bt_definition const * const *list = NULL; + unsigned int count; + int i = 0, ret = 0; + gboolean noError = TRUE; + const struct bt_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(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,"%" PRIu64 " %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) { @@ -283,11 +489,10 @@ void lttv_event_to_string(LttEvent *e, GString *s, gboolean mandatory_fields, 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", + g_string_append_printf(s,", %u, %u, %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)); @@ -305,6 +510,7 @@ void lttv_event_to_string(LttEvent *e, GString *s, gboolean mandatory_fields, } g_string_append_printf(s, " }"); } +#endif /* BABEL_CLEANUP */ static void init() {