@@ -1189,6 +1189,41 @@ static int write_compression_header(struct tracecmd_output *handle)
return 0;
}
+static int get_trace_page_size(struct tracecmd_output *handle)
+{
+ struct tracefs_instance *instance;
+ struct tep_handle *tep = NULL;
+ int psize, size;
+ char *buff = NULL;
+
+ /* In case of an error, return user space page size */
+ psize = getpagesize();
+
+ instance = tracefs_instance_alloc(find_tracing_dir(handle), NULL);
+ if (!instance)
+ goto out;
+
+ buff = tracefs_instance_file_read(instance, "events/header_page", &size);
+ if (!buff)
+ goto out;
+
+ tep = tep_alloc();
+ if (!tep)
+ goto out;
+
+ if (tep_parse_header_page(tep, buff, size, sizeof(long long)))
+ goto out;
+
+ psize = tep_get_sub_buffer_size(tep);
+
+out:
+ tracefs_instance_free(instance);
+ tep_free(tep);
+ free(buff);
+
+ return psize;
+}
+
/**
* tracecmd_output_allocate - allocate new output handler to a trace file
* @handle: file descriptor to an empty file, it can be -1 if the handler
@@ -1213,7 +1248,7 @@ struct tracecmd_output *tracecmd_output_allocate(int fd)
handle->file_version = FILE_VERSION_DEFAULT;
- handle->page_size = getpagesize();
+ handle->page_size = get_trace_page_size(handle);
handle->big_endian = tracecmd_host_bigendian();
list_head_init(&handle->options);
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 | 37 +++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-)