Print other fields
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 17 Nov 2016 13:20:22 +0000 (08:20 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Sat, 27 May 2017 18:09:07 +0000 (14:09 -0400)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
formats/ctf/ir/event-class.c
plugins/ctf/common/metadata/visitor-generate-ir.c
plugins/text/print.c
plugins/text/text.c
plugins/text/text.h

index 03f20a7e0c506c64cf9016eeabc0ef8986dc7b63..3747a5cf9da21daad3f76ed2940ccf22a7bd437f 100644 (file)
@@ -226,7 +226,8 @@ int bt_ctf_event_class_set_attribute(
                        ret = -1;
                        goto end;
                }
-       } else if (!strcmp(name, "name") || !strcmp(name, "model.emf.uri")) {
+       } else if (!strcmp(name, "name") || !strcmp(name, "model.emf.uri") ||
+                       !strcmp(name, "loglevel_string")) {
                if (!bt_value_is_string(value)) {
                        ret = -1;
                        goto end;
index 6fcf57540874e4c94659b0bb8814eaa0abe01c39..2e175e75d7d967cb2ef66cdbef69380bcc4d43e7 100644 (file)
@@ -120,6 +120,25 @@ enum {
        _EVENT_FIELDS_SET =             _BV(6),
 };
 
+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,
+       _NR_LOGLEVELS                   = 15,
+};
+
 /* Prefixes of type aliases */
 #define _PREFIX_ALIAS                  'a'
 #define _PREFIX_ENUM                   'e'
@@ -210,6 +229,37 @@ struct ctx {
        GHashTable *stream_classes;
 };
 
+static
+const char *loglevel_str [] = {
+       [ LOGLEVEL_EMERG ] = "TRACE_EMERG",
+       [ LOGLEVEL_ALERT ] = "TRACE_ALERT",
+       [ LOGLEVEL_CRIT ] = "TRACE_CRIT",
+       [ LOGLEVEL_ERR ] = "TRACE_ERR",
+       [ LOGLEVEL_WARNING ] = "TRACE_WARNING",
+       [ LOGLEVEL_NOTICE ] = "TRACE_NOTICE",
+       [ LOGLEVEL_INFO ] = "TRACE_INFO",
+       [ LOGLEVEL_DEBUG_SYSTEM ] = "TRACE_DEBUG_SYSTEM",
+       [ LOGLEVEL_DEBUG_PROGRAM ] = "TRACE_DEBUG_PROGRAM",
+       [ LOGLEVEL_DEBUG_PROCESS ] = "TRACE_DEBUG_PROCESS",
+       [ LOGLEVEL_DEBUG_MODULE ] = "TRACE_DEBUG_MODULE",
+       [ LOGLEVEL_DEBUG_UNIT ] = "TRACE_DEBUG_UNIT",
+       [ LOGLEVEL_DEBUG_FUNCTION ] = "TRACE_DEBUG_FUNCTION",
+       [ LOGLEVEL_DEBUG_LINE ] = "TRACE_DEBUG_LINE",
+       [ LOGLEVEL_DEBUG ] = "TRACE_DEBUG",
+};
+
+static
+const char *print_loglevel(int64_t value)
+{
+       if (value < 0) {
+               return NULL;
+       }
+       if (value >= _NR_LOGLEVELS) {
+               return "<<UNKNOWN>>";
+       }
+       return loglevel_str[value];
+}
+
 /**
  * Creates a new declaration scope.
  *
@@ -3047,7 +3097,9 @@ int visit_event_decl_entry(struct ctx *ctx, struct ctf_node *node,
 
                        _SET(set, _EVENT_FIELDS_SET);
                } else if (!strcmp(left, "loglevel")) {
-                       uint64_t loglevel;
+                       uint64_t loglevel_value;
+                       const char *loglevel_str;
+                       struct bt_value *value_obj, *str_obj;
 
                        if (_IS_SET(set, _EVENT_LOGLEVEL_SET)) {
                                _PERROR_DUP_ATTR("loglevel",
@@ -3057,15 +3109,38 @@ int visit_event_decl_entry(struct ctx *ctx, struct ctf_node *node,
                        }
 
                        ret = get_unary_unsigned(&node->u.ctf_expression.right,
-                               &loglevel);
+                               &loglevel_value);
                        if (ret) {
                                _PERROR("%s", "unexpected unary expression for event declaration's \"loglevel\" attribute");
                                ret = -EINVAL;
                                goto error;
                        }
-
-                       // TODO: FIXME: set log level here
-
+                       value_obj = bt_value_integer_create_init(loglevel_value);
+                       if (!value_obj) {
+                               _PERROR("%s", "cannot allocate memory for loglevel value object");
+                               ret = -ENOMEM;
+                               goto error;
+                       }
+                       if (bt_ctf_event_class_set_attribute(event_class,
+                               "loglevel", value_obj) != BT_VALUE_STATUS_OK) {
+                               _PERROR("%s", "cannot set loglevel value");
+                               ret = -EINVAL;
+                               bt_put(value_obj);
+                               goto error;
+                       }
+                       loglevel_str = print_loglevel(loglevel_value);
+                       if (loglevel_str) {
+                               str_obj = bt_value_string_create_init(loglevel_str);
+                               if (bt_ctf_event_class_set_attribute(event_class,
+                                               "loglevel_string", str_obj) != BT_VALUE_STATUS_OK) {
+                                       _PERROR("%s", "cannot set loglevel string");
+                                       ret = -EINVAL;
+                                       bt_put(str_obj);
+                                       goto error;
+                               }
+                               bt_put(str_obj);
+                       }
+                       bt_put(value_obj);
                        _SET(set, _EVENT_LOGLEVEL_SET);
                } else if (!strcmp(left, "model.emf.uri")) {
                        char *right;
index a7b67409ffbc7165e01940289d76c04589d42483..53adab4c738d56bd43aa65a3f4cc7cc8da23c0f3 100644 (file)
@@ -189,7 +189,7 @@ end:
 
 static
 enum bt_component_status print_event_timestamp(struct text_component *text,
-               struct bt_ctf_event *event)
+               struct bt_ctf_event *event, bool *start_line)
 {
        bool print_names = text->options.print_header_field_names;
        enum bt_component_status ret = BT_COMPONENT_STATUS_OK;
@@ -219,7 +219,10 @@ enum bt_component_status print_event_timestamp(struct text_component *text,
                print_timestamp_wall(text, clock, event);
        }
 
-       fputs(print_names ? ", " : "] ", out);
+       if (!print_names)
+               fputs("] ", out);
+       *start_line = !print_names;
+
        if (!text->options.print_delta_field) {
                goto end;
        }
@@ -238,25 +241,219 @@ enum bt_component_status print_event_header(struct text_component *text,
        bool print_names = text->options.print_header_field_names;
        enum bt_component_status ret = BT_COMPONENT_STATUS_OK;
        struct bt_ctf_event_class *event_class = NULL;
+       struct bt_ctf_stream_class *stream_class = NULL;
+       struct bt_ctf_trace *trace_class = NULL;
 
        event_class = bt_ctf_event_get_class(event);
        if (!event_class) {
                ret = BT_COMPONENT_STATUS_ERROR;
                goto end;
        }
+       stream_class = bt_ctf_event_class_get_stream_class(event_class);
+       if (!stream_class) {
+               ret = BT_COMPONENT_STATUS_ERROR;
+               goto end;
+       }
+       trace_class = bt_ctf_stream_class_get_trace(stream_class);
+       if (!trace_class) {
+               ret = BT_COMPONENT_STATUS_ERROR;
+               goto end;
+       }
        if (!text->start_line) {
                fputs(", ", text->out);
        }
        text->start_line = false;
-       ret = print_event_timestamp(text, event);
+       ret = print_event_timestamp(text, event, &text->start_line);
        if (ret != BT_COMPONENT_STATUS_OK) {
                goto end;
        }
+       if (text->options.print_trace_field) {
+               const char *name;
+
+               name = bt_ctf_trace_get_name(trace_class);
+               if (name) {
+                       if (!text->start_line) {
+                               fputs(", ", text->out);
+                       }
+                       text->start_line = false;
+                       if (print_names) {
+                               fputs("trace = ", text->out);
+                       }
+                       fprintf(text->out, "%s", name);
+               }
+       }
+       if (text->options.print_trace_hostname_field) {
+               struct bt_value *hostname_str;
+
+               hostname_str = bt_ctf_trace_get_environment_field_value_by_name(trace_class,
+                               "hostname");
+               if (hostname_str) {
+                       const char *str;
+
+                       if (!text->start_line) {
+                               fputs(", ", text->out);
+                       }
+                       text->start_line = false;
+                       if (print_names) {
+                               fputs("trace:hostname = ", text->out);
+                       }
+                       if (bt_value_string_get(hostname_str, &str)
+                                       == BT_VALUE_STATUS_OK) {
+                               fprintf(text->out, "%s", str);
+                       }
+                       bt_put(hostname_str);
+               }
+       }
+       if (text->options.print_trace_domain_field) {
+               struct bt_value *domain_str;
+
+               domain_str = bt_ctf_trace_get_environment_field_value_by_name(trace_class,
+                               "domain");
+               if (domain_str) {
+                       const char *str;
+
+                       if (!text->start_line) {
+                               fputs(", ", text->out);
+                       }
+                       text->start_line = false;
+                       if (print_names) {
+                               fputs("trace:domain = ", text->out);
+                       }
+                       if (bt_value_string_get(domain_str, &str)
+                                       == BT_VALUE_STATUS_OK) {
+                               fprintf(text->out, "%s", str);
+                       }
+                       bt_put(domain_str);
+               }
+       }
+       if (text->options.print_trace_procname_field) {
+               struct bt_value *procname_str;
+
+               procname_str = bt_ctf_trace_get_environment_field_value_by_name(trace_class,
+                               "procname");
+               if (procname_str) {
+                       const char *str;
+
+                       if (!text->start_line) {
+                               fputs(", ", text->out);
+                       }
+                       text->start_line = false;
+                       if (print_names) {
+                               fputs("trace:procname = ", text->out);
+                       }
+                       if (bt_value_string_get(procname_str, &str)
+                                       == BT_VALUE_STATUS_OK) {
+                               fprintf(text->out, "%s", str);
+                       }
+                       bt_put(procname_str);
+               }
+       }
+       if (text->options.print_trace_vpid_field) {
+               struct bt_value *vpid_value;
+
+               vpid_value = bt_ctf_trace_get_environment_field_value_by_name(trace_class,
+                               "vpid");
+               if (vpid_value) {
+                       int64_t value;
+
+                       if (!text->start_line) {
+                               fputs(", ", text->out);
+                       }
+                       text->start_line = false;
+                       if (print_names) {
+                               fputs("trace:vpid = ", text->out);
+                       }
+                       if (bt_value_integer_get(vpid_value, &value)
+                                       == BT_VALUE_STATUS_OK) {
+                               fprintf(text->out, "(%" PRId64 ")", value);
+                       }
+                       bt_put(vpid_value);
+               }
+       }
+       if (text->options.print_loglevel_field) {
+               struct bt_value *loglevel_str, *loglevel_value;
+
+               loglevel_str = bt_ctf_event_class_get_attribute_value_by_name(event_class,
+                               "loglevel_string");
+               loglevel_value = bt_ctf_event_class_get_attribute_value_by_name(event_class,
+                               "loglevel");
+               if (loglevel_str || loglevel_value) {
+                       bool has_str = false;
+
+                       if (!text->start_line) {
+                               fputs(", ", text->out);
+                       }
+                       text->start_line = false;
+                       if (print_names) {
+                               fputs("loglevel = ", text->out);
+                       }
+                       if (loglevel_str) {
+                               const char *str;
+
+                               if (bt_value_string_get(loglevel_str, &str)
+                                               == BT_VALUE_STATUS_OK) {
+                                       fprintf(text->out, "%s", str);
+                                       has_str = true;
+                               }
+                       }
+                       if (loglevel_value) {
+                               int64_t value;
+
+                               if (bt_value_integer_get(loglevel_value, &value)
+                                               == BT_VALUE_STATUS_OK) {
+                                       fprintf(text->out, "%s(%" PRId64 ")",
+                                               has_str ? " " : "", value);
+                               }
+                       }
+                       bt_put(loglevel_str);
+                       bt_put(loglevel_value);
+               }
+       }
+       if (text->options.print_emf_field) {
+               struct bt_value *uri_str;
+
+               uri_str = bt_ctf_event_class_get_attribute_value_by_name(event_class,
+                               "model.emf.uri");
+               if (uri_str) {
+                       if (!text->start_line) {
+                               fputs(", ", text->out);
+                       }
+                       text->start_line = false;
+                       if (print_names) {
+                               fputs("model.emf.uri = ", text->out);
+                       }
+                       if (uri_str) {
+                               const char *str;
+
+                               if (bt_value_string_get(uri_str, &str)
+                                               == BT_VALUE_STATUS_OK) {
+                                       fprintf(text->out, "%s", str);
+                               }
+                       }
+                       bt_put(uri_str);
+               }
+       }
+       if (text->options.print_callsite_field) {
+               if (!text->start_line) {
+                       fputs(", ", text->out);
+               }
+               text->start_line = false;
+               if (print_names) {
+                       fputs("callsite = ", text->out);
+               }
+               /* TODO */
+       }
+       if (!text->start_line) {
+               fputs(", ", text->out);
+       }
+       text->start_line = false;
        if (print_names) {
                fputs("name = ", text->out);
        }
        fputs(bt_ctf_event_class_get_name(event_class), text->out);
 end:
+       bt_put(trace_class);
+       bt_put(stream_class);
        bt_put(event_class);
        return ret;
 }
index da659eeb741bbcf6f226f4de19f7c8db4c3e30fc..f9134b778fedea0d9d32b75aa0de68159dc6c62f 100644 (file)
@@ -68,25 +68,6 @@ const char *plugin_options[] = {
        "field-callsite",
 };
 
-static
-const char *loglevel_str [] = {
-       [LOGLEVEL_EMERG] =              "TRACE_EMERG",
-       [LOGLEVEL_ALERT] =              "TRACE_ALERT",
-       [LOGLEVEL_CRIT] =               "TRACE_CRIT",
-       [LOGLEVEL_ERR] =                "TRACE_ERR",
-       [LOGLEVEL_WARNING] =            "TRACE_WARNING",
-       [LOGLEVEL_NOTICE] =             "TRACE_NOTICE",
-       [LOGLEVEL_INFO] =               "TRACE_INFO",
-       [LOGLEVEL_DEBUG_SYSTEM] =       "TRACE_DEBUG_SYSTEM",
-       [LOGLEVEL_DEBUG_PROGRAM] =      "TRACE_DEBUG_PROGRAM",
-       [LOGLEVEL_DEBUG_PROCESS] =      "TRACE_DEBUG_PROCESS",
-       [LOGLEVEL_DEBUG_MODULE] =       "TRACE_DEBUG_MODULE",
-       [LOGLEVEL_DEBUG_UNIT] =         "TRACE_DEBUG_UNIT",
-       [LOGLEVEL_DEBUG_FUNCTION] =     "TRACE_DEBUG_FUNCTION",
-       [LOGLEVEL_DEBUG_LINE] =         "TRACE_DEBUG_LINE",
-       [LOGLEVEL_DEBUG] =              "TRACE_DEBUG",
-};
-
 static
 void destroy_text_data(struct text_component *text)
 {
index f1ff92dfda6dc649709c093b29925523123e8536..103dc07977d5be48e89d9a0f7b9494c973cd0c9e 100644 (file)
 #include <babeltrace/babeltrace-internal.h>
 #include <babeltrace/plugin/component.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,
-};
-
 enum text_default {
        TEXT_DEFAULT_UNSET,
        TEXT_DEFAULT_SHOW,
This page took 0.031385 seconds and 4 git commands to generate.