]> Pileus Git - ~andy/linux/commitdiff
perf tools: Add possibility to specify mmap size
authorJiri Olsa <jolsa@redhat.com>
Sun, 1 Sep 2013 10:36:13 +0000 (12:36 +0200)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 9 Oct 2013 14:24:20 +0000 (11:24 -0300)
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>
tools/perf/Documentation/perf-kvm.txt
tools/perf/Documentation/perf-record.txt
tools/perf/Documentation/perf-top.txt
tools/perf/Documentation/perf-trace.txt
tools/perf/util/evlist.c
tools/perf/util/util.c
tools/perf/util/util.h

index ac84db2d23342aaa269255e34c9ab3f5d70a3e4f..6a06cefe96427453ad3b21e1caf64889f5f9ea55 100644 (file)
@@ -109,7 +109,9 @@ STAT LIVE OPTIONS
 
 -m::
 --mmap-pages=::
-    Number of mmap data pages. Must be a power of two.
+    Number of mmap data pages (must be a power of two) or size
+    specification with appended unit character - B/K/M/G. The
+    size is rounded up to have nearest pages power of two value.
 
 -a::
 --all-cpus::
index f732eaa6a500b655a9b0503378bc5de99bc21294..f10ab63576d7550dbffade473f45332be969657c 100644 (file)
@@ -87,7 +87,9 @@ OPTIONS
 
 -m::
 --mmap-pages=::
-       Number of mmap data pages. Must be a power of two.
+       Number of mmap data pages (must be a power of two) or size
+       specification with appended unit character - B/K/M/G. The
+       size is rounded up to have nearest pages power of two value.
 
 -g::
 --call-graph::
index 6d70fbfe28a2f37b6fcddd3df0e2850d8a76b2f9..f65777c1f723ba3c2226eceb9ad26f36e4fdcb88 100644 (file)
@@ -68,7 +68,9 @@ Default is to monitor all CPUS.
 
 -m <pages>::
 --mmap-pages=<pages>::
-       Number of mmapped data pages.
+       Number of mmap data pages (must be a power of two) or size
+       specification with appended unit character - B/K/M/G. The
+       size is rounded up to have nearest pages power of two value.
 
 -p <pid>::
 --pid=<pid>::
index 37773854d5c49ca7acf7e0e8ed6f4ebf2433b1b9..7f70d3640edd9f534f2f77d89fc1dbf5dfecf43b 100644 (file)
@@ -59,7 +59,9 @@ OPTIONS
 
 -m::
 --mmap-pages=::
-       Number of mmap data pages. Must be a power of two.
+       Number of mmap data pages (must be a power of two) or size
+       specification with appended unit character - B/K/M/G. The
+       size is rounded up to have nearest pages power of two value.
 
 -C::
 --cpu::
index 4283f49ca0ab9dc03b37cb2809c20d06a5678bc6..d21ab08129264c10859133e6b1da7bce444e4608 100644 (file)
@@ -687,14 +687,33 @@ static size_t perf_evlist__mmap_size(unsigned long pages)
 int perf_evlist__parse_mmap_pages(const struct option *opt, const char *str,
                                  int unset __maybe_unused)
 {
-       unsigned int pages, *mmap_pages = opt->value;
+       unsigned int pages, val, *mmap_pages = opt->value;
        size_t size;
-       char *eptr;
+       static struct parse_tag tags[] = {
+               { .tag  = 'B', .mult = 1       },
+               { .tag  = 'K', .mult = 1 << 10 },
+               { .tag  = 'M', .mult = 1 << 20 },
+               { .tag  = 'G', .mult = 1 << 30 },
+               { .tag  = 0 },
+       };
 
-       pages = strtoul(str, &eptr, 10);
-       if (*eptr != '\0') {
-               pr_err("failed to parse --mmap_pages/-m value\n");
-               return -1;
+       val = parse_tag_value(str, tags);
+       if (val != (unsigned int) -1) {
+               /* we got file size value */
+               pages = PERF_ALIGN(val, page_size) / page_size;
+               if (!is_power_of_2(pages)) {
+                       pages = next_pow2(pages);
+                       pr_info("rounding mmap pages size to %u (%u pages)\n",
+                               pages * page_size, pages);
+               }
+       } else {
+               /* we got pages count value */
+               char *eptr;
+               pages = strtoul(str, &eptr, 10);
+               if (*eptr != '\0') {
+                       pr_err("failed to parse --mmap_pages/-m value\n");
+                       return -1;
+               }
        }
 
        size = perf_evlist__mmap_size(pages);
@@ -738,6 +757,7 @@ int perf_evlist__mmap(struct perf_evlist *evlist, unsigned int pages,
 
        evlist->overwrite = overwrite;
        evlist->mmap_len = perf_evlist__mmap_size(pages);
+       pr_debug("mmap size %luB\n", evlist->mmap_len);
        mask = evlist->mmap_len - page_size - 1;
 
        list_for_each_entry(evsel, &evlist->entries, node) {
index ccfdeb62f576775d386d0a6e5c6f78255681ec1e..ab71d62168037bdc95359c0682461a5d0645fa0b 100644 (file)
@@ -361,3 +361,28 @@ int parse_nsec_time(const char *str, u64 *ptime)
        *ptime = time_sec * NSEC_PER_SEC + time_nsec;
        return 0;
 }
+
+unsigned long parse_tag_value(const char *str, struct parse_tag *tags)
+{
+       struct parse_tag *i = tags;
+
+       while (i->tag) {
+               char *s;
+
+               s = strchr(str, i->tag);
+               if (s) {
+                       unsigned long int value;
+                       char *endptr;
+
+                       value = strtoul(str, &endptr, 10);
+                       if (s != endptr)
+                               break;
+
+                       value *= i->mult;
+                       return value;
+               }
+               i++;
+       }
+
+       return (unsigned long) -1;
+}
index a53535949043f32654a181c3728a421c52baf276..c29ecaabf4610ace8ac1d5fa90f8060b4b4488dd 100644 (file)
@@ -270,6 +270,13 @@ bool is_power_of_2(unsigned long n)
        return (n != 0 && ((n & (n - 1)) == 0));
 }
 
+static inline unsigned next_pow2(unsigned x)
+{
+       if (!x)
+               return 1;
+       return 1ULL << (32 - __builtin_clz(x - 1));
+}
+
 size_t hex_width(u64 v);
 int hex2u64(const char *ptr, u64 *val);
 
@@ -281,4 +288,11 @@ void dump_stack(void);
 extern unsigned int page_size;
 
 void get_term_dimensions(struct winsize *ws);
+
+struct parse_tag {
+       char tag;
+       int mult;
+};
+
+unsigned long parse_tag_value(const char *str, struct parse_tag *tags);
 #endif /* GIT_COMPAT_UTIL_H */