Text output identical with babeltrace 1
[babeltrace.git] / plugins / text / print.c
index 958b94d8dd580cb26d5f159364a003d61ee7946f..e742f2184c19236c8ffce7ab9c582e67fb8b741f 100644 (file)
@@ -46,9 +46,9 @@
 #define COLOR_NAME                     BT_COMMON_COLOR_BOLD
 #define COLOR_FIELD_NAME               BT_COMMON_COLOR_FG_CYAN
 #define COLOR_RST                      BT_COMMON_COLOR_RESET
-#define COLOR_STRING_VALUE             BT_COMMON_COLOR_BOLD BT_COMMON_COLOR_FG_GREEN
-#define COLOR_NUMBER_VALUE             BT_COMMON_COLOR_BOLD BT_COMMON_COLOR_FG_RED
-#define COLOR_ENUM_MAPPING_NAME                BT_COMMON_COLOR_BOLD BT_COMMON_COLOR_FG_CYAN
+#define COLOR_STRING_VALUE             BT_COMMON_COLOR_BOLD
+#define COLOR_NUMBER_VALUE             BT_COMMON_COLOR_BOLD
+#define COLOR_ENUM_MAPPING_NAME                BT_COMMON_COLOR_BOLD
 #define COLOR_UNKNOWN                  BT_COMMON_COLOR_BOLD BT_COMMON_COLOR_FG_RED
 #define COLOR_EVENT_NAME               BT_COMMON_COLOR_BOLD BT_COMMON_COLOR_FG_MAGENTA
 #define COLOR_TIMESTAMP                        BT_COMMON_COLOR_BOLD BT_COMMON_COLOR_FG_YELLOW
@@ -69,7 +69,8 @@ struct timestamp {
 
 static
 enum bt_component_status print_field(struct text_component *text,
-               struct bt_ctf_field *field, bool print_names);
+               struct bt_ctf_field *field, bool print_names,
+               GQuark *filters_fields, int filter_array_len);
 
 static
 void print_name_equal(struct text_component *text, const char *name)
@@ -77,7 +78,7 @@ void print_name_equal(struct text_component *text, const char *name)
        if (text->use_colors) {
                fprintf(text->out, "%s%s%s = ", COLOR_NAME, name, COLOR_RST);
        } else {
-               fputs(name, text->out);
+               fprintf(text->out, "%s = ", name);
        }
 }
 
@@ -88,7 +89,7 @@ void print_field_name_equal(struct text_component *text, const char *name)
                fprintf(text->out, "%s%s%s = ", COLOR_FIELD_NAME, name,
                        COLOR_RST);
        } else {
-               fputs(name, text->out);
+               fprintf(text->out, "%s = ", name);
        }
 }
 
@@ -333,6 +334,7 @@ enum bt_component_status print_event_header(struct text_component *text,
        struct bt_ctf_event_class *event_class = NULL;
        struct bt_ctf_stream_class *stream_class = NULL;
        struct bt_ctf_trace *trace_class = NULL;
+       int dom_print = 0;
 
        event_class = bt_ctf_event_get_class(event);
        if (!event_class) {
@@ -349,10 +351,6 @@ enum bt_component_status print_event_header(struct text_component *text,
                ret = BT_COMPONENT_STATUS_ERROR;
                goto end;
        }
-       if (!text->start_line) {
-               fputs(", ", text->out);
-       }
-       text->start_line = false;
        ret = print_event_timestamp(text, event, &text->start_line);
        if (ret != BT_COMPONENT_STATUS_OK) {
                goto end;
@@ -365,11 +363,13 @@ enum bt_component_status print_event_header(struct text_component *text,
                        if (!text->start_line) {
                                fputs(", ", text->out);
                        }
-                       text->start_line = false;
                        if (print_names) {
                                print_name_equal(text, "trace");
                        }
                        fprintf(text->out, "%s", name);
+                       if (!print_names) {
+                               fprintf(text->out, " ");
+                       }
                }
        }
        if (text->options.print_trace_hostname_field) {
@@ -383,7 +383,6 @@ enum bt_component_status print_event_header(struct text_component *text,
                        if (!text->start_line) {
                                fputs(", ", text->out);
                        }
-                       text->start_line = false;
                        if (print_names) {
                                print_name_equal(text, "trace:hostname");
                        }
@@ -392,6 +391,7 @@ enum bt_component_status print_event_header(struct text_component *text,
                                fprintf(text->out, "%s", str);
                        }
                        bt_put(hostname_str);
+                       dom_print = 1;
                }
        }
        if (text->options.print_trace_domain_field) {
@@ -405,15 +405,17 @@ enum bt_component_status print_event_header(struct text_component *text,
                        if (!text->start_line) {
                                fputs(", ", text->out);
                        }
-                       text->start_line = false;
                        if (print_names) {
                                print_name_equal(text, "trace:domain");
+                       } else if (dom_print) {
+                               fputs(":", text->out);
                        }
                        if (bt_value_string_get(domain_str, &str)
                                        == BT_VALUE_STATUS_OK) {
                                fprintf(text->out, "%s", str);
                        }
                        bt_put(domain_str);
+                       dom_print = 1;
                }
        }
        if (text->options.print_trace_procname_field) {
@@ -427,15 +429,17 @@ enum bt_component_status print_event_header(struct text_component *text,
                        if (!text->start_line) {
                                fputs(", ", text->out);
                        }
-                       text->start_line = false;
                        if (print_names) {
                                print_name_equal(text, "trace:procname");
+                       } else if (dom_print) {
+                               fputs(":", text->out);
                        }
                        if (bt_value_string_get(procname_str, &str)
                                        == BT_VALUE_STATUS_OK) {
                                fprintf(text->out, "%s", str);
                        }
                        bt_put(procname_str);
+                       dom_print = 1;
                }
        }
        if (text->options.print_trace_vpid_field) {
@@ -449,15 +453,17 @@ enum bt_component_status print_event_header(struct text_component *text,
                        if (!text->start_line) {
                                fputs(", ", text->out);
                        }
-                       text->start_line = false;
                        if (print_names) {
                                print_name_equal(text, "trace:vpid");
+                       } else if (dom_print) {
+                               fputs(":", text->out);
                        }
                        if (bt_value_integer_get(vpid_value, &value)
                                        == BT_VALUE_STATUS_OK) {
                                fprintf(text->out, "(%" PRId64 ")", value);
                        }
                        bt_put(vpid_value);
+                       dom_print = 1;
                }
        }
        if (text->options.print_loglevel_field) {
@@ -473,9 +479,10 @@ enum bt_component_status print_event_header(struct text_component *text,
                        if (!text->start_line) {
                                fputs(", ", text->out);
                        }
-                       text->start_line = false;
                        if (print_names) {
                                print_name_equal(text, "loglevel");
+                       } else if (dom_print) {
+                               fputs(":", text->out);
                        }
                        if (loglevel_str) {
                                const char *str;
@@ -497,6 +504,7 @@ enum bt_component_status print_event_header(struct text_component *text,
                        }
                        bt_put(loglevel_str);
                        bt_put(loglevel_value);
+                       dom_print = 1;
                }
        }
        if (text->options.print_emf_field) {
@@ -508,9 +516,10 @@ enum bt_component_status print_event_header(struct text_component *text,
                        if (!text->start_line) {
                                fputs(", ", text->out);
                        }
-                       text->start_line = false;
                        if (print_names) {
                                print_name_equal(text, "model.emf.uri");
+                       } else if (dom_print) {
+                               fputs(":", text->out);
                        }
                        if (uri_str) {
                                const char *str;
@@ -521,12 +530,16 @@ enum bt_component_status print_event_header(struct text_component *text,
                                }
                        }
                        bt_put(uri_str);
+                       dom_print = 1;
                }
        }
+       if (dom_print && !print_names) {
+               fputs(" ", text->out);
+       }
        if (!text->start_line) {
                fputs(", ", text->out);
        }
-       text->start_line = false;
+       text->start_line = true;
        if (print_names) {
                print_name_equal(text, "name");
        }
@@ -537,6 +550,11 @@ enum bt_component_status print_event_header(struct text_component *text,
        if (text->use_colors) {
                fputs(COLOR_RST, text->out);
        }
+       if (!print_names) {
+               fputs(": ", text->out);
+       } else {
+               fputs(", ", text->out);
+       }
 end:
        bt_put(trace_class);
        bt_put(stream_class);
@@ -783,11 +801,31 @@ end:
        return ret;
 }
 
+static
+int filter_field_name(struct text_component *text, const char *field_name,
+               GQuark *filter_fields, int filter_array_len)
+{
+       int i;
+       GQuark field_quark = g_quark_try_string(field_name);
+
+       if (!field_quark || text->options.verbose) {
+               return 1;
+       }
+
+       for (i = 0; i < filter_array_len; i++) {
+               if (field_quark == filter_fields[i]) {
+                       return 0;
+               }
+       }
+       return 1;
+}
+
 static
 enum bt_component_status print_struct_field(struct text_component *text,
                struct bt_ctf_field *_struct,
                struct bt_ctf_field_type *struct_type,
-               int i, bool print_names)
+               int i, bool print_names, int *nr_printed_fields,
+               GQuark *filter_fields, int filter_array_len)
 {
        enum bt_component_status ret = BT_COMPONENT_STATUS_OK;
        const char *field_name;
@@ -805,7 +843,13 @@ enum bt_component_status print_struct_field(struct text_component *text,
                goto end;
        }
 
-       if (i != 0) {
+       if (filter_fields && !filter_field_name(text, field_name,
+                               filter_fields, filter_array_len)) {
+               ret = BT_COMPONENT_STATUS_OK;
+               goto end;
+       }
+
+       if (*nr_printed_fields > 0) {
                fprintf(text->out, ", ");
        } else {
                fprintf(text->out, " ");
@@ -813,7 +857,8 @@ enum bt_component_status print_struct_field(struct text_component *text,
        if (print_names) {
                print_field_name_equal(text, rem_(field_name));
        }
-       ret = print_field(text, field, print_names);
+       ret = print_field(text, field, print_names, NULL, 0);
+       *nr_printed_fields += 1;
 end:
        bt_put(field_type);
        bt_put(field);
@@ -822,11 +867,12 @@ end:
 
 static
 enum bt_component_status print_struct(struct text_component *text,
-               struct bt_ctf_field *_struct, bool print_names)
+               struct bt_ctf_field *_struct, bool print_names,
+               GQuark *filter_fields, int filter_array_len)
 {
        enum bt_component_status ret = BT_COMPONENT_STATUS_OK;
        struct bt_ctf_field_type *struct_type = NULL;
-       int nr_fields, i;
+       int nr_fields, i, nr_printed_fields;
 
        struct_type = bt_ctf_field_get_type(_struct);
        if (!struct_type) {
@@ -840,9 +886,11 @@ enum bt_component_status print_struct(struct text_component *text,
        }
        fprintf(text->out, "{");
        text->depth++;
+       nr_printed_fields = 0;
        for (i = 0; i < nr_fields; i++) {
                ret = print_struct_field(text, _struct, struct_type, i,
-                               print_names);
+                               print_names, &nr_printed_fields, filter_fields,
+                               filter_array_len);
                if (ret != BT_COMPONENT_STATUS_OK) {
                        goto end;
                }
@@ -868,13 +916,16 @@ enum bt_component_status print_array_field(struct text_component *text,
                } else {
                        fprintf(text->out, " ");
                }
+               if (print_names) {
+                       fprintf(text->out, "[%" PRIu64 "] = ", i);
+               }
        }
        field = bt_ctf_field_array_get_field(array, i);
        if (!field) {
                ret = BT_COMPONENT_STATUS_ERROR;
                goto end;
        }
-       ret = print_field(text, field, print_names);
+       ret = print_field(text, field, print_names, NULL, 0);
 end:
        bt_put(field);
        return ret;
@@ -977,13 +1028,16 @@ enum bt_component_status print_sequence_field(struct text_component *text,
                } else {
                        fprintf(text->out, " ");
                }
+               if (print_names) {
+                       fprintf(text->out, "[%" PRIu64 "] = ", i);
+               }
        }
        field = bt_ctf_field_sequence_get_field(seq, i);
        if (!field) {
                ret = BT_COMPONENT_STATUS_ERROR;
                goto end;
        }
-       ret = print_field(text, field, print_names);
+       ret = print_field(text, field, print_names, NULL, 0);
 end:
        bt_put(field);
        return ret;
@@ -1127,7 +1181,7 @@ enum bt_component_status print_variant(struct text_component *text,
                bt_put(tag_field);
                bt_put(iter);
        }
-       ret = print_field(text, field, print_names);
+       ret = print_field(text, field, print_names, NULL, 0);
        if (ret != BT_COMPONENT_STATUS_OK) {
                goto end;
        }
@@ -1140,7 +1194,8 @@ end:
 
 static
 enum bt_component_status print_field(struct text_component *text,
-               struct bt_ctf_field *field, bool print_names)
+               struct bt_ctf_field *field, bool print_names,
+               GQuark *filter_fields, int filter_array_len)
 {
        enum bt_ctf_type_id type_id;
 
@@ -1178,7 +1233,8 @@ enum bt_component_status print_field(struct text_component *text,
                }
                return BT_COMPONENT_STATUS_OK;
        case CTF_TYPE_STRUCT:
-               return print_struct(text, field, print_names);
+               return print_struct(text, field, print_names, filter_fields,
+                               filter_array_len);
        case CTF_TYPE_UNTAGGED_VARIANT:
        case CTF_TYPE_VARIANT:
                return print_variant(text, field, print_names);
@@ -1217,7 +1273,9 @@ enum bt_component_status print_stream_packet_context(struct text_component *text
                print_name_equal(text, "stream.packet.context");
        }
        ret = print_field(text, main_field,
-                       text->options.print_context_field_names);
+                       text->options.print_context_field_names,
+                       stream_packet_context_quarks,
+                       STREAM_PACKET_CONTEXT_QUARKS_LEN);
 end:
        bt_put(main_field);
        bt_put(packet);
@@ -1243,7 +1301,7 @@ enum bt_component_status print_event_header_raw(struct text_component *text,
                print_name_equal(text, "stream.event.header");
        }
        ret = print_field(text, main_field,
-                       text->options.print_header_field_names);
+                       text->options.print_header_field_names, NULL, 0);
 end:
        bt_put(main_field);
        return ret;
@@ -1268,7 +1326,7 @@ enum bt_component_status print_stream_event_context(struct text_component *text,
                print_name_equal(text, "stream.event.context");
        }
        ret = print_field(text, main_field,
-                       text->options.print_context_field_names);
+                       text->options.print_context_field_names, NULL, 0);
 end:
        bt_put(main_field);
        return ret;
@@ -1293,7 +1351,7 @@ enum bt_component_status print_event_context(struct text_component *text,
                print_name_equal(text, "event.context");
        }
        ret = print_field(text, main_field,
-                       text->options.print_context_field_names);
+                       text->options.print_context_field_names, NULL, 0);
 end:
        bt_put(main_field);
        return ret;
@@ -1318,7 +1376,7 @@ enum bt_component_status print_event_payload(struct text_component *text,
                print_name_equal(text, "event.fields");
        }
        ret = print_field(text, main_field,
-                       text->options.print_payload_field_names);
+                       text->options.print_payload_field_names, NULL, 0);
 end:
        bt_put(main_field);
        return ret;
@@ -1341,9 +1399,11 @@ enum bt_component_status text_print_event(struct text_component *text,
                goto end;
        }
 
-       ret = print_event_header_raw(text, event);
-       if (ret != BT_COMPONENT_STATUS_OK) {
-               goto end;
+       if (text->options.verbose) {
+               ret = print_event_header_raw(text, event);
+               if (ret != BT_COMPONENT_STATUS_OK) {
+                       goto end;
+               }
        }
 
        ret = print_stream_event_context(text, event);
This page took 0.02981 seconds and 4 git commands to generate.