diff options
| author | Stephane Eranian <eranian@google.com> | 2013-08-21 06:10:25 -0400 |
|---|---|---|
| committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2013-09-11 09:09:32 -0400 |
| commit | 5c5e854bc760a2e2c878df3cfcf2afa4febcd511 (patch) | |
| tree | cc0c44e8d8d9804f30c90f067d08c6cb4c9565ac | |
| parent | e71aa28312b208a14cd87fa61e941ac8c85072f4 (diff) | |
perf tools: Add attr->mmap2 support
This patch adds support for the new PERF_RECORD_MMAP2 record type
exposed by the kernel. This is an extended PERF_RECORD_MMAP record.
It adds for each file-backed mapping the device major, minor number and
the inode number and generation.
This triplet uniquely identifies the source of a file-backed mapping. It
can be used to detect identical virtual mappings between processes, for
instance.
The patch will prefer MMAP2 over MMAP.
Signed-off-by: Stephane Eranian <eranian@google.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung.kim@lge.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/1377079825-19057-3-git-send-email-eranian@google.com
[ Cope with 314add6 "Change machine__findnew_thread() to set thread pid",
fix 'perf test' regression test entry affected,
use perf_missing_features.mmap2 to fallback to not using .mmap2 in older kernels,
so that new tools can work with kernels where this feature is not present ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
| -rw-r--r-- | tools/perf/builtin-annotate.c | 1 | ||||
| -rw-r--r-- | tools/perf/builtin-inject.c | 15 | ||||
| -rw-r--r-- | tools/perf/builtin-mem.c | 1 | ||||
| -rw-r--r-- | tools/perf/builtin-report.c | 1 | ||||
| -rw-r--r-- | tools/perf/builtin-script.c | 1 | ||||
| -rw-r--r-- | tools/perf/tests/perf-record.c | 15 | ||||
| -rw-r--r-- | tools/perf/util/build-id.c | 1 | ||||
| -rw-r--r-- | tools/perf/util/event.c | 56 | ||||
| -rw-r--r-- | tools/perf/util/event.h | 19 | ||||
| -rw-r--r-- | tools/perf/util/evsel.c | 16 | ||||
| -rw-r--r-- | tools/perf/util/header.c | 3 | ||||
| -rw-r--r-- | tools/perf/util/machine.c | 53 | ||||
| -rw-r--r-- | tools/perf/util/machine.h | 1 | ||||
| -rw-r--r-- | tools/perf/util/map.c | 8 | ||||
| -rw-r--r-- | tools/perf/util/map.h | 8 | ||||
| -rw-r--r-- | tools/perf/util/session.c | 25 | ||||
| -rw-r--r-- | tools/perf/util/tool.h | 1 |
17 files changed, 200 insertions, 25 deletions
diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c index f988d380c52f..5ebd0c3b71b6 100644 --- a/tools/perf/builtin-annotate.c +++ b/tools/perf/builtin-annotate.c | |||
| @@ -277,6 +277,7 @@ int cmd_annotate(int argc, const char **argv, const char *prefix __maybe_unused) | |||
| 277 | .tool = { | 277 | .tool = { |
| 278 | .sample = process_sample_event, | 278 | .sample = process_sample_event, |
| 279 | .mmap = perf_event__process_mmap, | 279 | .mmap = perf_event__process_mmap, |
| 280 | .mmap2 = perf_event__process_mmap2, | ||
| 280 | .comm = perf_event__process_comm, | 281 | .comm = perf_event__process_comm, |
| 281 | .exit = perf_event__process_exit, | 282 | .exit = perf_event__process_exit, |
| 282 | .fork = perf_event__process_fork, | 283 | .fork = perf_event__process_fork, |
diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c index 9b336fdb6f71..423875c999b2 100644 --- a/tools/perf/builtin-inject.c +++ b/tools/perf/builtin-inject.c | |||
| @@ -123,6 +123,19 @@ static int perf_event__repipe_mmap(struct perf_tool *tool, | |||
| 123 | return err; | 123 | return err; |
| 124 | } | 124 | } |
| 125 | 125 | ||
| 126 | static int perf_event__repipe_mmap2(struct perf_tool *tool, | ||
| 127 | union perf_event *event, | ||
| 128 | struct perf_sample *sample, | ||
| 129 | struct machine *machine) | ||
| 130 | { | ||
| 131 | int err; | ||
| 132 | |||
| 133 | err = perf_event__process_mmap2(tool, event, sample, machine); | ||
| 134 | perf_event__repipe(tool, event, sample, machine); | ||
| 135 | |||
| 136 | return err; | ||
| 137 | } | ||
| 138 | |||
| 126 | static int perf_event__repipe_fork(struct perf_tool *tool, | 139 | static int perf_event__repipe_fork(struct perf_tool *tool, |
| 127 | union perf_event *event, | 140 | union perf_event *event, |
| 128 | struct perf_sample *sample, | 141 | struct perf_sample *sample, |
| @@ -339,6 +352,7 @@ static int __cmd_inject(struct perf_inject *inject) | |||
| 339 | 352 | ||
| 340 | if (inject->build_ids || inject->sched_stat) { | 353 | if (inject->build_ids || inject->sched_stat) { |
| 341 | inject->tool.mmap = perf_event__repipe_mmap; | 354 | inject->tool.mmap = perf_event__repipe_mmap; |
| 355 | inject->tool.mmap2 = perf_event__repipe_mmap2; | ||
| 342 | inject->tool.fork = perf_event__repipe_fork; | 356 | inject->tool.fork = perf_event__repipe_fork; |
| 343 | inject->tool.tracing_data = perf_event__repipe_tracing_data; | 357 | inject->tool.tracing_data = perf_event__repipe_tracing_data; |
| 344 | } | 358 | } |
| @@ -390,6 +404,7 @@ int cmd_inject(int argc, const char **argv, const char *prefix __maybe_unused) | |||
| 390 | .tool = { | 404 | .tool = { |
| 391 | .sample = perf_event__repipe_sample, | 405 | .sample = perf_event__repipe_sample, |
| 392 | .mmap = perf_event__repipe, | 406 | .mmap = perf_event__repipe, |
| 407 | .mmap2 = perf_event__repipe, | ||
| 393 | .comm = perf_event__repipe, | 408 | .comm = perf_event__repipe, |
| 394 | .fork = perf_event__repipe, | 409 | .fork = perf_event__repipe, |
| 395 | .exit = perf_event__repipe, | 410 | .exit = perf_event__repipe, |
diff --git a/tools/perf/builtin-mem.c b/tools/perf/builtin-mem.c index 791b432df847..253133a6251d 100644 --- a/tools/perf/builtin-mem.c +++ b/tools/perf/builtin-mem.c | |||
| @@ -190,6 +190,7 @@ int cmd_mem(int argc, const char **argv, const char *prefix __maybe_unused) | |||
| 190 | .tool = { | 190 | .tool = { |
| 191 | .sample = process_sample_event, | 191 | .sample = process_sample_event, |
| 192 | .mmap = perf_event__process_mmap, | 192 | .mmap = perf_event__process_mmap, |
| 193 | .mmap2 = perf_event__process_mmap2, | ||
| 193 | .comm = perf_event__process_comm, | 194 | .comm = perf_event__process_comm, |
| 194 | .lost = perf_event__process_lost, | 195 | .lost = perf_event__process_lost, |
| 195 | .fork = perf_event__process_fork, | 196 | .fork = perf_event__process_fork, |
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c index 9725aa375414..8e50d8d77419 100644 --- a/tools/perf/builtin-report.c +++ b/tools/perf/builtin-report.c | |||
| @@ -744,6 +744,7 @@ int cmd_report(int argc, const char **argv, const char *prefix __maybe_unused) | |||
| 744 | .tool = { | 744 | .tool = { |
| 745 | .sample = process_sample_event, | 745 | .sample = process_sample_event, |
| 746 | .mmap = perf_event__process_mmap, | 746 | .mmap = perf_event__process_mmap, |
| 747 | .mmap2 = perf_event__process_mmap2, | ||
| 747 | .comm = perf_event__process_comm, | 748 | .comm = perf_event__process_comm, |
| 748 | .exit = perf_event__process_exit, | 749 | .exit = perf_event__process_exit, |
| 749 | .fork = perf_event__process_fork, | 750 | .fork = perf_event__process_fork, |
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index 93a34cef9676..7f31a3ded1b6 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c | |||
| @@ -542,6 +542,7 @@ static int process_sample_event(struct perf_tool *tool __maybe_unused, | |||
| 542 | static struct perf_tool perf_script = { | 542 | static struct perf_tool perf_script = { |
| 543 | .sample = process_sample_event, | 543 | .sample = process_sample_event, |
| 544 | .mmap = perf_event__process_mmap, | 544 | .mmap = perf_event__process_mmap, |
| 545 | .mmap2 = perf_event__process_mmap2, | ||
| 545 | .comm = perf_event__process_comm, | 546 | .comm = perf_event__process_comm, |
| 546 | .exit = perf_event__process_exit, | 547 | .exit = perf_event__process_exit, |
| 547 | .fork = perf_event__process_fork, | 548 | .fork = perf_event__process_fork, |
diff --git a/tools/perf/tests/perf-record.c b/tools/perf/tests/perf-record.c index 72d8881873b0..b8a7056519ac 100644 --- a/tools/perf/tests/perf-record.c +++ b/tools/perf/tests/perf-record.c | |||
| @@ -50,7 +50,7 @@ int test__PERF_RECORD(void) | |||
| 50 | struct perf_sample sample; | 50 | struct perf_sample sample; |
| 51 | const char *cmd = "sleep"; | 51 | const char *cmd = "sleep"; |
| 52 | const char *argv[] = { cmd, "1", NULL, }; | 52 | const char *argv[] = { cmd, "1", NULL, }; |
| 53 | char *bname; | 53 | char *bname, *mmap_filename; |
| 54 | u64 prev_time = 0; | 54 | u64 prev_time = 0; |
| 55 | bool found_cmd_mmap = false, | 55 | bool found_cmd_mmap = false, |
| 56 | found_libc_mmap = false, | 56 | found_libc_mmap = false, |
| @@ -212,6 +212,7 @@ int test__PERF_RECORD(void) | |||
| 212 | 212 | ||
| 213 | if ((type == PERF_RECORD_COMM || | 213 | if ((type == PERF_RECORD_COMM || |
| 214 | type == PERF_RECORD_MMAP || | 214 | type == PERF_RECORD_MMAP || |
| 215 | type == PERF_RECORD_MMAP2 || | ||
| 215 | type == PERF_RECORD_FORK || | 216 | type == PERF_RECORD_FORK || |
| 216 | type == PERF_RECORD_EXIT) && | 217 | type == PERF_RECORD_EXIT) && |
| 217 | (pid_t)event->comm.pid != evlist->workload.pid) { | 218 | (pid_t)event->comm.pid != evlist->workload.pid) { |
| @@ -220,7 +221,8 @@ int test__PERF_RECORD(void) | |||
| 220 | } | 221 | } |
| 221 | 222 | ||
| 222 | if ((type == PERF_RECORD_COMM || | 223 | if ((type == PERF_RECORD_COMM || |
| 223 | type == PERF_RECORD_MMAP) && | 224 | type == PERF_RECORD_MMAP || |
| 225 | type == PERF_RECORD_MMAP2) && | ||
| 224 | event->comm.pid != event->comm.tid) { | 226 | event->comm.pid != event->comm.tid) { |
| 225 | pr_debug("%s with different pid/tid!\n", name); | 227 | pr_debug("%s with different pid/tid!\n", name); |
| 226 | ++errs; | 228 | ++errs; |
| @@ -236,7 +238,12 @@ int test__PERF_RECORD(void) | |||
| 236 | case PERF_RECORD_EXIT: | 238 | case PERF_RECORD_EXIT: |
| 237 | goto found_exit; | 239 | goto found_exit; |
| 238 | case PERF_RECORD_MMAP: | 240 | case PERF_RECORD_MMAP: |
| 239 | bname = strrchr(event->mmap.filename, '/'); | 241 | mmap_filename = event->mmap.filename; |
| 242 | goto check_bname; | ||
| 243 | case PERF_RECORD_MMAP2: | ||
| 244 | mmap_filename = event->mmap2.filename; | ||
| 245 | check_bname: | ||
| 246 | bname = strrchr(mmap_filename, '/'); | ||
| 240 | if (bname != NULL) { | 247 | if (bname != NULL) { |
| 241 | if (!found_cmd_mmap) | 248 | if (!found_cmd_mmap) |
| 242 | found_cmd_mmap = !strcmp(bname + 1, cmd); | 249 | found_cmd_mmap = !strcmp(bname + 1, cmd); |
| @@ -245,7 +252,7 @@ int test__PERF_RECORD(void) | |||
| 245 | if (!found_ld_mmap) | 252 | if (!found_ld_mmap) |
| 246 | found_ld_mmap = !strncmp(bname + 1, "ld", 2); | 253 | |
