Skip to content

Commit

Permalink
text: mask some internal fields
Browse files Browse the repository at this point in the history
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 <jdesfossez@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
  • Loading branch information
Julien Desfossez authored and jgalar committed Feb 13, 2017
1 parent eee4d36 commit 35b873e
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 18 deletions.
69 changes: 52 additions & 17 deletions plugins/text/print.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -783,11 +784,31 @@ enum bt_component_status print_enum(struct text_component *text,
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;
Expand All @@ -805,15 +826,22 @@ 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, " ");
}
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);
Expand All @@ -822,11 +850,12 @@ enum bt_component_status print_struct_field(struct text_component *text,

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) {
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand All @@ -1140,7 +1171,8 @@ enum bt_component_status print_variant(struct text_component *text,

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;

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down
23 changes: 22 additions & 1 deletion plugins/text/text.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand All @@ -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.");

12 changes: 12 additions & 0 deletions plugins/text/text.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 35b873e

Please sign in to comment.