diff mbox series

[v7,3/4] libtraceevent: Add APIs for printing the fields of a record

Message ID 20210823095618.138887-4-y.karadz@gmail.com (mailing list archive)
State Superseded
Headers show
Series libtraceevent: Optimize the print of tep fields | expand

Commit Message

Yordan Karadzhov Aug. 23, 2021, 9:56 a.m. UTC
The new methods can print all unique data fielsd, or only a subset of
the fields of the trace event. The print format is derived from the
parsing tokens (tep_print_parse objects) of the event.

Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
---
 src/event-parse.c | 49 +++++++++++++++++++++++++++++++++++++++++++----
 src/event-parse.h |  7 +++++++
 2 files changed, 52 insertions(+), 4 deletions(-)

Comments

Steven Rostedt Sept. 8, 2021, 8:04 p.m. UTC | #1
On Mon, 23 Aug 2021 12:56:17 +0300
"Yordan Karadzhov (VMware)" <y.karadz@gmail.com> wrote:

> The new methods can print all unique data fielsd, or only a subset of
> the fields of the trace event. The print format is derived from the
> parsing tokens (tep_print_parse objects) of the event.

The more I look at this, the more I think we should have a
"selected_fields" mask, and not a ignored mask. At least for the API.
The internal functions can stay the same. That is, the internal
functions have the ignored_mask.

> 
> Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
> ---


> +/**
> + * tep_record_print_selected_fields - print the field name followed by the

I think the above should be "tep_record_print_fields" ?

> + * record's field value for a selected subset of record fields.
> + * @s: The seq to print to
> + * @record: The record to get the event from
> + * @event: The event that the field is for
> + */
> +void tep_record_print_fields(struct trace_seq *s,
> +			     struct tep_record *record,
> +			     struct tep_event *event)
> +{
> +	print_selected_fields(s, record->data, event, 0);
> +}
> +
> +/**
> + * tep_record_print_selected_fields - print the field name followed by the
> + * record's field value for a selected subset of record fields.
> + * @s: The seq to print to
> + * @record: The record to get the event from
> + * @event: The event that the field is for
> + * @ignore_mask: Bit mask defining the fields to be ignored

change to:

      @select_mask: Bit mask defining the fields to record

> + */
> +void tep_record_print_selected_fields(struct trace_seq *s,
> +				      struct tep_record *record,
> +				      struct tep_event *event,
> +				      unsigned long long ignore_mask)

				      unsigned long long select_mask)

> +{

Since print_selected_fields() will still have the ignore_mask, you can
have:

	unsigned long long ignore_mask = ~select_mask;


> +	print_selected_fields(s, record->data, event, ignore_mask);

The above would remain the same.

-- Steve

> +}
> +
>  static int print_function(struct trace_seq *s, const char *format,
>  			  void *data, int size, struct tep_event
> *event, struct tep_print_arg *arg)
> diff --git a/src/event-parse.h b/src/event-parse.h
> index d4a876f..08dcbd8 100644
> --- a/src/event-parse.h
> +++ b/src/event-parse.h
> @@ -545,6 +545,13 @@ int tep_cmdline_pid(struct tep_handle *tep,
> struct tep_cmdline *cmdline); 
>  void tep_print_field(struct trace_seq *s, void *data,
>  		     struct tep_format_field *field);
> +void tep_record_print_fields(struct trace_seq *s,
> +			     struct tep_record *record,
> +			     struct tep_event *event);
> +void tep_record_print_selected_fields(struct trace_seq *s,
> +				      struct tep_record *record,
> +				      struct tep_event *event,
> +				      unsigned long long
> ignore_mask); void tep_print_fields(struct trace_seq *s, void *data,
>  		      int size __maybe_unused, struct tep_event
> *event); int tep_strerror(struct tep_handle *tep, enum tep_errno
> errnum,
diff mbox series

Patch

diff --git a/src/event-parse.c b/src/event-parse.c
index 51cb30b..71a3ccd 100644
--- a/src/event-parse.c
+++ b/src/event-parse.c
@@ -5455,20 +5455,61 @@  void tep_print_field(struct trace_seq *s, void *data,
 	print_field(s, data, field, NULL);
 }
 
-void tep_print_fields(struct trace_seq *s, void *data,
-		      int size __maybe_unused, struct tep_event *event)
+static inline void
+print_selected_fields(struct trace_seq *s, void *data,
+		      struct tep_event *event,
+		      unsigned long long ignore_mask)
 {
 	struct tep_print_parse *parse = event->print_fmt.print_cache;
 	struct tep_format_field *field;
+	unsigned long long field_mask = 1;
 
 	field = event->format.fields;
-	while (field) {
+	for(; field; field = field->next, field_mask <<= 1) {
+		if (field_mask & ignore_mask)
+			continue;
+
 		trace_seq_printf(s, " %s=", field->name);
 		print_field(s, data, field, &parse);
-		field = field->next;
 	}
 }
 
+void tep_print_fields(struct trace_seq *s, void *data,
+		      int size __maybe_unused, struct tep_event *event)
+{
+	print_selected_fields(s, data, event, 0);
+}
+
+/**
+ * tep_record_print_selected_fields - print the field name followed by the
+ * record's field value for a selected subset of record fields.
+ * @s: The seq to print to
+ * @record: The record to get the event from
+ * @event: The event that the field is for
+ */
+void tep_record_print_fields(struct trace_seq *s,
+			     struct tep_record *record,
+			     struct tep_event *event)
+{
+	print_selected_fields(s, record->data, event, 0);
+}
+
+/**
+ * tep_record_print_selected_fields - print the field name followed by the
+ * record's field value for a selected subset of record fields.
+ * @s: The seq to print to
+ * @record: The record to get the event from
+ * @event: The event that the field is for
+ * @ignore_mask: Bit mask defining the fields to be ignored
+ */
+void tep_record_print_selected_fields(struct trace_seq *s,
+				      struct tep_record *record,
+				      struct tep_event *event,
+				      unsigned long long ignore_mask)
+{
+	print_selected_fields(s, record->data, event, ignore_mask);
+}
+
 static int print_function(struct trace_seq *s, const char *format,
 			  void *data, int size, struct tep_event *event,
 			  struct tep_print_arg *arg)
diff --git a/src/event-parse.h b/src/event-parse.h
index d4a876f..08dcbd8 100644
--- a/src/event-parse.h
+++ b/src/event-parse.h
@@ -545,6 +545,13 @@  int tep_cmdline_pid(struct tep_handle *tep, struct tep_cmdline *cmdline);
 
 void tep_print_field(struct trace_seq *s, void *data,
 		     struct tep_format_field *field);
+void tep_record_print_fields(struct trace_seq *s,
+			     struct tep_record *record,
+			     struct tep_event *event);
+void tep_record_print_selected_fields(struct trace_seq *s,
+				      struct tep_record *record,
+				      struct tep_event *event,
+				      unsigned long long ignore_mask);
 void tep_print_fields(struct trace_seq *s, void *data,
 		      int size __maybe_unused, struct tep_event *event);
 int tep_strerror(struct tep_handle *tep, enum tep_errno errnum,