Skip to contentSkip to conversation

Useful APIs for merging tracing files

PATCH Superseded Tzvetomir Stoyanov (VMware) 2 participants 5 messages Apr 9, 2020 – Apr 13, 2020

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover Useful APIs for merging tracing files

Helper APIs, used when opening and merging files from same tracing session.

Tzvetomir Stoyanov (VMware) (2):
trace-cmd: Add new API tracecmd_set_merge_peer()
trace-cmd: Validate input parameters of tracecmd_get_guest_cpumap()
API

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

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

When tracing host and one or more guest machines at the same time, guest and host are tracing peers. There is information in both trace files, related to host PID to guest vCPU mapping, timestamp synchronization and other. This information is useful when opening files at the same time and merging the events. When the host is set as a tracing peer to the guest, then the timestamps of guest's events are recalculated to match the host event's time

---
 include/trace-cmd/trace-cmd.h |  2 ++
 lib/trace-cmd/trace-input.c   | 62 ++++++++++++++++++++++++++++++++---
 2 files changed, 60 insertions(+), 4 deletions(-)
include/trace-cmd/trace-cmd.h +2 -0
index e22aa251..0fdc855b 100644
@@ -145,6 +145,8 @@ 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);
+int tracecmd_set_merge_peer(struct tracecmd_input *handle,
+			    struct tracecmd_input *peer);
 void tracecmd_ref(struct tracecmd_input *handle);
 void tracecmd_close(struct tracecmd_input *handle);
 int tracecmd_read_headers(struct tracecmd_input *handle);
lib/trace-cmd/trace-input.c +58 -4

97 lines not on this page · raw message

Signature · 1 line
2.25.1
#2 lore raw

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

Quoted 4 lines · On Thu, 9 Apr 2020 16:28:34 +0300 "Tzvetomir Stoyanov (VMware)"…
lib/trace-cmd/trace-input.c +4 -0
+/**
+ * tracecmd_set_merge_peer - Link a tracing peer to this handle
+ * @handle: input handle for the trace.dat file
+ * @peer: input handle for the tracing peer

lib/trace-cmd/trace-input.c fail: · line 3248

Quoted 10 lines
lib/trace-cmd/trace-input.c +10 -0
+ *
+ * When tracing host and one or more guest machines at the same time,
+ * guest and host are tracing peers. There is information in both trace
+ * files, related to host PID to guest vCPU mapping, timestamp synchronization
+ * and other. This information is useful when opening files at the same time and
+ * merging the events. When the host is set as a tracing peer to the guest, then
+ * the timestamps of guest's events are recalculated to match the host event's time
+ */
+int tracecmd_set_merge_peer(struct tracecmd_input *handle,
+			    struct tracecmd_input *peer)

I wonder it would be better to call this tracecmd_pair_peer(), like pairing a bluetooth headset with your phone?

lib/trace-cmd/trace-input.c fail: · line 3252

Quoted 4 lines
lib/trace-cmd/trace-input.c +4 -0
+{
+	if (!handle)
+		return -1;
+

This should probably fail if the host.peer_data is already set. Which means we should also have a way to unmerge (unpair) the two. Which is why I like the term "pair" better, as it is like paring a bluetooth device and then unpairing it.

-- Steve

Quoted 18 lines
lib/trace-cmd/trace-input.c +8 -1
+	handle->host.peer_data = peer;
+	tracecmd_ref(peer);
+	tsync_check_enable(handle);
+
+	return 0;
+}
+
 /**
  * tracecmd_ref - add a reference to the handle
  * @handle: input handle for the trace.dat file
@@ -3785,7 +3839,7 @@ int tracecmd_get_guest_cpumap(struct tracecmd_input *handle,
  */
 unsigned long long tracecmd_get_tsync_peer(struct tracecmd_input *handle)
 {
-	return handle->host.trace_id;
+	return handle->host.peer_trace_id;
 }
 
#3 lore raw

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

Quoted 32 lines · Steven Rostedt
Quoted 4 lines · On Thu, 9 Apr 2020 16:28:34 +0300 "Tzvetomir Stoyanov (VMware)"…
lib/trace-cmd/trace-input.c +4 -0
+/**
+ * tracecmd_set_merge_peer - Link a tracing peer to this handle
+ * @handle: input handle for the trace.dat file
+ * @peer: input handle for the tracing peer

lib/trace-cmd/trace-input.c fail: · line 3248

Quoted 10 lines
lib/trace-cmd/trace-input.c +10 -0
+ *
+ * When tracing host and one or more guest machines at the same time,
+ * guest and host are tracing peers. There is information in both trace
+ * files, related to host PID to guest vCPU mapping, timestamp synchronization
+ * and other. This information is useful when opening files at the same time and
+ * merging the events. When the host is set as a tracing peer to the guest, then
+ * the timestamps of guest's events are recalculated to match the host event's time
+ */
+int tracecmd_set_merge_peer(struct tracecmd_input *handle,
+                         struct tracecmd_input *peer)

I wonder it would be better to call this tracecmd_pair_peer(), like pairing a bluetooth headset with your phone?

lib/trace-cmd/trace-input.c fail: · line 3252

Quoted 4 lines
lib/trace-cmd/trace-input.c +4 -0
+{
+     if (!handle)
+             return -1;
+

This should probably fail if the host.peer_data is already set. Which means we should also have a way to unmerge (unpair) the two. Which is why I like the term "pair" better, as it is like paring a bluetooth device and then unpairing it.

Quoted 3 lines

-- Steve

It makes sense, I'll send the next version with these changes. Thanks, Steven!

Quoted 18 lines
Quoted 18 lines
lib/trace-cmd/trace-input.c +8 -1
+     handle->host.peer_data = peer;
+     tracecmd_ref(peer);
+     tsync_check_enable(handle);
+
+     return 0;
+}
+
 /**
  * tracecmd_ref - add a reference to the handle
  * @handle: input handle for the trace.dat file
@@ -3785,7 +3839,7 @@ int tracecmd_get_guest_cpumap(struct tracecmd_input *handle,
  */
 unsigned long long tracecmd_get_tsync_peer(struct tracecmd_input *handle)
 {
-     return handle->host.trace_id;
+     return handle->host.peer_trace_id;
 }
 
Signature · 2 lines
Tzvetomir (Ceco) Stoyanov
VMware Open Source Technology Center
#4 lore raw

PATCH 2/2 trace-cmd: Validate input parameters of tracecmd_get_guest_cpumap() API

In reply to Tzvetomir Stoyanov (VMware)

The API:
int tracecmd_get_guest_cpumap(struct tracecmd_input *handle,
unsigned long long trace_id,
const char **name,
int *vcpu_count, const int **cpu_pid)
is used to retrieve the host PID to guest VCPU mapping from a tracecmd input handle, if such information is available in the trace.dat file for the peer with the given trace_id. The input parameters name, vcpu_count and cpu_pid are mandatory, they are used to return then requested mapping. The API could be used also to check if such information is available, without requesting it. Made those input parameters optional, so the API can be used in this use case.

---
 lib/trace-cmd/trace-input.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
lib/trace-cmd/trace-input.c +6 -3
index 6c358131..8651dac1 100644
@@ -3823,9 +3823,12 @@ int tracecmd_get_guest_cpumap(struct tracecmd_input *handle,
 	if (!guest)
 		return -1;
 
-	*name = guest->name;
-	*vcpu_count = guest->vcpu_count;
-	*cpu_pid = guest->cpu_pid;
+	if (name)
+		*name = guest->name;
+	if (vcpu_count)
+		*vcpu_count = guest->vcpu_count;
+	if (cpu_pid)
+		*cpu_pid = guest->cpu_pid;
 	return 0;
 }
 
Signature · 1 line
2.25.1