All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3] libtraceevent: A new API for trace page size
@ 2021-11-26  3:46 Tzvetomir Stoyanov (VMware)
  0 siblings, 0 replies; only message in thread
From: Tzvetomir Stoyanov (VMware) @ 2021-11-26  3:46 UTC (permalink / raw)
  To: rostedt; +Cc: linux-trace-devel

Currently, the size of a trace buffer page is equal to the size of the
system memory page. This may change in the future, so this assumption
may not be valid. The proper way to determine the trace buffer page size
is by using the information from "events/header_page" ftrace file:
 ...
 field: char data;	offset:16;	size:4080;	signed:1;
 ...
The trace buffer page size is the size of the "data" filed + its offset.

A new libtraceevent API is introduced, for getting the trace buffer page
size using that formula:
 tep_get_sub_buffer_size()

Note, that some old kernels may not have "events/header_page" file. For
those, the system memory page size is returned.

Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
---

v3 changes:
 - Removed unneeded unistd.h include.
v2 changes:
 - Renamed tep_get_trace_page_size() to tep_get_sub_buffer_size().
 - Handle the old kernels in tep_parse_header_page() instead of in
   tep_get_sub_buffer_size().

 src/event-parse-api.c | 15 +++++++++++++++
 src/event-parse.c     |  2 ++
 src/event-parse.h     |  1 +
 3 files changed, 18 insertions(+)

diff --git a/src/event-parse-api.c b/src/event-parse-api.c
index f8361e4..a765a68 100644
--- a/src/event-parse-api.c
+++ b/src/event-parse-api.c
@@ -248,6 +248,21 @@ void tep_set_page_size(struct tep_handle *tep, int _page_size)
 		tep->page_size = _page_size;
 }
 
+/**
+ * tep_get_sub_buffer_size - get the size of a trace buffer page
+ * @tep: a handle to the tep_handle
+ *
+ * This returns the size of a trace buffer page on the traced machine.
+ * If @tep is NULL then -1 is returned.
+ */
+int tep_get_sub_buffer_size(struct tep_handle *tep)
+{
+	if (!tep)
+		return -1;
+
+	return tep->header_page_data_size + tep->header_page_data_offset;
+}
+
 /**
  * tep_is_file_bigendian - return the endian of the file
  * @tep: a handle to the tep_handle
diff --git a/src/event-parse.c b/src/event-parse.c
index e3bf87b..34d6c96 100644
--- a/src/event-parse.c
+++ b/src/event-parse.c
@@ -17,6 +17,7 @@
 #include <ctype.h>
 #include <errno.h>
 #include <stdint.h>
+#include <unistd.h>
 #include <limits.h>
 #include <linux/time64.h>
 
@@ -7029,6 +7030,7 @@ int tep_parse_header_page(struct tep_handle *tep, char *buf, unsigned long size,
 		tep->header_page_ts_size = sizeof(long long);
 		tep->header_page_size_size = long_size;
 		tep->header_page_data_offset = sizeof(long long) + long_size;
+		tep->header_page_data_size = getpagesize() - tep->header_page_data_offset;
 		tep->old_format = 1;
 		return -1;
 	}
diff --git a/src/event-parse.h b/src/event-parse.h
index db8bc6d..9723406 100644
--- a/src/event-parse.h
+++ b/src/event-parse.h
@@ -573,6 +573,7 @@ void tep_set_cpus(struct tep_handle *tep, int cpus);
 int tep_get_long_size(struct tep_handle *tep);
 void tep_set_long_size(struct tep_handle *tep, int long_size);
 int tep_get_page_size(struct tep_handle *tep);
+int tep_get_sub_buffer_size(struct tep_handle *tep);
 void tep_set_page_size(struct tep_handle *tep, int _page_size);
 bool tep_is_file_bigendian(struct tep_handle *tep);
 void tep_set_file_bigendian(struct tep_handle *tep, enum tep_endian endian);
-- 
2.33.1


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2021-11-26  4:22 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-26  3:46 [PATCH v3] libtraceevent: A new API for trace page size Tzvetomir Stoyanov (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.