diff options
author | Namhyung Kim <namhyung@kernel.org> | 2015-01-29 03:06:44 -0500 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2015-01-29 14:37:20 -0500 |
commit | e3d5911221f5cf71e1f0306256d4e42d34a365d2 (patch) | |
tree | 2184bb4ec461ba141d8a89b2df2e63705d4cdfed /tools | |
parent | 4ac30cf74b308fb01338e660d3471cd490a7958a (diff) |
perf record: Show precise number of samples
After perf record finishes, it prints file size and number of samples in
the file but this info is wrong since it assumes typical sample size of
24 bytes and divides file size by the value.
However as we post-process recorded samples for build-id, it can show
correct number like below. If build-id post-processing is not requested
just omit the wrong number of samples.
$ perf record noploop 1
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.159 MB perf.data (3989 samples) ]
$ perf report --stdio -n
# To display the perf.data header info, please use --header/--header-only options.
#
# Samples: 3K of event 'cycles'
# Event count (approx.): 3771330663
#
# Overhead Samples Command Shared Object Symbol
# ........ ............ ....... ................ ..........................
#
99.90% 3982 noploop noploop [.] main
0.09% 1 noploop ld-2.17.so [.] _dl_check_map_versions
0.01% 1 noploop [kernel.vmlinux] [k] setup_arg_pages
0.00% 5 noploop [kernel.vmlinux] [k] intel_pmu_enable_all
Reported-by: Milian Wolff <mail@milianw.de>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Reviewed-by: Jiri Olsa <jolsa@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/1422518843-25818-4-git-send-email-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/perf/builtin-record.c | 51 |
1 files changed, 39 insertions, 12 deletions
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index 1134de22979e..9900b433e861 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c | |||
@@ -190,6 +190,19 @@ out: | |||
190 | return rc; | 190 | return rc; |
191 | } | 191 | } |
192 | 192 | ||
193 | static int process_sample_event(struct perf_tool *tool, | ||
194 | union perf_event *event, | ||
195 | struct perf_sample *sample, | ||
196 | struct perf_evsel *evsel, | ||
197 | struct machine *machine) | ||
198 | { | ||
199 | struct record *rec = container_of(tool, struct record, tool); | ||
200 | |||
201 | rec->samples++; | ||
202 | |||
203 | return build_id__mark_dso_hit(tool, event, sample, evsel, machine); | ||
204 | } | ||
205 | |||
193 | static int process_buildids(struct record *rec) | 206 | static int process_buildids(struct record *rec) |
194 | { | 207 | { |
195 | struct perf_data_file *file = &rec->file; | 208 | struct perf_data_file *file = &rec->file; |
@@ -212,7 +225,7 @@ static int process_buildids(struct record *rec) | |||
212 | */ | 225 | */ |
213 | symbol_conf.ignore_vmlinux_buildid = true; | 226 | symbol_conf.ignore_vmlinux_buildid = true; |
214 | 227 | ||
215 | return perf_session__process_events(session, &build_id__mark_dso_hit_ops); | 228 | return perf_session__process_events(session, &rec->tool); |
216 | } | 229 | } |
217 | 230 | ||
218 | static void perf_event__synthesize_guest_os(struct machine *machine, void *data) | 231 | static void perf_event__synthesize_guest_os(struct machine *machine, void *data) |
@@ -503,19 +516,9 @@ static int __cmd_record(struct record *rec, int argc, const char **argv) | |||
503 | goto out_child; | 516 | goto out_child; |
504 | } | 517 | } |
505 | 518 | ||
506 | if (!quiet) { | 519 | if (!quiet) |
507 | fprintf(stderr, "[ perf record: Woken up %ld times to write data ]\n", waking); | 520 | fprintf(stderr, "[ perf record: Woken up %ld times to write data ]\n", waking); |
508 | 521 | ||
509 | /* | ||
510 | * Approximate RIP event size: 24 bytes. | ||
511 | */ | ||
512 | fprintf(stderr, | ||
513 | "[ perf record: Captured and wrote %.3f MB %s (~%" PRIu64 " samples) ]\n", | ||
514 | (double)rec->bytes_written / 1024.0 / 1024.0, | ||
515 | file->path, | ||
516 | rec->bytes_written / 24); | ||
517 | } | ||
518 | |||
519 | out_child: | 522 | out_child: |
520 | if (forks) { | 523 | if (forks) { |
521 | int exit_status; | 524 | int exit_status; |
@@ -534,6 +537,9 @@ out_child: | |||
534 | } else | 537 | } else |
535 | status = err; | 538 | status = err; |
536 | 539 | ||
540 | /* this will be recalculated during process_buildids() */ | ||
541 | rec->samples = 0; | ||
542 | |||
537 | if (!err && !file->is_pipe) { | 543 | if (!err && !file->is_pipe) { |
538 | rec->session->header.data_size += rec->bytes_written; | 544 | rec->session->header.data_size += rec->bytes_written; |
539 | 545 | ||
@@ -543,6 +549,20 @@ out_child: | |||
543 | file->fd, true); | 549 | file->fd, true); |
544 | } | 550 | } |
545 | 551 | ||
552 | if (!err && !quiet) { | ||
553 | char samples[128]; | ||
554 | |||
555 | if (rec->samples) | ||
556 | scnprintf(samples, sizeof(samples), | ||
557 | " (%" PRIu64 " samples)", rec->samples); | ||
558 | else | ||
559 | samples[0] = '\0'; | ||
560 | |||
561 | fprintf(stderr, "[ perf record: Captured and wrote %.3f MB %s%s ]\n", | ||
562 | perf_data_file__size(file) / 1024.0 / 1024.0, | ||
563 | file->path, samples); | ||
564 | } | ||
565 | |||
546 | out_delete_session: | 566 | out_delete_session: |
547 | perf_session__delete(session); | 567 | perf_session__delete(session); |
548 | return status; | 568 | return status; |
@@ -719,6 +739,13 @@ static struct record record = { | |||
719 | .default_per_cpu = true, | 739 | .default_per_cpu = true, |
720 | }, | 740 | }, |
721 | }, | 741 | }, |
742 | .tool = { | ||
743 | .sample = process_sample_event, | ||
744 | .fork = perf_event__process_fork, | ||
745 | .comm = perf_event__process_comm, | ||
746 | .mmap = perf_event__process_mmap, | ||
747 | .mmap2 = perf_event__process_mmap2, | ||
748 | }, | ||
722 | }; | 749 | }; |
723 | 750 | ||
724 | #define CALLCHAIN_HELP "setup and enables call-graph (stack chain/backtrace) recording: " | 751 | #define CALLCHAIN_HELP "setup and enables call-graph (stack chain/backtrace) recording: " |