]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
perf record: Add --sample-mem-info option
authorNamhyung Kim <namhyung@kernel.org>
Wed, 30 Apr 2025 20:55:39 +0000 (13:55 -0700)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Fri, 2 May 2025 18:36:14 +0000 (15:36 -0300)
There's no way to enable PERF_SAMPLE_DATA_SRC without PERF_SAMPLE_ADDR
which brings a lot of overhead due to the number of MMAP[2] records.

Let's add a new option to enable this information separately.

Committer testing:

  # perf record -a --sample-mem-info
  ^C[ perf record: Woken up 1 times to write data ]
  [ perf record: Captured and wrote 1.815 MB perf.data (2637 samples) ]
  #
  # perf evlist -v
  cycles:P: type: 0 (PERF_TYPE_HARDWARE), size: 136, config: 0 (PERF_COUNT_HW_CPU_CYCLES), { sample_period, sample_freq }: 4000, sample_type: IP|TID|TIME|CPU|PERIOD|IDENTIFIER|DATA_SRC, read_format: ID|LOST, disabled: 1, freq: 1, precise_ip: 2, sample_id_all: 1
  dummy:u: type: 1 (PERF_TYPE_SOFTWARE), size: 136, config: 0x9 (PERF_COUNT_SW_DUMMY), { sample_period, sample_freq }: 1, sample_type: IP|TID|TIME|CPU|IDENTIFIER|DATA_SRC, read_format: ID|LOST, exclude_kernel: 1, exclude_hv: 1, mmap: 1, comm: 1, task: 1, sample_id_all: 1, exclude_guest: 1, mmap2: 1, comm_exec: 1, ksymbol: 1, bpf_event: 1
  #
  # perf report -D |& grep -w PERF_RECORD_SAMPLE -A3 -m1
  0 44675164447282 0x1a7590 [0x40]: PERF_RECORD_SAMPLE(IP, 0x4001): 107299/107299: 0xffffffffac4a5e11 period: 144 addr: 0
   . data_src: 0x229080142
   ... thread: perf:107299
   ...... dso: /lib/modules/6.15.0-rc4+/build/vmlinux
  #

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@arm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Link: https://lore.kernel.org/r/20250430205548.789750-3-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/Documentation/perf-record.txt
tools/perf/builtin-record.c
tools/perf/util/evsel.c
tools/perf/util/record.h

index c7fc1ba265e2755d339c4b04c9ea5ea79d2eae86..c59f1e79f2b4a6f84f3f02c58d0d086277b41150 100644 (file)
@@ -340,7 +340,7 @@ OPTIONS
 
 -d::
 --data::
-       Record the sample virtual addresses.
+       Record the sample virtual addresses.  Implies --sample-mem-info.
 
 --phys-data::
        Record the sample physical addresses.
@@ -368,6 +368,11 @@ OPTIONS
        the sample_type member of the struct perf_event_attr argument to the
        perf_event_open system call.
 
+--sample-mem-info::
+       Record the sample data source information for memory operations.
+       It requires hardware supports and may work on specific events only.
+       Please consider using 'perf mem record' instead if you're not sure.
+
 -n::
 --no-samples::
        Don't sample.
index ba20bf7c011d7765c6e479bce47e76f6f8f8f607..6637a3acb1f1295f0aa92f2961c9bf38cdab5b45 100644 (file)
@@ -3436,6 +3436,8 @@ static struct option __record_options[] = {
                    "Record the sampled data address data page size"),
        OPT_BOOLEAN(0, "code-page-size", &record.opts.sample_code_page_size,
                    "Record the sampled code address (ip) page size"),
+       OPT_BOOLEAN(0, "sample-mem-info", &record.opts.sample_data_src,
+                   "Record the data source for memory operations"),
        OPT_BOOLEAN(0, "sample-cpu", &record.opts.sample_cpu, "Record the sample cpu"),
        OPT_BOOLEAN(0, "sample-identifier", &record.opts.sample_identifier,
                    "Record the sample identifier"),
@@ -4130,6 +4132,10 @@ int cmd_record(int argc, const char **argv)
                goto out_opts;
        }
 
+       /* For backward compatibility, -d implies --mem-info */
+       if (rec->opts.sample_address)
+               rec->opts.sample_data_src = true;
+
        /*
         * Allow aliases to facilitate the lookup of symbols for address
         * filters. Refer to auxtrace_parse_filters().
index 1d79ffecd41f10ec339e079fe7838ad7e01c66c1..0f86df259c822799653597cad5661be282132dea 100644 (file)
@@ -1425,7 +1425,7 @@ void evsel__config(struct evsel *evsel, struct record_opts *opts,
                evsel__set_sample_bit(evsel, CPU);
        }
 
-       if (opts->sample_address)
+       if (opts->sample_data_src)
                evsel__set_sample_bit(evsel, DATA_SRC);
 
        if (opts->sample_phys_addr)
index a6566134e09e5b193d7ad709d74e7c34ed6f62ef..f1956c4db3195070f4b6047e486e9e75c0b82209 100644 (file)
@@ -28,6 +28,7 @@ struct record_opts {
        bool          sample_time_set;
        bool          sample_cpu;
        bool          sample_identifier;
+       bool          sample_data_src;
        bool          period;
        bool          period_set;
        bool          running_time;