diff options
author | Jiri Olsa <jolsa@redhat.com> | 2013-09-01 06:36:13 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2013-10-09 10:24:20 -0400 |
commit | 27050f530dc4fd88dc93d85c177e000efe970d12 (patch) | |
tree | 2d73d0b265fb05f74c2dfb00a83ee0241c736097 /tools/perf | |
parent | 994a1f78b191df0c9d6caca3f3afb03e247aff26 (diff) |
perf tools: Add possibility to specify mmap size
Adding possibility to specify mmap size via -m/--mmap-pages
by appending unit size character (B/K/M/G) to the
number, like:
$ perf record -m 8K ls
$ perf record -m 2M ls
The size is rounded up appropriately to follow perf
mmap restrictions.
If no unit is specified the number provides pages as
of now, like:
$ perf record -m 8 ls
Signed-off-by: Jiri Olsa <jolsa@redhat.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1378031796-17892-3-git-send-email-jolsa@redhat.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf')
-rw-r--r-- | tools/perf/Documentation/perf-kvm.txt | 4 | ||||
-rw-r--r-- | tools/perf/Documentation/perf-record.txt | 4 | ||||
-rw-r--r-- | tools/perf/Documentation/perf-top.txt | 4 | ||||
-rw-r--r-- | tools/perf/Documentation/perf-trace.txt | 4 | ||||
-rw-r--r-- | tools/perf/util/evlist.c | 32 | ||||
-rw-r--r-- | tools/perf/util/util.c | 25 | ||||
-rw-r--r-- | tools/perf/util/util.h | 14 |
7 files changed, 77 insertions, 10 deletions
diff --git a/tools/perf/Documentation/perf-kvm.txt b/tools/perf/Documentation/perf-kvm.txt index ac84db2d2334..6a06cefe9642 100644 --- a/tools/perf/Documentation/perf-kvm.txt +++ b/tools/perf/Documentation/perf-kvm.txt | |||
@@ -109,7 +109,9 @@ STAT LIVE OPTIONS | |||
109 | 109 | ||
110 | -m:: | 110 | -m:: |
111 | --mmap-pages=:: | 111 | --mmap-pages=:: |
112 | Number of mmap data pages. Must be a power of two. | 112 | Number of mmap data pages (must be a power of two) or size |
113 | specification with appended unit character - B/K/M/G. The | ||
114 | size is rounded up to have nearest pages power of two value. | ||
113 | 115 | ||
114 | -a:: | 116 | -a:: |
115 | --all-cpus:: | 117 | --all-cpus:: |
diff --git a/tools/perf/Documentation/perf-record.txt b/tools/perf/Documentation/perf-record.txt index f732eaa6a500..f10ab63576d7 100644 --- a/tools/perf/Documentation/perf-record.txt +++ b/tools/perf/Documentation/perf-record.txt | |||
@@ -87,7 +87,9 @@ OPTIONS | |||
87 | 87 | ||
88 | -m:: | 88 | -m:: |
89 | --mmap-pages=:: | 89 | --mmap-pages=:: |
90 | Number of mmap data pages. Must be a power of two. | 90 | Number of mmap data pages (must be a power of two) or size |
91 | specification with appended unit character - B/K/M/G. The | ||
92 | size is rounded up to have nearest pages power of two value. | ||
91 | 93 | ||
92 | -g:: | 94 | -g:: |
93 | --call-graph:: | 95 | --call-graph:: |
diff --git a/tools/perf/Documentation/perf-top.txt b/tools/perf/Documentation/perf-top.txt index 6d70fbfe28a2..f65777c1f723 100644 --- a/tools/perf/Documentation/perf-top.txt +++ b/tools/perf/Documentation/perf-top.txt | |||
@@ -68,7 +68,9 @@ Default is to monitor all CPUS. | |||
68 | 68 | ||
69 | -m <pages>:: | 69 | -m <pages>:: |
70 | --mmap-pages=<pages>:: | 70 | --mmap-pages=<pages>:: |
71 | Number of mmapped data pages. | 71 | Number of mmap data pages (must be a power of two) or size |
72 | specification with appended unit character - B/K/M/G. The | ||
73 | size is rounded up to have nearest pages power of two value. | ||
72 | 74 | ||
73 | -p <pid>:: | 75 | -p <pid>:: |
74 | --pid=<pid>:: | 76 | --pid=<pid>:: |
diff --git a/tools/perf/Documentation/perf-trace.txt b/tools/perf/Documentation/perf-trace.txt index 37773854d5c4..7f70d3640edd 100644 --- a/tools/perf/Documentation/perf-trace.txt +++ b/tools/perf/Documentation/perf-trace.txt | |||
@@ -59,7 +59,9 @@ OPTIONS | |||
59 | 59 | ||
60 | -m:: | 60 | -m:: |
61 | --mmap-pages=:: | 61 | --mmap-pages=:: |
62 | Number of mmap data pages. Must be a power of two. | 62 | Number of mmap data pages (must be a power of two) or size |
63 | specification with appended unit character - B/K/M/G. The | ||
64 | size is rounded up to have nearest pages power of two value. | ||
63 | 65 | ||
64 | -C:: | 66 | -C:: |
65 | --cpu:: | 67 | --cpu:: |
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index 4283f49ca0ab..d21ab0812926 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c | |||
@@ -687,14 +687,33 @@ static size_t perf_evlist__mmap_size(unsigned long pages) | |||
687 | int perf_evlist__parse_mmap_pages(const struct option *opt, const char *str, | 687 | int perf_evlist__parse_mmap_pages(const struct option *opt, const char *str, |
688 | int unset __maybe_unused) | 688 | int unset __maybe_unused) |
689 | { | 689 | { |
690 | unsigned int pages, *mmap_pages = opt->value; | 690 | unsigned int pages, val, *mmap_pages = opt->value; |
691 | size_t size; | 691 | size_t size; |
692 | char *eptr; | 692 | static struct parse_tag tags[] = { |
693 | { .tag = 'B', .mult = 1 }, | ||
694 | { .tag = 'K', .mult = 1 << 10 }, | ||
695 | { .tag = 'M', .mult = 1 << 20 }, | ||
696 | { .tag = 'G', .mult = 1 << 30 }, | ||
697 | { .tag = 0 }, | ||
698 | }; | ||
693 | 699 | ||
694 | pages = strtoul(str, &eptr, 10); | 700 | val = parse_tag_value(str, tags); |
695 | if (*eptr != '\0') { | 701 | if (val != (unsigned int) -1) { |
696 | pr_err("failed to parse --mmap_pages/-m value\n"); | 702 | /* we got file size value */ |
697 | return -1; | 703 | pages = PERF_ALIGN(val, page_size) / page_size; |
704 | if (!is_power_of_2(pages)) { | ||
705 | pages = next_pow2(pages); | ||
706 | pr_info("rounding mmap pages size to %u (%u pages)\n", | ||
707 | pages * page_size, pages); | ||
708 | } | ||
709 | } else { | ||
710 | /* we got pages count value */ | ||
711 | char *eptr; | ||
712 | pages = strtoul(str, &eptr, 10); | ||
713 | if (*eptr != '\0') { | ||
714 | pr_err("failed to parse --mmap_pages/-m value\n"); | ||
715 | return -1; | ||
716 | } | ||
698 | } | 717 | } |
699 | 718 | ||
700 | size = perf_evlist__mmap_size(pages); | 719 | size = perf_evlist__mmap_size(pages); |
@@ -738,6 +757,7 @@ int perf_evlist__mmap(struct perf_evlist *evlist, unsigned int pages, | |||
738 | 757 | ||
739 | evlist->overwrite = overwrite; | 758 | evlist->overwrite = overwrite; |
740 | evlist->mmap_len = perf_evlist__mmap_size(pages); | 759 | evlist->mmap_len = perf_evlist__mmap_size(pages); |
760 | pr_debug("mmap size %luB\n", evlist->mmap_len); | ||
741 | mask = evlist->mmap_len - page_size - 1; | 761 | mask = evlist->mmap_len - page_size - 1; |
742 | 762 | ||
743 | list_for_each_entry(evsel, &evlist->entries, node) { | 763 | list_for_each_entry(evsel, &evlist->entries, node) { |
diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c index ccfdeb62f576..ab71d6216803 100644 --- a/tools/perf/util/util.c +++ b/tools/perf/util/util.c | |||
@@ -361,3 +361,28 @@ int parse_nsec_time(const char *str, u64 *ptime) | |||
361 | *ptime = time_sec * NSEC_PER_SEC + time_nsec; | 361 | *ptime = time_sec * NSEC_PER_SEC + time_nsec; |
362 | return 0; | 362 | return 0; |
363 | } | 363 | } |
364 | |||
365 | unsigned long parse_tag_value(const char *str, struct parse_tag *tags) | ||
366 | { | ||
367 | struct parse_tag *i = tags; | ||
368 | |||
369 | while (i->tag) { | ||
370 | char *s; | ||
371 | |||
372 | s = strchr(str, i->tag); | ||
373 | if (s) { | ||
374 | unsigned long int value; | ||
375 | char *endptr; | ||
376 | |||
377 | value = strtoul(str, &endptr, 10); | ||
378 | if (s != endptr) | ||
379 | break; | ||
380 | |||
381 | value *= i->mult; | ||
382 | return value; | ||
383 | } | ||
384 | i++; | ||
385 | } | ||
386 | |||
387 | return (unsigned long) -1; | ||
388 | } | ||
diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h index a53535949043..c29ecaabf461 100644 --- a/tools/perf/util/util.h +++ b/tools/perf/util/util.h | |||
@@ -270,6 +270,13 @@ bool is_power_of_2(unsigned long n) | |||
270 | return (n != 0 && ((n & (n - 1)) == 0)); | 270 | return (n != 0 && ((n & (n - 1)) == 0)); |
271 | } | 271 | } |
272 | 272 | ||
273 | static inline unsigned next_pow2(unsigned x) | ||
274 | { | ||
275 | if (!x) | ||
276 | return 1; | ||
277 | return 1ULL << (32 - __builtin_clz(x - 1)); | ||
278 | } | ||
279 | |||
273 | size_t hex_width(u64 v); | 280 | size_t hex_width(u64 v); |
274 | int hex2u64(const char *ptr, u64 *val); | 281 | int hex2u64(const char *ptr, u64 *val); |
275 | 282 | ||
@@ -281,4 +288,11 @@ void dump_stack(void); | |||
281 | extern unsigned int page_size; | 288 | extern unsigned int page_size; |
282 | 289 | ||
283 | void get_term_dimensions(struct winsize *ws); | 290 | void get_term_dimensions(struct winsize *ws); |
291 | |||
292 | struct parse_tag { | ||
293 | char tag; | ||
294 | int mult; | ||
295 | }; | ||
296 | |||
297 | unsigned long parse_tag_value(const char *str, struct parse_tag *tags); | ||
284 | #endif /* GIT_COMPAT_UTIL_H */ | 298 | #endif /* GIT_COMPAT_UTIL_H */ |