linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] Useful APIs for merging tracing files
@ 2020-04-09 13:28 Tzvetomir Stoyanov (VMware)
  2020-04-09 13:28 ` [PATCH 1/2] trace-cmd: Add new API tracecmd_set_merge_peer() Tzvetomir Stoyanov (VMware)
  2020-04-09 13:28 ` [PATCH 2/2] trace-cmd: Validate input parameters of tracecmd_get_guest_cpumap() API Tzvetomir Stoyanov (VMware)
  0 siblings, 2 replies; 5+ messages in thread
From: Tzvetomir Stoyanov (VMware) @ 2020-04-09 13:28 UTC (permalink / raw)
  To: rostedt; +Cc: linux-trace-devel

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(-)

-- 
2.25.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/2] trace-cmd: Add new API tracecmd_set_merge_peer()
  2020-04-09 13:28 [PATCH 0/2] Useful APIs for merging tracing files Tzvetomir Stoyanov (VMware)
@ 2020-04-09 13:28 ` Tzvetomir Stoyanov (VMware)
  2020-04-10  1:07   ` Steven Rostedt
  2020-04-09 13:28 ` [PATCH 2/2] trace-cmd: Validate input parameters of tracecmd_get_guest_cpumap() API Tzvetomir Stoyanov (VMware)
  1 sibling, 1 reply; 5+ messages in thread
From: Tzvetomir Stoyanov (VMware) @ 2020-04-09 13:28 UTC (permalink / raw)
  To: rostedt; +Cc: linux-trace-devel

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

Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
---
 include/trace-cmd/trace-cmd.h |  2 ++
 lib/trace-cmd/trace-input.c   | 62 ++++++++++++++++++++++++++++++++---
 2 files changed, 60 insertions(+), 4 deletions(-)

diff --git a/include/trace-cmd/trace-cmd.h b/include/trace-cmd/trace-cmd.h
index e22aa251..0fdc855b 100644
--- a/include/trace-cmd/trace-cmd.h
+++ b/include/trace-cmd/trace-cmd.h
@@ -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);
diff --git a/lib/trace-cmd/trace-input.c b/lib/trace-cmd/trace-input.c
index efc8d4bd..6c358131 100644
--- a/lib/trace-cmd/trace-input.c
+++ b/lib/trace-cmd/trace-input.c
@@ -91,8 +91,9 @@ struct guest_trace_info {
 };
 
 struct host_trace_info {
-	unsigned long long	trace_id;
+	unsigned long long	peer_trace_id;
 	bool			sync_enable;
+	struct tracecmd_input	*peer_data;
 	int			ts_samples_count;
 	struct ts_offset_sample	*ts_samples;
 };
@@ -2194,10 +2195,38 @@ static void tsync_offset_load(struct tracecmd_input *handle, char *buf)
 		host->sync_enable = true;
 }
 
+static void tsync_check_enable(struct tracecmd_input *handle)
+{
+	struct host_trace_info	*host = &handle->host;
+	struct guest_trace_info *guest;
+
+	host->sync_enable = false;
+
+	if (!host->peer_data || !host->peer_data->guest ||
+	    !host->ts_samples_count || !host->ts_samples)
+		return;
+	if (host->peer_trace_id != host->peer_data->trace_id)
+		return;
+	guest = host->peer_data->guest;
+	while (guest) {
+		if (guest->trace_id == handle->trace_id)
+			break;
+		guest = guest->next;
+	}
+	if (!guest)
+		return;
+
+	host->sync_enable = true;
+}
+
 static void trace_tsync_offset_free(struct host_trace_info *host)
 {
 	free(host->ts_samples);
 	host->ts_samples = NULL;
+	if (host->peer_data) {
+		tracecmd_close(host->peer_data);
+		host->peer_data = NULL;
+	}
 }
 
 static int trace_pid_map_cmp(const void *a, const void *b)
@@ -2510,8 +2539,8 @@ static int handle_options(struct tracecmd_input *handle)
 			 */
 			if (size < 12 || handle->flags & TRACECMD_FL_IGNORE_DATE)
 				break;
-			handle->host.trace_id = tep_read_number(handle->pevent,
-								buf, 8);
+			handle->host.peer_trace_id = tep_read_number(handle->pevent,
+								     buf, 8);
 			handle->host.ts_samples_count = tep_read_number(handle->pevent,
 									buf + 8, 4);
 			samples_size = (8 * handle->host.ts_samples_count);
@@ -3203,6 +3232,31 @@ fail:
 	return NULL;
 }
 
+/**
+ * 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
+ *
+ * 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)
+{
+	if (!handle)
+		return -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;
 }
 
 /**
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/2] trace-cmd: Validate input parameters of tracecmd_get_guest_cpumap() API
  2020-04-09 13:28 [PATCH 0/2] Useful APIs for merging tracing files Tzvetomir Stoyanov (VMware)
  2020-04-09 13:28 ` [PATCH 1/2] trace-cmd: Add new API tracecmd_set_merge_peer() Tzvetomir Stoyanov (VMware)
@ 2020-04-09 13:28 ` Tzvetomir Stoyanov (VMware)
  1 sibling, 0 replies; 5+ messages in thread
From: Tzvetomir Stoyanov (VMware) @ 2020-04-09 13:28 UTC (permalink / raw)
  To: rostedt; +Cc: linux-trace-devel

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.

Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
---
 lib/trace-cmd/trace-input.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/lib/trace-cmd/trace-input.c b/lib/trace-cmd/trace-input.c
index 6c358131..8651dac1 100644
--- a/lib/trace-cmd/trace-input.c
+++ b/lib/trace-cmd/trace-input.c
@@ -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;
 }
 
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] trace-cmd: Add new API tracecmd_set_merge_peer()
  2020-04-09 13:28 ` [PATCH 1/2] trace-cmd: Add new API tracecmd_set_merge_peer() Tzvetomir Stoyanov (VMware)
@ 2020-04-10  1:07   ` Steven Rostedt
  2020-04-13  7:05     ` Tzvetomir Stoyanov
  0 siblings, 1 reply; 5+ messages in thread
From: Steven Rostedt @ 2020-04-10  1:07 UTC (permalink / raw)
  To: Tzvetomir Stoyanov (VMware); +Cc: linux-trace-devel

On Thu,  9 Apr 2020 16:28:34 +0300
"Tzvetomir Stoyanov (VMware)" <tz.stoyanov@gmail.com> wrote:

> +/**
> + * 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
> + *
> + * 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?

> +{
> +	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


> +	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;
>  }
>  

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] trace-cmd: Add new API tracecmd_set_merge_peer()
  2020-04-10  1:07   ` Steven Rostedt
@ 2020-04-13  7:05     ` Tzvetomir Stoyanov
  0 siblings, 0 replies; 5+ messages in thread
From: Tzvetomir Stoyanov @ 2020-04-13  7:05 UTC (permalink / raw)
  To: Steven Rostedt; +Cc: linux-trace-devel

On Fri, Apr 10, 2020 at 4:07 AM Steven Rostedt <rostedt@goodmis.org> wrote:
>
> On Thu,  9 Apr 2020 16:28:34 +0300
> "Tzvetomir Stoyanov (VMware)" <tz.stoyanov@gmail.com> wrote:
>
> > +/**
> > + * 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
> > + *
> > + * 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?
>
> > +{
> > +     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
>
>
It makes sense, I'll send the next version with these changes.
Thanks, Steven!

> > +     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;
> >  }
> >



-- 
Tzvetomir (Ceco) Stoyanov
VMware Open Source Technology Center

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-04-13  7:06 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-09 13:28 [PATCH 0/2] Useful APIs for merging tracing files Tzvetomir Stoyanov (VMware)
2020-04-09 13:28 ` [PATCH 1/2] trace-cmd: Add new API tracecmd_set_merge_peer() Tzvetomir Stoyanov (VMware)
2020-04-10  1:07   ` Steven Rostedt
2020-04-13  7:05     ` Tzvetomir Stoyanov
2020-04-09 13:28 ` [PATCH 2/2] trace-cmd: Validate input parameters of tracecmd_get_guest_cpumap() API 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).