text: wip event formating
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 8 Sep 2016 15:58:54 +0000 (11:58 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Sat, 27 May 2017 18:09:06 +0000 (14:09 -0400)
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
plugins/ctf/fs/fs.h
plugins/text/Makefile.am
plugins/text/text.c

index f3d442e466bbf7e33d6be8c8822c394b3b6ebaec..f4bd86c9d9b515065be5bf2d6a0e447a7e4801fa 100644 (file)
@@ -1,5 +1,5 @@
-#ifndef BABELTRACE_PLUGIN_CTF_FS_INTERNAL_H
-#define BABELTRACE_PLUGIN_CTF_FS_INTERNAL_H
+#ifndef BABELTRACE_PLUGIN_CTF_FS_H
+#define BABELTRACE_PLUGIN_CTF_FS_H
 
 /*
  * BabelTrace - CTF on File System Component
@@ -92,4 +92,4 @@ BT_HIDDEN
 enum bt_component_status ctf_fs_init(struct bt_component *source,
                struct bt_value *params);
 
-#endif /* BABELTRACE_PLUGIN_CTF_FS_INTERNAL_H */
+#endif /* BABELTRACE_PLUGIN_CTF_FS_H */
index ccdf4cb7b808c6a5dfdd8f9fed8ffe03b40a6ce1..8b12e3124d51adaf83a69ae7a2417e4c84d4c381 100644 (file)
@@ -7,7 +7,8 @@ plugin_LTLIBRARIES = libbabeltrace-plugin-ctf-text.la
 
 # ctf-text plugin
 libbabeltrace_plugin_ctf_text_la_SOURCES = \
-       text.c
+       text.h text.c \
+       print.c
 
 libbabeltrace_plugin_ctf_text_la_LDFLAGS = \
        -version-info $(BABELTRACE_LIBRARY_VERSION)
index 9d72e3a1ed76a0b0765f66f2c33c9c3e1e35f3de..fc32c75e90d57e027249c7411fb1469c6ff9cd3c 100644 (file)
 #include <babeltrace/plugin/component.h>
 #include <babeltrace/plugin/sink.h>
 #include <babeltrace/plugin/notification/notification.h>
+#include <babeltrace/plugin/notification/event.h>
 #include <stdio.h>
 #include <stdbool.h>
 #include <glib.h>
-
-enum loglevel {
-        LOGLEVEL_EMERG                  = 0,
-        LOGLEVEL_ALERT                  = 1,
-        LOGLEVEL_CRIT                   = 2,
-        LOGLEVEL_ERR                    = 3,
-        LOGLEVEL_WARNING                = 4,
-        LOGLEVEL_NOTICE                 = 5,
-        LOGLEVEL_INFO                   = 6,
-        LOGLEVEL_DEBUG_SYSTEM           = 7,
-        LOGLEVEL_DEBUG_PROGRAM          = 8,
-        LOGLEVEL_DEBUG_PROCESS          = 9,
-        LOGLEVEL_DEBUG_MODULE           = 10,
-        LOGLEVEL_DEBUG_UNIT             = 11,
-        LOGLEVEL_DEBUG_FUNCTION         = 12,
-        LOGLEVEL_DEBUG_LINE             = 13,
-        LOGLEVEL_DEBUG                  = 14,
-};
+#include "text.h"
 
 static
 const char *loglevel_str [] = {
@@ -71,36 +55,41 @@ const char *loglevel_str [] = {
        [LOGLEVEL_DEBUG] =              "TRACE_DEBUG",
 };
 
-struct text_options {
-       bool print_scope_field_names : 1;
-       bool print_header_field_names : 1;
-       bool print_context_field_names : 1;
-       bool print_payload_field_names : 1;
-       bool print_delta_field : 1;
-       bool print_loglevel_field : 1;
-       bool print_trace_field : 1;
-       bool print_trace_domain_field : 1;
-       bool print_trace_procname_field : 1;
-       bool print_trace_vpid_field : 1;
-       bool print_trace_hostname_field : 1;
-       bool no_size_limit : 1;
-};
-
-struct text_component {
-       struct text_options options;
-       FILE *out, *err;
-};
+static
+void destroy_stream_timestamp(void *stream_timestamp)
+{
+       g_free(stream_timestamp);
+}
 
 static
-struct text_component *create_text(void)
+void destroy_text_data(struct text_component *text)
 {
-       return g_new0(struct text_component, 1);
+       if (text->stream_timestamps) {
+               g_hash_table_destroy(text->stream_timestamps);
+       }
+       g_free(text);
 }
 
 static
-void destroy_text_data(struct text_component *data)
+struct text_component *create_text(void)
 {
-       g_free(data);
+       struct text_component *text;
+
+       text = g_new0(struct text_component, 1);
+       if (!text) {
+               goto end;
+       }
+
+       text->stream_timestamps = g_hash_table_new_full(
+                       NULL, NULL, NULL, destroy_stream_timestamp);
+       if (!text->stream_timestamps) {
+               goto error;
+       }
+end:
+       return text;
+error:
+       destroy_text_data(text);
+       return NULL;
 }
 
 static void destroy_text(struct bt_component *component)
@@ -114,6 +103,14 @@ static
 enum bt_component_status handle_notification(struct bt_component *component,
        struct bt_notification *notification)
 {
+       enum bt_component_status ret = BT_COMPONENT_STATUS_OK;
+       struct text_component *text = bt_component_get_private_data(component);
+
+       if (!text) {
+               ret = BT_COMPONENT_STATUS_ERROR;
+               goto end;
+       }
+
        switch (bt_notification_get_type(notification)) {
        case BT_NOTIFICATION_TYPE_PACKET_START:
                puts("<packet>");
@@ -122,15 +119,29 @@ enum bt_component_status handle_notification(struct bt_component *component,
                puts("</packet>");
                break;
        case BT_NOTIFICATION_TYPE_EVENT:
+       {
+               struct bt_ctf_event *event = bt_notification_event_get_event(
+                               notification);
+
                puts("\t<event>");
+               if (!event) {
+                       ret = BT_COMPONENT_STATUS_ERROR;
+                       goto end;
+               }
+               ret = text_print_event(text, event);
+               if (ret != BT_COMPONENT_STATUS_OK) {
+                       goto end;
+               }
                break;
+       }
        case BT_NOTIFICATION_TYPE_STREAM_END:
                puts("</stream>");
                break;
        default:
                puts("Unhandled notification type");
        }
-       return BT_COMPONENT_STATUS_OK;
+end:
+       return ret;
 }
 
 static
@@ -178,5 +189,7 @@ BT_PLUGIN_AUTHOR("Jérémie Galarneau");
 BT_PLUGIN_LICENSE("MIT");
 
 BT_PLUGIN_COMPONENT_CLASSES_BEGIN
-BT_PLUGIN_SINK_COMPONENT_CLASS_ENTRY("text", "Formats CTF-IR to text. Formerly known as ctf-text.", text_component_init)
+BT_PLUGIN_SINK_COMPONENT_CLASS_ENTRY("text",
+               "Formats CTF-IR to text. Formerly known as ctf-text.",
+               text_component_init)
 BT_PLUGIN_COMPONENT_CLASSES_END
This page took 0.02882 seconds and 4 git commands to generate.