Add loglevel support
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 6 Dec 2011 16:47:53 +0000 (11:47 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 6 Dec 2011 16:47:53 +0000 (11:47 -0500)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
converter/babeltrace.c
formats/ctf-text/ctf-text.c
formats/ctf/metadata/ctf-visitor-generate-io-struct.c
include/babeltrace/babeltrace-internal.h
include/babeltrace/ctf-ir/metadata.h

index 2c1c44404eea61ad8c1b7e0427708b26a0630e6a..2870df8fdbdb03216b18c15c2f0e3bd2644b84ce 100644 (file)
@@ -99,7 +99,8 @@ static void usage(FILE *fp)
        fprintf(fp, "                                 Available field names:\n");
        fprintf(fp, "                                     (payload OR args OR arg)\n");
        fprintf(fp, "                                     all, scope, header, (context OR ctx)\n");
-       fprintf(fp, "                                     trace, trace:domain, trace:procname, trace:vpid\n");
+       fprintf(fp, "                                     trace, trace:domain, trace:procname, trace:vpid,\n");
+       fprintf(fp, "                                     loglevel.\n");
        fprintf(fp, "                                        (payload active by default)\n");
        list_formats(fp);
        fprintf(fp, "\n");
@@ -134,6 +135,8 @@ static int get_names_args(poptContext *pc)
                        opt_trace_procname = 1;
                else if (!strcmp(str, "trace:vpid"))
                        opt_trace_vpid = 1;
+               else if (!strcmp(str, "loglevel"))
+                       opt_loglevel = 1;
                else {
                        fprintf(stdout, "[error] unknown field name type %s\n", str);
                        return -EINVAL;
index 9b5f98be1a23bd6d90104f836e9ea20977dbb291..1b3e4bc73438716289662696e8da6c4b33410c2e 100644 (file)
@@ -42,7 +42,8 @@ int opt_all_field_names,
        opt_trace_name,
        opt_trace_domain,
        opt_trace_procname,
-       opt_trace_vpid;
+       opt_trace_vpid,
+       opt_loglevel;
 
 enum field_item {
        ITEM_SCOPE,
@@ -244,6 +245,21 @@ int ctf_text_write_event(struct stream_pos *ppos,
                        fprintf(pos->fp, ", ");
                dom_print = 1;
        }
+       if ((opt_loglevel || opt_all_field_names) && event_class->loglevel_identifier != 0) {
+               set_field_names_print(pos, ITEM_HEADER);
+               if (pos->print_names) {
+                       fprintf(pos->fp, "loglevel = ");
+               } else if (dom_print) {
+                       fprintf(pos->fp, ":");
+               }
+
+               fprintf(pos->fp, "%s (%lld)",
+                       g_quark_to_string(event_class->loglevel_identifier),
+                       (long long) event_class->loglevel_value);
+               if (pos->print_names)
+                       fprintf(pos->fp, ", ");
+               dom_print = 1;
+       }
        if (dom_print && !pos->print_names)
                fprintf(pos->fp, " ");
        set_field_names_print(pos, ITEM_HEADER);
index 82af10a10f259be1fd05a6467bc210aa13c0ae83..6e828fcd13059b20f466a53eb07f4ea7cf59a23a 100644 (file)
@@ -104,6 +104,23 @@ int get_unary_unsigned(struct cds_list_head *head, uint64_t *value)
        return 0;
 }
 
+static
+int get_unary_signed(struct cds_list_head *head, int64_t *value)
+{
+       struct ctf_node *node;
+       int i = 0;
+
+       cds_list_for_each_entry(node, head, siblings) {
+               assert(node->type == NODE_UNARY_EXPRESSION);
+               assert(node->u.unary_expression.type == UNARY_UNSIGNED_CONSTANT);
+               assert(node->u.unary_expression.link == UNARY_LINK_UNKNOWN);
+               assert(i == 0);
+               *value = node->u.unary_expression.u.signed_constant;
+               i++;
+       }
+       return 0;
+}
+
 static
 int get_unary_uuid(struct cds_list_head *head, uuid_t *uuid)
 {
@@ -1550,6 +1567,36 @@ int ctf_event_declaration_visit(FILE *fd, int depth, struct ctf_node *node, stru
                                goto error;
                        }
                        event->fields_decl = container_of(declaration, struct declaration_struct, p);
+               } else if (!strcmp(left, "loglevel.identifier")) {
+                       char *right;
+
+                       if (CTF_EVENT_FIELD_IS_SET(event, loglevel_identifier)) {
+                               fprintf(fd, "[error] %s: identifier already declared in event declaration\n", __func__);
+                               ret = -EPERM;
+                               goto error;
+                       }
+                       right = concatenate_unary_strings(&node->u.ctf_expression.right);
+                       if (!right) {
+                               fprintf(fd, "[error] %s: unexpected unary expression for event identifier\n", __func__);
+                               ret = -EINVAL;
+                               goto error;
+                       }
+                       event->loglevel_identifier = g_quark_from_string(right);
+                       g_free(right);
+                       CTF_EVENT_SET_FIELD(event, loglevel_identifier);
+               } else if (!strcmp(left, "loglevel.value")) {
+                       if (CTF_EVENT_FIELD_IS_SET(event, loglevel_value)) {
+                               fprintf(fd, "[error] %s: loglevel value already declared in event declaration\n", __func__);
+                               ret = -EPERM;
+                               goto error;
+                       }
+                       ret = get_unary_signed(&node->u.ctf_expression.right, &event->loglevel_value);
+                       if (ret) {
+                               fprintf(fd, "[error] %s: unexpected unary expression for event loglevel value\n", __func__);
+                               ret = -EINVAL;
+                               goto error;
+                       }
+                       CTF_EVENT_SET_FIELD(event, loglevel_value);
                } else {
                        fprintf(fd, "[error] %s: attribute \"%s\" is unknown in event declaration.\n", __func__, left);
                        ret = -EINVAL;
index 58af9c90e3605485d924610ab0a4001aff2e52e5..991e23c45a145af2c62e41344578c085811d3404 100644 (file)
@@ -37,6 +37,7 @@ extern int opt_all_field_names,
        opt_trace_name,
        opt_trace_domain,
        opt_trace_procname,
-       opt_trace_vpid;
+       opt_trace_vpid,
+       opt_loglevel;
 
 #endif
index 3f03504ea1850bda7fc67e305270b8180703b91e..2d216f2fa23d27385dc0b21b5555cb7047ec25a1 100644 (file)
@@ -171,11 +171,15 @@ struct ctf_event {
        GQuark name;
        uint64_t id;            /* Numeric identifier within the stream */
        uint64_t stream_id;
+       GQuark loglevel_identifier;
+       int64_t loglevel_value;
 
        enum {                                  /* Fields populated mask */
-               CTF_EVENT_name  =       (1 << 0),
-               CTF_EVENT_id    =       (1 << 1),
-               CTF_EVENT_stream_id =   (1 << 2),
+               CTF_EVENT_name  =               (1 << 0),
+               CTF_EVENT_id    =               (1 << 1),
+               CTF_EVENT_stream_id =           (1 << 2),
+               CTF_EVENT_loglevel_identifier = (1 << 3),
+               CTF_EVENT_loglevel_value =      (1 << 4),
        } field_mask;
 };
 
This page took 0.039623 seconds and 4 git commands to generate.