Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf data convert: Prefer sampled CPU when exporting JSON

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>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/r/20220526201506.2028281-1-schapla@codeweavers.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Shawn M. Chapla and committed by
Arnaldo Carvalho de Melo
924a2215 399bd66e

+4 -1
+4 -1
tools/perf/util/data-convert-json.c
··· 149 149 struct convert_json *c = container_of(tool, struct convert_json, tool); 150 150 FILE *out = c->out; 151 151 struct addr_location al, tal; 152 + u64 sample_type = __evlist__combined_sample_type(evsel->evlist); 152 153 u8 cpumode = PERF_RECORD_MISC_USER; 153 154 154 155 if (machine__resolve(machine, &al, sample) < 0) { ··· 169 168 output_json_key_format(out, true, 3, "pid", "%i", al.thread->pid_); 170 169 output_json_key_format(out, true, 3, "tid", "%i", al.thread->tid); 171 170 172 - if (al.thread->cpu >= 0) 171 + if ((sample_type & PERF_SAMPLE_CPU)) 172 + output_json_key_format(out, true, 3, "cpu", "%i", sample->cpu); 173 + else if (al.thread->cpu >= 0) 173 174 output_json_key_format(out, true, 3, "cpu", "%i", al.thread->cpu); 174 175 175 176 output_json_key_string(out, true, 3, "comm", thread__comm_str(al.thread));