All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v8 0/2] libtraceevent: Optimize the print of tep fields
@ 2021-09-09  8:06 Yordan Karadzhov (VMware)
  2021-09-09  8:06 ` [PATCH v8 1/2] libtraceevent: Add APIs for printing the fields of a record Yordan Karadzhov (VMware)
  2021-09-09  8:06 ` [PATCH v8 2/2] libtraceevent: Add documentation for the new printing APIs Yordan Karadzhov (VMware)
  0 siblings, 2 replies; 3+ messages in thread
From: Yordan Karadzhov (VMware) @ 2021-09-09  8:06 UTC (permalink / raw)
  To: rostedt; +Cc: linux-trace-devel, Yordan Karadzhov (VMware)

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(-)

-- 
2.30.2


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH v8 1/2] libtraceevent: Add APIs for printing the fields of a record
  2021-09-09  8:06 [PATCH v8 0/2] libtraceevent: Optimize the print of tep fields Yordan Karadzhov (VMware)
@ 2021-09-09  8:06 ` Yordan Karadzhov (VMware)
  2021-09-09  8:06 ` [PATCH v8 2/2] libtraceevent: Add documentation for the new printing APIs Yordan Karadzhov (VMware)
  1 sibling, 0 replies; 3+ messages in thread
From: Yordan Karadzhov (VMware) @ 2021-09-09  8:06 UTC (permalink / raw)
  To: rostedt; +Cc: linux-trace-devel, Yordan Karadzhov (VMware)

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 | 51 +++++++++++++++++++++++++++++++++++++++++++----
 src/event-parse.h |  7 +++++++
 2 files changed, 54 insertions(+), 4 deletions(-)

diff --git a/src/event-parse.c b/src/event-parse.c
index 51cb30b..8057fb5 100644
--- a/src/event-parse.c
+++ b/src/event-parse.c
@@ -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)
diff --git a/src/event-parse.h b/src/event-parse.h
index d4a876f..0833893 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 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,
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH v8 2/2] libtraceevent: Add documentation for the new printing APIs
  2021-09-09  8:06 [PATCH v8 0/2] libtraceevent: Optimize the print of tep fields Yordan Karadzhov (VMware)
  2021-09-09  8:06 ` [PATCH v8 1/2] libtraceevent: Add APIs for printing the fields of a record Yordan Karadzhov (VMware)
@ 2021-09-09  8:06 ` Yordan Karadzhov (VMware)
  1 sibling, 0 replies; 3+ messages in thread
From: Yordan Karadzhov (VMware) @ 2021-09-09  8:06 UTC (permalink / raw)
  To: rostedt; +Cc: linux-trace-devel, Yordan Karadzhov (VMware)

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

Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
---
 Documentation/libtraceevent-field_print.txt | 11 ++++++++++-
 Documentation/libtraceevent.txt             |  2 ++
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/Documentation/libtraceevent-field_print.txt b/Documentation/libtraceevent-field_print.txt
index 2c2cf6c..c201c13 100644
--- a/Documentation/libtraceevent-field_print.txt
+++ b/Documentation/libtraceevent-field_print.txt
@@ -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
diff --git a/Documentation/libtraceevent.txt b/Documentation/libtraceevent.txt
index d42b5c9..01014b7 100644
--- a/Documentation/libtraceevent.txt
+++ b/Documentation/libtraceevent.txt
@@ -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_);
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-09-09  8:06 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-09  8:06 [PATCH v8 0/2] libtraceevent: Optimize the print of tep fields Yordan Karadzhov (VMware)
2021-09-09  8:06 ` [PATCH v8 1/2] libtraceevent: Add APIs for printing the fields of a record Yordan Karadzhov (VMware)
2021-09-09  8:06 ` [PATCH v8 2/2] libtraceevent: Add documentation for the new printing APIs Yordan Karadzhov (VMware)

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.