linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] trace-cmd: Use the real trace buffer page size
@ 2021-10-01  6:27 Tzvetomir Stoyanov (VMware)
  0 siblings, 0 replies; only message in thread
From: Tzvetomir Stoyanov (VMware) @ 2021-10-01  6:27 UTC (permalink / raw)
  To: rostedt; +Cc: linux-trace-devel

When new output handler is created, it assumes that the trace buffer page
size is equal to the system memory page size. This assumption is valid
for the current ftrace implementation, but it may change in the future.
The newly introduced traceevent library API should be used to get the
real trace buffer page size, bases on the information from the
"events/header_page" ftrace file.

This commit depends on:
 [PATCH] libtraceevent: A new API for trace page size
 https://lore.kernel.org/linux-trace-devel/20211001062338.2389024-1-tz.stoyanov@gmail.com/

Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
---
 lib/trace-cmd/trace-output.c | 52 +++++++++++++++++++++++++++++++++++-
 1 file changed, 51 insertions(+), 1 deletion(-)

diff --git a/lib/trace-cmd/trace-output.c b/lib/trace-cmd/trace-output.c
index a8de107c..f4177f54 100644
--- a/lib/trace-cmd/trace-output.c
+++ b/lib/trace-cmd/trace-output.c
@@ -921,6 +921,56 @@ static int select_file_version(struct tracecmd_output *handle,
 	return 0;
 }
 
+static int get_trace_page_size(struct tracecmd_output *handle)
+{
+	struct tep_handle *tep = NULL;
+	tsize_t psize, size;
+	char *path = NULL;
+	char *buff = NULL;
+	int fd = -1;
+	int r, s;
+
+	/* In case of an error, return user space page size */
+	psize = getpagesize();
+
+	path = get_tracing_file(handle, "events/header_page");
+	if (!path)
+		goto out;
+	fd = open(path, O_RDONLY);
+	if (fd < 0) /* old style did not show this info */
+		goto out;
+
+	tep = tep_alloc();
+	if (!tep)
+		goto out;
+	size = get_size_fd(fd);
+	if (!size)
+		goto out;
+	buff = malloc(size);
+	if (!buff)
+		goto out;
+
+	s = size;
+	do {
+		r = read(fd, buff, s);
+		if (r > 0)
+			s -= r;
+	} while (r > 0 && s);
+	if (s)
+		goto out;
+	if (tep_parse_header_page(tep, buff, size, sizeof(long long)))
+		goto out;
+	psize = tep_get_trace_page_size(tep);
+out:
+	tep_free(tep);
+	free(buff);
+	if (path)
+		put_tracing_file(path);
+	if (fd >= 0)
+		close(fd);
+	return psize;
+}
+
 static struct tracecmd_output *
 create_file_fd(int fd, struct tracecmd_input *ihandle,
 	       const char *tracing_dir,
@@ -980,7 +1030,7 @@ create_file_fd(int fd, struct tracecmd_input *ihandle,
 			buf[0] = 1;
 		else
 			buf[0] = 0;
-		handle->page_size = getpagesize();
+		handle->page_size = get_trace_page_size(handle);
 	}
 
 	if (do_write_check(handle, buf, 1))
-- 
2.31.1


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

only message in thread, other threads:[~2021-10-01  6:27 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-01  6:27 [PATCH] trace-cmd: Use the real trace buffer page size Tzvetomir Stoyanov (VMware)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).