Skip to contentSkip to conversation

Split reading the trace.dat options from trace data

PATCH In review Tzvetomir Stoyanov (VMware) 2 participants 5 messages Apr 9, 2020 – Jan 15, 2021

lore
Share & tools
lore
#0 lore raw

cover Split reading the trace.dat options from trace data

Add functionality which allows to implement opening a trace file on stages - reading the trace headers and reading the trace data.

Tzvetomir Stoyanov (VMware) (2):
trace-cmd: Move reading of trace.dat options to
tracecmd_read_headers()
trace-cmd: Add new API tracecmd_open_head()

 include/trace-cmd/trace-cmd.h |   2 +
 lib/trace-cmd/trace-input.c   | 117 +++++++++++++++++++++++++---------
 2 files changed, 90 insertions(+), 29 deletions(-)
Signature · 1 line
2.25.1
#1 lore raw

PATCH 1/2 trace-cmd: Move reading of trace.dat options to tracecmd_read_headers()

The options section from trace.dat file is logically part of trace headers. In some use cases it is useful first to read all headers from the file, analyze the information and do some processing, before reading the tracing data. In the current implementation, reading of options is just before reading the tracing data.
Moved the reading of options and a CPU count from read_cpu_data() to tracecmd_read_headers(). This allows to implement APIs for trace.dat file reading on stages - headers stage and tracing data stage.

---
 include/trace-cmd/trace-cmd.h |  1 +
 lib/trace-cmd/trace-input.c   | 89 +++++++++++++++++++++++------------
 2 files changed, 61 insertions(+), 29 deletions(-)
include/trace-cmd/trace-cmd.h +1 -0
index 595919d5..3f96bbde 100644
@@ -119,6 +119,7 @@ enum {
 	TRACECMD_FL_BUFFER_INSTANCE	= (1 << 1),
 	TRACECMD_FL_LATENCY		= (1 << 2),
 	TRACECMD_FL_IN_USECS		= (1 << 3),
+	TRACECMD_FL_FLYRECORD		= (1 << 4),
 };
 
 struct tracecmd_ftrace {
lib/trace-cmd/trace-input.c +60 -29

158 lines not on this page · raw message

Signature · 1 line
2.25.1
#2 lore raw

PATCH 2/2 trace-cmd: Add new API tracecmd_open_head()

In reply to Tzvetomir Stoyanov (VMware)

Add an API to create a tracecmd_handle from a file, read and parse only the trace headers from the file. This allows to implement opening a trace file on stages - reading the trace headers and reading the trace data.

---
 include/trace-cmd/trace-cmd.h |  1 +
 lib/trace-cmd/trace-input.c   | 28 ++++++++++++++++++++++++++++
 2 files changed, 29 insertions(+)
include/trace-cmd/trace-cmd.h +1 -0
index 3f96bbde..e22aa251 100644
@@ -143,6 +143,7 @@ typedef void (*tracecmd_handle_init_func)(struct tracecmd_input *handle,
 struct tracecmd_input *tracecmd_alloc(const char *file);
 struct tracecmd_input *tracecmd_alloc_fd(int fd);
 struct tracecmd_input *tracecmd_open(const char *file);
+struct tracecmd_input *tracecmd_open_head(const char *file);
 struct tracecmd_input *tracecmd_open_fd(int fd);
 void tracecmd_ref(struct tracecmd_input *handle);
 void tracecmd_close(struct tracecmd_input *handle);
lib/trace-cmd/trace-input.c +28 -0
index ee9bfb52..efc8d4bd 100644
@@ -3175,6 +3175,34 @@ struct tracecmd_input *tracecmd_open(const char *file)
 	return tracecmd_open_fd(fd);
 }
 
+/**
+ * tracecmd_open_head - create a tracecmd_handle from a given file, read
+ *			read and parse only the trace headers from the file
+ * @file: the file name of the file that is of tracecmd data type.
+ */
+struct tracecmd_input *tracecmd_open_head(const char *file)
+{
+	struct tracecmd_input *handle;
+	int fd;
+
+	fd = open(file, O_RDONLY);
+	if (fd < 0)
+		return NULL;
+
+	handle = tracecmd_alloc_fd(fd);
+	if (!handle)
+		return NULL;
+
+	if (tracecmd_read_headers(handle) < 0)
+		goto fail;
+
+	return handle;
+
+fail:
+	tracecmd_close(handle);
+	return NULL;
+}
+
 /**
  * tracecmd_ref - add a reference to the handle
  * @handle: input handle for the trace.dat file
Signature · 1 line
2.25.1
#3 lore raw

Re: [PATCH 2/2] trace-cmd: Add new API tracecmd_open_head()

Quoted 16 lines · On Thu, 9 Apr 2020 16:28:25 +0300 "Tzvetomir Stoyanov (VMware)"…

Add an API to create a tracecmd_handle from a file, read and parse only the trace headers from the file. This allows to implement opening a trace file on stages - reading the trace headers and reading the trace data.

---
 include/trace-cmd/trace-cmd.h |  1 +
 lib/trace-cmd/trace-input.c   | 28 ++++++++++++++++++++++++++++
 2 files changed, 29 insertions(+)
include/trace-cmd/trace-cmd.h +0 -0
index 3f96bbde..e22aa251 100644

include/trace-cmd/trace-cmd.h typedef void (*tracecmd_handle_init_func)(struct tracecmd_input *handle, · line 149

Quoted 7 lines
include/trace-cmd/trace-cmd.h +1 -0
@@ -143,6 +143,7 @@ typedef void (*tracecmd_handle_init_func)(struct tracecmd_input *handle,
 struct tracecmd_input *tracecmd_alloc(const char *file);
 struct tracecmd_input *tracecmd_alloc_fd(int fd);
 struct tracecmd_input *tracecmd_open(const char *file);
+struct tracecmd_input *tracecmd_open_head(const char *file);
 struct tracecmd_input *tracecmd_open_fd(int fd);
 void tracecmd_ref(struct tracecmd_input *handle);
 void tracecmd_close(struct tracecmd_input *handle);

Hi Tzvetomir,

I was thinking, before we release libtracecmd, we should add tracecmd_open() and tracecmd_open_fd() to the library. Just because I find that tracecmd_open_head() is a awkward name to have alone and only makes sense if there's already a tracecmd_open(). It will also help with differentiating the different functions.

I know we were going to only have functions that kernelshark uses, but that may be a little too limiting.

Thanks!

-- Steve

#4 lore raw

Re: [PATCH 2/2] trace-cmd: Add new API tracecmd_open_head()

Quoted 30 lines · Steven Rostedt
Quoted 16 lines · On Thu, 9 Apr 2020 16:28:25 +0300 "Tzvetomir Stoyanov (VMware)"…

Add an API to create a tracecmd_handle from a file, read and parse only the trace headers from the file. This allows to implement opening a trace file on stages - reading the trace headers and reading the trace data.

---
 include/trace-cmd/trace-cmd.h |  1 +
 lib/trace-cmd/trace-input.c   | 28 ++++++++++++++++++++++++++++
 2 files changed, 29 insertions(+)
include/trace-cmd/trace-cmd.h +0 -0
index 3f96bbde..e22aa251 100644

include/trace-cmd/trace-cmd.h typedef void (*tracecmd_handle_init_func)(struct tracecmd_input *handle, · line 149

Quoted 7 lines
include/trace-cmd/trace-cmd.h +1 -0
@@ -143,6 +143,7 @@ typedef void (*tracecmd_handle_init_func)(struct tracecmd_input *handle,
 struct tracecmd_input *tracecmd_alloc(const char *file);
 struct tracecmd_input *tracecmd_alloc_fd(int fd);
 struct tracecmd_input *tracecmd_open(const char *file);
+struct tracecmd_input *tracecmd_open_head(const char *file);
 struct tracecmd_input *tracecmd_open_fd(int fd);
 void tracecmd_ref(struct tracecmd_input *handle);
 void tracecmd_close(struct tracecmd_input *handle);

Hi Tzvetomir,

Quoted 5 lines

I was thinking, before we release libtracecmd, we should add tracecmd_open() and tracecmd_open_fd() to the library. Just because I find that tracecmd_open_head() is a awkward name to have alone and only makes sense if there's already a tracecmd_open(). It will also help with differentiating the different functions.

I'll add tracecmd_open() and tracecmd_open_fd() as APIs. The reason why tracecmd_open_head()
is used by KernelShark is that tracecmd_open() reads headers + tracing data and calculates the
timestamps. Thus makes it hard to open multiple tracing files from a single trace session and adjust
timestamps to be in a same time space. The current KernelShark open flow is:
- Open a trace file and parse only the headers with tracecmd_open_head()
- Based on the metadata information from the headers, check if there
is already an opened file from
the same tracing session. If such is found, pair both files with
tracecmd_pair_peer(), before reading
the tracing data.
- Read the tracing data from the file with tracecmd_init_data(). This
will adjust timestamps accordingly,
if there is a paired peer to the file.

We can rename tracecmd_open_head() to something else, or redesign the whole flow of opening trace files

Quoted 7 lines

I know we were going to only have functions that kernelshark uses, but that may be a little too limiting.

Thanks!

-- Steve

Signature · 2 lines
Tzvetomir (Ceco) Stoyanov
VMware Open Source Technology Center