Commit e29386c8 authored by Jiri Olsa's avatar Jiri Olsa Committed by Arnaldo Carvalho de Melo

perf record: Add --buildid-mmap option to enable PERF_RECORD_MMAP2's build id

Add --buildid-mmap option to enable build id in PERF_RECORD_MMAP2 events.

It will only work if there's kernel support for that and it disables
build id cache (implies --no-buildid).

It's also possible to enable it permanently via config option in
~/.perfconfig file:

  [record]
  build-id=mmap

Also added build_id bit in the verbose output for perf_event_attr:

  # perf record --buildid-mmap -vv
  ...
  perf_event_attr:
    type                             1
    size                             120
    ...
    build_id                         1

Adding also missing text_poke bit.

Committer testing:

  $ perf record -h build

   Usage: perf record [<options>] [<command>]
      or: perf record [<options>] -- <command> [<options>]

      -B, --no-buildid      do not collect buildids in perf.data
      -N, --no-buildid-cache
                            do not update the buildid cache
          --buildid-all     Record build-id of all DSOs regardless of hits
          --buildid-mmap    Record build-id in map events

  $

  $ perf record --buildid-mmap sleep 1
  Failed: no support to record build id in mmap events, update your kernel.
  $

After adding the needed kernel bits in a test kernel:

  $ perf record -vv --buildid-mmap sleep 1 |& grep -m1 build
  Enabling build id in mmap2 events.
  $ perf evlist -v
  cycles:u: size: 120, { sample_period, sample_freq }: 4000, sample_type: IP|TID|TIME|PERIOD, read_format: ID, disabled: 1, inherit: 1, exclude_kernel: 1, mmap: 1, comm: 1, freq: 1, enable_on_exec: 1, task: 1, sample_id_all: 1, exclude_guest: 1, mmap2: 1, comm_exec: 1, ksymbol: 1, bpf_event: 1, build_id: 1
  $
Signed-off-by: default avatarJiri Olsa <jolsa@kernel.org>
Tested-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
Acked-by: default avatarIan Rogers <irogers@google.com>
Acked-by: default avatarNamhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Alexei Budankov <abudankov@huawei.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Michael Petlan <mpetlan@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lore.kernel.org/lkml/20201214105457.543111-16-jolsa@kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 4183a8d7
...@@ -552,11 +552,12 @@ kmem.*:: ...@@ -552,11 +552,12 @@ kmem.*::
record.*:: record.*::
record.build-id:: record.build-id::
This option can be 'cache', 'no-cache' or 'skip'. This option can be 'cache', 'no-cache', 'skip' or 'mmap'.
'cache' is to post-process data and save/update the binaries into 'cache' is to post-process data and save/update the binaries into
the build-id cache (in ~/.debug). This is the default. the build-id cache (in ~/.debug). This is the default.
But if this option is 'no-cache', it will not update the build-id cache. But if this option is 'no-cache', it will not update the build-id cache.
'skip' skips post-processing and does not update the cache. 'skip' skips post-processing and does not update the cache.
'mmap' skips post-processing and reads build-ids from MMAP events.
record.call-graph:: record.call-graph::
This is identical to 'call-graph.record-mode', except it is This is identical to 'call-graph.record-mode', except it is
......
...@@ -485,6 +485,9 @@ Specify vmlinux path which has debuginfo. ...@@ -485,6 +485,9 @@ Specify vmlinux path which has debuginfo.
--buildid-all:: --buildid-all::
Record build-id of all DSOs regardless whether it's actually hit or not. Record build-id of all DSOs regardless whether it's actually hit or not.
--buildid-mmap::
Record build ids in mmap2 events, disables build id cache (implies --no-buildid).
--aio[=n]:: --aio[=n]::
Use <n> control blocks in asynchronous (Posix AIO) trace writing mode (default: 1, max: 4). Use <n> control blocks in asynchronous (Posix AIO) trace writing mode (default: 1, max: 4).
Asynchronous mode is supported only when linking Perf tool with libc library Asynchronous mode is supported only when linking Perf tool with libc library
......
...@@ -102,6 +102,7 @@ struct record { ...@@ -102,6 +102,7 @@ struct record {
bool no_buildid_cache; bool no_buildid_cache;
bool no_buildid_cache_set; bool no_buildid_cache_set;
bool buildid_all; bool buildid_all;
bool buildid_mmap;
bool timestamp_filename; bool timestamp_filename;
bool timestamp_boundary; bool timestamp_boundary;
struct switch_output switch_output; struct switch_output switch_output;
...@@ -2135,6 +2136,8 @@ static int perf_record_config(const char *var, const char *value, void *cb) ...@@ -2135,6 +2136,8 @@ static int perf_record_config(const char *var, const char *value, void *cb)
rec->no_buildid_cache = true; rec->no_buildid_cache = true;
else if (!strcmp(value, "skip")) else if (!strcmp(value, "skip"))
rec->no_buildid = true; rec->no_buildid = true;
else if (!strcmp(value, "mmap"))
rec->buildid_mmap = true;
else else
return -1; return -1;
return 0; return 0;
...@@ -2552,6 +2555,8 @@ static struct option __record_options[] = { ...@@ -2552,6 +2555,8 @@ static struct option __record_options[] = {
"file", "vmlinux pathname"), "file", "vmlinux pathname"),
OPT_BOOLEAN(0, "buildid-all", &record.buildid_all, OPT_BOOLEAN(0, "buildid-all", &record.buildid_all,
"Record build-id of all DSOs regardless of hits"), "Record build-id of all DSOs regardless of hits"),
OPT_BOOLEAN(0, "buildid-mmap", &record.buildid_mmap,
"Record build-id in map events"),
OPT_BOOLEAN(0, "timestamp-filename", &record.timestamp_filename, OPT_BOOLEAN(0, "timestamp-filename", &record.timestamp_filename,
"append timestamp to output filename"), "append timestamp to output filename"),
OPT_BOOLEAN(0, "timestamp-boundary", &record.timestamp_boundary, OPT_BOOLEAN(0, "timestamp-boundary", &record.timestamp_boundary,
...@@ -2655,6 +2660,21 @@ int cmd_record(int argc, const char **argv) ...@@ -2655,6 +2660,21 @@ int cmd_record(int argc, const char **argv)
} }
if (rec->buildid_mmap) {
if (!perf_can_record_build_id()) {
pr_err("Failed: no support to record build id in mmap events, update your kernel.\n");
err = -EINVAL;
goto out_opts;
}
pr_debug("Enabling build id in mmap2 events.\n");
/* Enable mmap build id synthesizing. */
symbol_conf.buildid_mmap2 = true;
/* Enable perf_event_attr::build_id bit. */
rec->opts.build_id = true;
/* Disable build id cache. */
rec->no_buildid = true;
}
if (rec->opts.kcore) if (rec->opts.kcore)
rec->data.is_dir = true; rec->data.is_dir = true;
......
...@@ -1168,10 +1168,12 @@ void evsel__config(struct evsel *evsel, struct record_opts *opts, ...@@ -1168,10 +1168,12 @@ void evsel__config(struct evsel *evsel, struct record_opts *opts,
if (opts->sample_weight) if (opts->sample_weight)
evsel__set_sample_bit(evsel, WEIGHT); evsel__set_sample_bit(evsel, WEIGHT);
attr->task = track; attr->task = track;
attr->mmap = track; attr->mmap = track;
attr->mmap2 = track && !perf_missing_features.mmap2; attr->mmap2 = track && !perf_missing_features.mmap2;
attr->comm = track; attr->comm = track;
attr->build_id = track && opts->build_id;
/* /*
* ksymbol is tracked separately with text poke because it needs to be * ksymbol is tracked separately with text poke because it needs to be
* system wide and enabled immediately. * system wide and enabled immediately.
......
...@@ -98,6 +98,11 @@ static void perf_probe_text_poke(struct evsel *evsel) ...@@ -98,6 +98,11 @@ static void perf_probe_text_poke(struct evsel *evsel)
evsel->core.attr.text_poke = 1; evsel->core.attr.text_poke = 1;
} }
static void perf_probe_build_id(struct evsel *evsel)
{
evsel->core.attr.build_id = 1;
}
bool perf_can_sample_identifier(void) bool perf_can_sample_identifier(void)
{ {
return perf_probe_api(perf_probe_sample_identifier); return perf_probe_api(perf_probe_sample_identifier);
...@@ -172,3 +177,8 @@ bool perf_can_aux_sample(void) ...@@ -172,3 +177,8 @@ bool perf_can_aux_sample(void)
return true; return true;
} }
bool perf_can_record_build_id(void)
{
return perf_probe_api(perf_probe_build_id);
}
...@@ -11,5 +11,6 @@ bool perf_can_record_cpu_wide(void); ...@@ -11,5 +11,6 @@ bool perf_can_record_cpu_wide(void);
bool perf_can_record_switch_events(void); bool perf_can_record_switch_events(void);
bool perf_can_record_text_poke_events(void); bool perf_can_record_text_poke_events(void);
bool perf_can_sample_identifier(void); bool perf_can_sample_identifier(void);
bool perf_can_record_build_id(void);
#endif // __PERF_API_PROBE_H #endif // __PERF_API_PROBE_H
...@@ -134,6 +134,8 @@ int perf_event_attr__fprintf(FILE *fp, struct perf_event_attr *attr, ...@@ -134,6 +134,8 @@ int perf_event_attr__fprintf(FILE *fp, struct perf_event_attr *attr,
PRINT_ATTRf(bpf_event, p_unsigned); PRINT_ATTRf(bpf_event, p_unsigned);
PRINT_ATTRf(aux_output, p_unsigned); PRINT_ATTRf(aux_output, p_unsigned);
PRINT_ATTRf(cgroup, p_unsigned); PRINT_ATTRf(cgroup, p_unsigned);
PRINT_ATTRf(text_poke, p_unsigned);
PRINT_ATTRf(build_id, p_unsigned);
PRINT_ATTRn("{ wakeup_events, wakeup_watermark }", wakeup_events, p_unsigned); PRINT_ATTRn("{ wakeup_events, wakeup_watermark }", wakeup_events, p_unsigned);
PRINT_ATTRf(bp_type, p_unsigned); PRINT_ATTRf(bp_type, p_unsigned);
......
...@@ -50,6 +50,7 @@ struct record_opts { ...@@ -50,6 +50,7 @@ struct record_opts {
bool no_bpf_event; bool no_bpf_event;
bool kcore; bool kcore;
bool text_poke; bool text_poke;
bool build_id;
unsigned int freq; unsigned int freq;
unsigned int mmap_pages; unsigned int mmap_pages;
unsigned int auxtrace_mmap_pages; unsigned int auxtrace_mmap_pages;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment