All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] perf data: Prefer sampled CPU when exporting JSON
@ 2022-05-26 20:14 Shawn M. Chapla
  2022-06-22 14:42 ` Shawn M. Chapla
  0 siblings, 1 reply; 4+ messages in thread
From: Shawn M. Chapla @ 2022-05-26 20:14 UTC (permalink / raw)
  To: linux-kernel
  Cc: Shawn M . Chapla, Peter Zijlstra, Ingo Molnar,
	Arnaldo Carvalho de Melo, Mark Rutland, Alexander Shishkin,
	Jiri Olsa, Namhyung Kim

When CPU has been explicitly sampled (via --sample-cpu), prefer this
sampled value over the thread CPU value when exporting to JSON.

Signed-off-by: Shawn M. Chapla <schapla@codeweavers.com>
---
 tools/perf/util/data-convert-json.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/data-convert-json.c b/tools/perf/util/data-convert-json.c
index f1ab6edba446..613d6ae82663 100644
--- a/tools/perf/util/data-convert-json.c
+++ b/tools/perf/util/data-convert-json.c
@@ -149,6 +149,7 @@ static int process_sample_event(struct perf_tool *tool,
 	struct convert_json *c = container_of(tool, struct convert_json, tool);
 	FILE *out = c->out;
 	struct addr_location al, tal;
+	u64 sample_type = __evlist__combined_sample_type(evsel->evlist);
 	u8 cpumode = PERF_RECORD_MISC_USER;
 
 	if (machine__resolve(machine, &al, sample) < 0) {
@@ -168,7 +169,9 @@ static int process_sample_event(struct perf_tool *tool,
 	output_json_key_format(out, true, 3, "pid", "%i", al.thread->pid_);
 	output_json_key_format(out, true, 3, "tid", "%i", al.thread->tid);
 
-	if (al.thread->cpu >= 0)
+	if ((sample_type & PERF_SAMPLE_CPU))
+		output_json_key_format(out, true, 3, "cpu", "%i", sample->cpu);
+	else if (al.thread->cpu >= 0)
 		output_json_key_format(out, true, 3, "cpu", "%i", al.thread->cpu);
 
 	output_json_key_string(out, true, 3, "comm", thread__comm_str(al.thread));
-- 
2.36.1


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

* Re: [PATCH] perf data: Prefer sampled CPU when exporting JSON
  2022-05-26 20:14 [PATCH] perf data: Prefer sampled CPU when exporting JSON Shawn M. Chapla
@ 2022-06-22 14:42 ` Shawn M. Chapla
  2022-06-22 16:30   ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 4+ messages in thread
From: Shawn M. Chapla @ 2022-06-22 14:42 UTC (permalink / raw)
  To: linux-kernel
  Cc: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim

On Thu, May 26, 2022 at 04:14:47PM -0400, Shawn M. Chapla wrote:
> When CPU has been explicitly sampled (via --sample-cpu), prefer this
> sampled value over the thread CPU value when exporting to JSON.
> 
> Signed-off-by: Shawn M. Chapla <schapla@codeweavers.com>
> ---
>  tools/perf/util/data-convert-json.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/perf/util/data-convert-json.c b/tools/perf/util/data-convert-json.c
> index f1ab6edba446..613d6ae82663 100644
> --- a/tools/perf/util/data-convert-json.c
> +++ b/tools/perf/util/data-convert-json.c
> @@ -149,6 +149,7 @@ static int process_sample_event(struct perf_tool *tool,
>  	struct convert_json *c = container_of(tool, struct convert_json, tool);
>  	FILE *out = c->out;
>  	struct addr_location al, tal;
> +	u64 sample_type = __evlist__combined_sample_type(evsel->evlist);
>  	u8 cpumode = PERF_RECORD_MISC_USER;
>  
>  	if (machine__resolve(machine, &al, sample) < 0) {
> @@ -168,7 +169,9 @@ static int process_sample_event(struct perf_tool *tool,
>  	output_json_key_format(out, true, 3, "pid", "%i", al.thread->pid_);
>  	output_json_key_format(out, true, 3, "tid", "%i", al.thread->tid);
>  
> -	if (al.thread->cpu >= 0)
> +	if ((sample_type & PERF_SAMPLE_CPU))
> +		output_json_key_format(out, true, 3, "cpu", "%i", sample->cpu);
> +	else if (al.thread->cpu >= 0)
>  		output_json_key_format(out, true, 3, "cpu", "%i", al.thread->cpu);
>  
>  	output_json_key_string(out, true, 3, "comm", thread__comm_str(al.thread));
> -- 
> 2.36.1
> 

Just checking in to see if anyone has had a chance to take a look at
this yet.

Thanks,
Shawn

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

* Re: [PATCH] perf data: Prefer sampled CPU when exporting JSON
  2022-06-22 14:42 ` Shawn M. Chapla
@ 2022-06-22 16:30   ` Arnaldo Carvalho de Melo
  2022-06-22 16:39     ` Shawn M. Chapla
  0 siblings, 1 reply; 4+ messages in thread
From: Arnaldo Carvalho de Melo @ 2022-06-22 16:30 UTC (permalink / raw)
  To: Shawn M. Chapla
  Cc: linux-kernel, Peter Zijlstra, Ingo Molnar, Mark Rutland,
	Alexander Shishkin, Jiri Olsa, Namhyung Kim

Em Wed, Jun 22, 2022 at 10:42:43AM -0400, Shawn M. Chapla escreveu:
> On Thu, May 26, 2022 at 04:14:47PM -0400, Shawn M. Chapla wrote:
> > When CPU has been explicitly sampled (via --sample-cpu), prefer this
> > sampled value over the thread CPU value when exporting to JSON.

> > Signed-off-by: Shawn M. Chapla <schapla@codeweavers.com>
> > ---
> >  tools/perf/util/data-convert-json.c | 5 ++++-
> >  1 file changed, 4 insertions(+), 1 deletion(-)
> > 
> > diff --git a/tools/perf/util/data-convert-json.c b/tools/perf/util/data-convert-json.c
> > index f1ab6edba446..613d6ae82663 100644
> > --- a/tools/perf/util/data-convert-json.c
> > +++ b/tools/perf/util/data-convert-json.c
> > @@ -149,6 +149,7 @@ static int process_sample_event(struct perf_tool *tool,
> >  	struct convert_json *c = container_of(tool, struct convert_json, tool);
> >  	FILE *out = c->out;
> >  	struct addr_location al, tal;
> > +	u64 sample_type = __evlist__combined_sample_type(evsel->evlist);
> >  	u8 cpumode = PERF_RECORD_MISC_USER;
> >  
> >  	if (machine__resolve(machine, &al, sample) < 0) {
> > @@ -168,7 +169,9 @@ static int process_sample_event(struct perf_tool *tool,
> >  	output_json_key_format(out, true, 3, "pid", "%i", al.thread->pid_);
> >  	output_json_key_format(out, true, 3, "tid", "%i", al.thread->tid);
> >  
> > -	if (al.thread->cpu >= 0)
> > +	if ((sample_type & PERF_SAMPLE_CPU))
> > +		output_json_key_format(out, true, 3, "cpu", "%i", sample->cpu);
> > +	else if (al.thread->cpu >= 0)
> >  		output_json_key_format(out, true, 3, "cpu", "%i", al.thread->cpu);
> >  
> >  	output_json_key_string(out, true, 3, "comm", thread__comm_str(al.thread));
> > -- 
> > 2.36.1
> > 
> 
> Just checking in to see if anyone has had a chance to take a look at
> this yet.

Seems sensible, applying to perf/core for 5.20.

- Arnaldo

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

* Re: [PATCH] perf data: Prefer sampled CPU when exporting JSON
  2022-06-22 16:30   ` Arnaldo Carvalho de Melo
@ 2022-06-22 16:39     ` Shawn M. Chapla
  0 siblings, 0 replies; 4+ messages in thread
From: Shawn M. Chapla @ 2022-06-22 16:39 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: linux-kernel, Peter Zijlstra, Ingo Molnar, Mark Rutland,
	Alexander Shishkin, Jiri Olsa, Namhyung Kim

On Wed, Jun 22, 2022 at 01:30:30PM -0300, Arnaldo Carvalho de Melo wrote:
> Em Wed, Jun 22, 2022 at 10:42:43AM -0400, Shawn M. Chapla escreveu:
> > On Thu, May 26, 2022 at 04:14:47PM -0400, Shawn M. Chapla wrote:
> > > When CPU has been explicitly sampled (via --sample-cpu), prefer this
> > > sampled value over the thread CPU value when exporting to JSON.
> 
> > > Signed-off-by: Shawn M. Chapla <schapla@codeweavers.com>
> > > ---
> > >  tools/perf/util/data-convert-json.c | 5 ++++-
> > >  1 file changed, 4 insertions(+), 1 deletion(-)
> > > 
> > > diff --git a/tools/perf/util/data-convert-json.c b/tools/perf/util/data-convert-json.c
> > > index f1ab6edba446..613d6ae82663 100644
> > > --- a/tools/perf/util/data-convert-json.c
> > > +++ b/tools/perf/util/data-convert-json.c
> > > @@ -149,6 +149,7 @@ static int process_sample_event(struct perf_tool *tool,
> > >  	struct convert_json *c = container_of(tool, struct convert_json, tool);
> > >  	FILE *out = c->out;
> > >  	struct addr_location al, tal;
> > > +	u64 sample_type = __evlist__combined_sample_type(evsel->evlist);
> > >  	u8 cpumode = PERF_RECORD_MISC_USER;
> > >  
> > >  	if (machine__resolve(machine, &al, sample) < 0) {
> > > @@ -168,7 +169,9 @@ static int process_sample_event(struct perf_tool *tool,
> > >  	output_json_key_format(out, true, 3, "pid", "%i", al.thread->pid_);
> > >  	output_json_key_format(out, true, 3, "tid", "%i", al.thread->tid);
> > >  
> > > -	if (al.thread->cpu >= 0)
> > > +	if ((sample_type & PERF_SAMPLE_CPU))
> > > +		output_json_key_format(out, true, 3, "cpu", "%i", sample->cpu);
> > > +	else if (al.thread->cpu >= 0)
> > >  		output_json_key_format(out, true, 3, "cpu", "%i", al.thread->cpu);
> > >  
> > >  	output_json_key_string(out, true, 3, "comm", thread__comm_str(al.thread));
> > > -- 
> > > 2.36.1
> > > 
> > 
> > Just checking in to see if anyone has had a chance to take a look at
> > this yet.
> 
> Seems sensible, applying to perf/core for 5.20.
> 
> - Arnaldo

Thank you! I appreciate it.

Cheers,
Shawn

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

end of thread, other threads:[~2022-06-22 16:39 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-26 20:14 [PATCH] perf data: Prefer sampled CPU when exporting JSON Shawn M. Chapla
2022-06-22 14:42 ` Shawn M. Chapla
2022-06-22 16:30   ` Arnaldo Carvalho de Melo
2022-06-22 16:39     ` Shawn M. Chapla

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.