Printing events using babeltrace
authorHassan Makkeh <hassan.makke@polymtl.ca>
Sun, 11 Mar 2012 05:28:16 +0000 (00:28 -0500)
committerYannick Brosseau <yannick.brosseau@gmail.com>
Mon, 11 Jun 2012 21:34:33 +0000 (17:34 -0400)
Disable the depanalysis and formatedDump until they are ported

Signed-off-by: Hassan Makke <hassan.makke@polymtl.ca>
Signed-off-by: Yannick Brosseau <yannick.brosseau@gmail.com>
lttv/lttv/print.c
lttv/lttv/print.h
lttv/modules/text/Makefile.am
lttv/modules/text/textDump.c

index d54f5f0dd65d4240cd045f69388e3780a585b66d..9731b3ed37f505fe2fb6bcb47b2dd24260f720b6 100644 (file)
@@ -41,6 +41,7 @@
 #include <stdio.h>
 #include <ctype.h>
 #include <ltt/ltt-private.h>
+#include <babeltrace/ctf/events.h>
 #include <string.h>
 #include <inttypes.h>
 
@@ -258,6 +259,210 @@ void lttv_print_field(LttEvent *e, struct marker_field *f, GString *s,
        }
 }
 
+int getProcessInfosFromEvent(struct bt_ctf_event *ctf_event, GString* processInfos)
+{
+       int pid, tid, ppid;
+       char *procname;
+       struct definition *scope;
+       unsigned long timestamp;
+
+       int ret = 0;
+
+       gboolean noError = TRUE;
+
+       timestamp = bt_ctf_get_timestamp(ctf_event);
+       if (timestamp == -1ULL) {
+               noError = FALSE;
+       }
+       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;
+               }
+       }
+
+       if (noError) {
+               g_string_append_printf(processInfos, "%u, %u, %s, %u", pid, tid, procname, ppid);
+       }
+       else {
+               ret = -1;
+       }
+
+       return ret;
+}
+
+
+int getCPUIdFromEvent(struct bt_ctf_event *ctf_event, GString* cpuId_str)
+{
+       struct definition *scope;
+       unsigned long timestamp;
+       unsigned int cpu_id;
+       int ret = 0;
+
+       gboolean noError = TRUE;
+
+       timestamp = bt_ctf_get_timestamp(ctf_event);
+       if (timestamp == -1ULL) {
+               noError = FALSE;
+       }
+       if (noError) {
+               scope = bt_ctf_get_top_level_scope(ctf_event, BT_STREAM_PACKET_CONTEXT);
+               if (bt_ctf_field_get_error()) {
+                       noError = FALSE;
+               }
+       }
+       if (noError) {
+               cpu_id = bt_ctf_get_uint64(bt_ctf_get_field(ctf_event, scope, "cpu_id"));
+               if (bt_ctf_field_get_error()) {
+                       noError = FALSE;
+               }
+               else {
+                       g_string_append_printf(cpuId_str, "%u", cpu_id);
+               }
+       }
+
+       if (!noError) {
+               ret = -1;
+       }
+
+       return ret;
+}
+
+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(struct bt_ctf_event *event, GString *a_string, gboolean field_names)
+{
+       GString* processInfos = g_string_new("");
+       GString* fields = g_string_new("");
+       GString* cpuId_str = g_string_new("");
+
+       getProcessInfosFromEvent(event, processInfos);
+       getFieldsFromEvent(event, fields, field_names);
+       getCPUIdFromEvent(event, cpuId_str);
+
+       g_string_set_size(a_string,0);
+
+       g_string_append_printf(a_string, "%llu %s: { %s }", bt_ctf_get_timestamp(event), bt_ctf_event_name(event), 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);
+}
+
+#ifdef BABEL_CLEANUP
 void lttv_event_to_string(LttEvent *e, GString *s, gboolean mandatory_fields,
                gboolean field_names, LttvTracefileState *tfs)
 { 
@@ -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()
 {
index 904028106068741e32f5244de4d638415cb3a504..e5da0e989a45b448590d8e7c47328fea92962a39 100644 (file)
  * Use these functions to print textually event fields. 
  */
 
-
+struct bt_ctf_event;
 
 void lttv_print_field(LttEvent *e, struct marker_field *f, GString *s,
                gboolean field_names, LttvTracefileState *tfs);
-
+#ifdef BABEL_CLEANUP
 void lttv_event_to_string(LttEvent *e, GString *s, gboolean mandatory_fields,
                gboolean field_names, LttvTracefileState *tfs);
+#endif
+void lttv_event_to_string(struct bt_ctf_event *event, GString *a_string, gboolean field_names);
 
index 4f11cb6e174ee25b24b1dcd9a38b805bcc3c7fb4..b537019951f37449733462474af4fa6a4ada8ee1 100644 (file)
@@ -3,15 +3,19 @@ AM_LDFLAGS = $(MODULE_LDFLAGS)
 
 libdir = ${lttvplugindir}
 
-lib_LTLIBRARIES = libtextDump.la libbatchAnalysis.la libtextFilter.la libprecomputeState.la libdepanalysis.la libsync_chain_batch.la libformattedDump.la
+lib_LTLIBRARIES = libtextDump.la libbatchAnalysis.la libtextFilter.la libprecomputeState.la libsync_chain_batch.la
+
+##
+# Libraries pending babeltrace conversion
+#libdepanalysis.la libformattedDump.la
 
 libtextDump_la_SOURCES = textDump.c
 libbatchAnalysis_la_SOURCES = batchAnalysis.c
 libtextFilter_la_SOURCES = textFilter.c
 libprecomputeState_la_SOURCES = precomputeState.c
-libdepanalysis_la_SOURCES = depanalysis.c sstack.c
+#libdepanalysis_la_SOURCES = depanalysis.c sstack.c
 libsync_chain_batch_la_SOURCES = sync_chain_batch.c
-libformattedDump_la_SOURCES = formattedDump.c
+#libformattedDump_la_SOURCES = formattedDump.c
 
 noinst_HEADERS = \
        batchanalysis.h \
index 004384a8885321563bed9153a25e540f03618bae..b294b2cd87441286aecdc03410901d6530f5af58 100644 (file)
@@ -304,7 +304,6 @@ static gboolean write_trace_header(void *hook_data, void *call_data)
   return FALSE;
 }
 
-
 static int write_event_content(void *hook_data, void *call_data)
 {
   gboolean result;
@@ -348,10 +347,10 @@ static int write_event_content(void *hook_data, void *call_data)
 #ifdef BABEL_CLEANUP
   lttv_event_to_string(e, a_string, TRUE, !a_no_field_names, tfs);
 #endif
-  g_string_set_size(a_string,0);
-  g_string_append_printf(a_string, " %s %llu", 
-                        bt_ctf_event_name(event),
-                        bt_ctf_get_timestamp_raw(event));
+
+  /* TODO 2012-03-12 Add state info */
+  lttv_event_to_string(event, a_string, !a_no_field_names);
+
 #ifdef BABEL_CLEANUP
   if(a_state) {
     g_string_append_printf(a_string, " %s ",
This page took 0.027696 seconds and 4 git commands to generate.