From: Julien Desfossez Date: Mon, 23 Jan 2017 20:39:39 +0000 (-0500) Subject: text: mask some internal fields X-Git-Tag: v2.0.0-pre1~475 X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=2b4c4a7ca098cb220ebbec83e05b7d1fa238c812 text: mask some internal fields Some fields from the stream packet context are not really useful to the end user of the text output, so we mask them by default. They can be displayed using the -v/--verbose flag. The masked fields are the same as in previous version: - timestamp_begin - timestamp_end - events_discarded - content_size - packet_size - packet_seq_num Signed-off-by: Julien Desfossez Signed-off-by: Jérémie Galarneau --- diff --git a/plugins/text/print.c b/plugins/text/print.c index 958b94d8..66df3318 100644 --- a/plugins/text/print.c +++ b/plugins/text/print.c @@ -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) @@ -783,11 +784,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 +826,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 +840,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 +850,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 +869,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; } @@ -874,7 +905,7 @@ enum bt_component_status print_array_field(struct text_component *text, 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; @@ -983,7 +1014,7 @@ enum bt_component_status print_sequence_field(struct text_component *text, 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 +1158,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 +1171,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 +1210,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 +1250,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 +1278,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 +1303,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 +1328,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 +1353,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; diff --git a/plugins/text/text.c b/plugins/text/text.c index 44887b6f..e6631763 100644 --- a/plugins/text/text.c +++ b/plugins/text/text.c @@ -665,6 +665,25 @@ void set_use_colors(struct text_component *text) } } +static +void init_stream_packet_context_quarks(void) +{ + stream_packet_context_quarks[Q_TIMESTAMP_BEGIN] = + g_quark_from_string("timestamp_begin"); + stream_packet_context_quarks[Q_TIMESTAMP_BEGIN] = + g_quark_from_string("timestamp_begin"); + stream_packet_context_quarks[Q_TIMESTAMP_END] = + g_quark_from_string("timestamp_end"); + stream_packet_context_quarks[Q_EVENTS_DISCARDED] = + g_quark_from_string("events_discarded"); + stream_packet_context_quarks[Q_CONTENT_SIZE] = + g_quark_from_string("content_size"); + stream_packet_context_quarks[Q_PACKET_SIZE] = + g_quark_from_string("packet_size"); + stream_packet_context_quarks[Q_PACKET_SEQ_NUM] = + g_quark_from_string("packet_seq_num"); +} + static enum bt_component_status text_component_init( struct bt_component *component, struct bt_value *params, @@ -698,6 +717,9 @@ enum bt_component_status text_component_init( if (ret != BT_COMPONENT_STATUS_OK) { goto error; } + + init_stream_packet_context_quarks(); + end: return ret; error: @@ -715,4 +737,3 @@ BT_PLUGIN_SINK_COMPONENT_CLASS_INIT_METHOD(text, text_component_init); BT_PLUGIN_SINK_COMPONENT_CLASS_DESTROY_METHOD(text, destroy_text); BT_PLUGIN_SINK_COMPONENT_CLASS_DESCRIPTION(text, "Formats CTF-IR to text. Formerly known as ctf-text."); - diff --git a/plugins/text/text.h b/plugins/text/text.h index ed4ad3e8..d6143283 100644 --- a/plugins/text/text.h +++ b/plugins/text/text.h @@ -91,6 +91,18 @@ struct text_component { uint64_t delta_real_timestamp; }; +enum stream_packet_context_quarks_enum { + Q_TIMESTAMP_BEGIN, + Q_TIMESTAMP_END, + Q_EVENTS_DISCARDED, + Q_CONTENT_SIZE, + Q_PACKET_SIZE, + Q_PACKET_SEQ_NUM, + STREAM_PACKET_CONTEXT_QUARKS_LEN, /* Always the last one of this enum. */ +}; + +GQuark stream_packet_context_quarks[STREAM_PACKET_CONTEXT_QUARKS_LEN]; + BT_HIDDEN enum bt_component_status text_print_event(struct text_component *text, struct bt_ctf_event *event);