Skip to contentSkip to conversation

libtraceevent: Optimize the print of tep fields

PATCH New Yordan Karadzhov (VMware) 1 participant 3 messages Sep 9, 2021 Documentation

lore
Share & tools
lore
#0 lore raw

v8 cover libtraceevent: Optimize the print of tep fields

Provide new capabilities for printing the content of the individual fields of the event.

Changes in v8:
- In tep_record_print_selected_fields(), changing the argument 'ignore_mask' to 'select_maks'.
- Fixes in the documentation of the new APIs.

Changes in v7:
- Proper naming (without 'tep' prefix) of the static methods defined in the patches.
- Fixing the 'for' loop in print_selected_fields()
- 'tep_print_selected_fields()' was renamed to 'tep_record_print_selected_fields()'. 'tep_record_print_fields()' was added.
- Adding documentation for the new APIs.

Changes in v6:
- Cleanup in [PATCH 1/5].
- Protection against infinite loop in _tep_print_field() ([PATCH 4/5]).

Changes in v5:
- The loop over the tokens in _tep_print_field() is made circular in order to support the corner case when the fields and the tokens are listed in different order.
- _tep_print_field() and print_selected_fields() are made "inline" in order to help the compiler to optimize out the unused variables (suggested by Steven).

Changes in v4:
- Directly applying the modification in tep_print_field() suggested by Steven.
- Optimizing the loop over the tokens in tep_print_fields().

Yordan Karadzhov (VMware) (2):
libtraceevent: Add APIs for printing the fields of a record
libtraceevent: Add documentation for the new printing APIs

 Documentation/libtraceevent-field_print.txt | 11 ++++-
 Documentation/libtraceevent.txt             |  2 +
 src/event-parse.c                           | 51 +++++++++++++++++++--
 src/event-parse.h                           |  7 +++
 4 files changed, 66 insertions(+), 5 deletions(-)
Signature · 1 line
2.30.2
#1 lore raw

PATCH v8 1/2 libtraceevent: Add APIs for printing the fields of a record

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.

---
 src/event-parse.c | 51 +++++++++++++++++++++++++++++++++++++++++++----
 src/event-parse.h |  7 +++++++
 2 files changed, 54 insertions(+), 4 deletions(-)
src/event-parse.c +47 -4
index 51cb30b..8057fb5 100644
@@ -5455,20 +5455,63 @@ 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_fields - print the field name followed by the
+ * record's field value.
+ * @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
+ * @select_mask: Bit mask defining the fields to print
+ */
+void tep_record_print_selected_fields(struct trace_seq *s,
+				      struct tep_record *record,
+				      struct tep_event *event,
+				      unsigned long long select_mask)
+{
+	unsigned long long ignore_mask = ~select_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)
src/event-parse.h +7 -0
index d4a876f..0833893 100644
@@ -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 select_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,
Signature · 1 line
2.30.2
#2 lore raw

PATCH v8 2/2 libtraceevent: Add documentation for the new printing APIs

In reply to Yordan Karadzhov (VMware)

'tep_record_print_fields()' and 'tep_record_print_selected_fields()' are documented.

---
 Documentation/libtraceevent-field_print.txt | 11 ++++++++++-
 Documentation/libtraceevent.txt             |  2 ++
 2 files changed, 12 insertions(+), 1 deletion(-)
Documentation/libtraceevent-field_print.txt +10 -1
index 2c2cf6c..c201c13 100644
@@ -3,7 +3,7 @@ libtraceevent(3)
 
 NAME
 ----
-tep_print_field, tep_print_fields, tep_print_num_field, tep_print_func_field -
+tep_print_field, tep_print_fields, tep_print_num_field, tep_print_func_field, tep_record_print_fields, tep_record_print_selected_fields -
 Print the field content.
 
 SYNOPSIS
@@ -17,6 +17,8 @@ void *tep_print_field*(struct trace_seq pass:[*]_s_, void pass:[*]_data_, struct
 void *tep_print_fields*(struct trace_seq pass:[*]_s_, void pass:[*]_data_, int _size_, struct tep_event pass:[*]_event_);
 int *tep_print_num_field*(struct trace_seq pass:[*]_s_, const char pass:[*]_fmt_, struct tep_event pass:[*]_event_, const char pass:[*]_name_, struct tep_record pass:[*]_record_, int _err_);
 int *tep_print_func_field*(struct trace_seq pass:[*]_s_, const char pass:[*]_fmt_, struct tep_event pass:[*]_event_, const char pass:[*]_name_, struct tep_record pass:[*]_record_, int _err_);
+void *tep_record_print_fields*(struct trace_seq pass:[*]_s_, struct tep_record pass:[*]_record_, struct tep_event pass:[*]_event_);
+void *tep_record_print_selected_fields*(struct trace_seq pass:[*]_s_, struct tep_record pass:[*]_record_, struct tep_event pass:[*]_event_, int _select_mask_);
 --
 
 DESCRIPTION
@@ -49,6 +51,13 @@ function. The function name (if found) and its address are printed in the _s_,
 according to the given format string _fmt_. If the argument _err_ is non-zero,
 and an error occures - it is printed in _s_.
 
+The _tep_record_print_fields()_ prints the field's name followed by its value
+for all record's field.
+
+The _tep_record_print_selected_fields()_ prints the field's name followed by
+its value for selected subset of record field. The fields to be printed are
+defined by the _select_mask_ bit mask.
+
 RETURN VALUE
 ------------
 The _tep_print_num_field()_ and _tep_print_func_field()_ functions return 1
Documentation/libtraceevent.txt +2 -0
index d42b5c9..01014b7 100644
@@ -80,6 +80,8 @@ Event fields printing:
 	void *tep_print_fields*(struct trace_seq pass:[*]_s_, void pass:[*]_data_, int _size_, struct tep_event pass:[*]_event_);
 	int *tep_print_num_field*(struct trace_seq pass:[*]_s_, const char pass:[*]_fmt_, struct tep_event pass:[*]_event_, const char pass:[*]_name_, struct tep_record pass:[*]_record_, int _err_);
 	int *tep_print_func_field*(struct trace_seq pass:[*]_s_, const char pass:[*]_fmt_, struct tep_event pass:[*]_event_, const char pass:[*]_name_, struct tep_record pass:[*]_record_, int _err_);
+	void *tep_record_print_fields*(struct trace_seq pass:[*]_s_, struct tep_record pass:[*]_record_, struct tep_event pass:[*]_event_);
+	void *tep_record_print_selected_fields*(struct trace_seq pass:[*]_s_, struct tep_record pass:[*]_record_, struct tep_event pass:[*]_event_, int _select_mask_);
 
 Event fields finding:
 	struct tep_format_field pass:[*]*tep_find_common_field*(struct tep_event pass:[*]_event_, const char pass:[*]_name_);
Signature · 1 line
2.30.2