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

perf record: Add new option to sample identifier

In preparation for recording sideband events in a virtual machine guest so
that they can be injected into a host perf.data file.

Add an option to always include sample type PERF_SAMPLE_IDENTIFIER.

Committer testing:

# perf record sleep 1
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.020 MB perf.data (7 samples) ]
# perf evlist -v
cycles: size: 128, { sample_period, sample_freq }: 4000, sample_type: IP|TID|TIME|PERIOD, read_format: ID, disabled: 1, inherit: 1, mmap: 1, comm: 1, freq: 1, enable_on_exec: 1, task: 1, sample_id_all: 1, mmap2: 1, comm_exec: 1, ksymbol: 1, bpf_event: 1
#
#
# perf record --sample-identifier sleep 1
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.022 MB perf.data (7 samples) ]
# perf evlist -v
cycles: size: 128, { sample_period, sample_freq }: 4000, sample_type: IP|TID|TIME|PERIOD|IDENTIFIER, read_format: ID, disabled: 1, inherit: 1, mmap: 1, comm: 1, freq: 1, enable_on_exec: 1, task: 1, sample_id_all: 1, mmap2: 1, comm_exec: 1, ksymbol: 1, bpf_event: 1
#

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Acked-by: Ian Rogers <irogers@google.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: https://lore.kernel.org/r/20220615052511.4441-1-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Adrian Hunter and committed by
Arnaldo Carvalho de Melo
61110883 6b080312

+9 -1
+5
tools/perf/Documentation/perf-record.txt
··· 313 313 --sample-cpu:: 314 314 Record the sample cpu. 315 315 316 + --sample-identifier:: 317 + Record the sample identifier i.e. PERF_SAMPLE_IDENTIFIER bit set in 318 + the sample_type member of the struct perf_event_attr argument to the 319 + perf_event_open system call. 320 + 316 321 -n:: 317 322 --no-samples:: 318 323 Don't sample.
+2
tools/perf/builtin-record.c
··· 3191 3191 OPT_BOOLEAN(0, "code-page-size", &record.opts.sample_code_page_size, 3192 3192 "Record the sampled code address (ip) page size"), 3193 3193 OPT_BOOLEAN(0, "sample-cpu", &record.opts.sample_cpu, "Record the sample cpu"), 3194 + OPT_BOOLEAN(0, "sample-identifier", &record.opts.sample_identifier, 3195 + "Record the sample identifier"), 3194 3196 OPT_BOOLEAN_SET('T', "timestamp", &record.opts.sample_time, 3195 3197 &record.opts.sample_time_set, 3196 3198 "Record the sample timestamps"),
+1 -1
tools/perf/util/record.c
··· 121 121 evlist__for_each_entry(evlist, evsel) 122 122 evsel__config_leader_sampling(evsel, evlist); 123 123 124 - if (opts->full_auxtrace) { 124 + if (opts->full_auxtrace || opts->sample_identifier) { 125 125 /* 126 126 * Need to be able to synthesize and parse selected events with 127 127 * arbitrary sample types, which requires always being able to
+1
tools/perf/util/record.h
··· 28 28 bool sample_time; 29 29 bool sample_time_set; 30 30 bool sample_cpu; 31 + bool sample_identifier; 31 32 bool period; 32 33 bool period_set; 33 34 bool running_time;