[RFC] perf stat: Add -U/--user option

From: Namhyung Kim
Date: Wed Apr 08 2015 - 08:56:12 EST


The -U/--user option is to control event modifier for all events easily.
It has same effect as if adding 'u' modifier to every events.

An example follows:

$ perf stat -U true

Performance counter stats for 'true':

0.722461 task-clock:uH (msec) # 0.520 CPUs utilized
0 context-switches:uH # 0.000 K/sec
0 cpu-migrations:uH # 0.000 K/sec
41 page-faults:uH # 0.057 M/sec
145,341 cycles:uH # 0.201 GHz
517,317 stalled-cycles-frontend:uH # 355.93% frontend cycles idle
497,570 stalled-cycles-backend:uH # 342.35% backend cycles idle
98,846 instructions:uH # 0.68 insns per cycle
# 5.23 stalled cycles per insn
19,552 branches:uH # 27.063 M/sec
<not counted> branch-misses:uH

0.001389613 seconds time elapsed

Cc: Andi Kleen <ak@xxxxxxxxxxxxxxx>
Signed-off-by: Namhyung Kim <namhyung@xxxxxxxxxx>
---
tools/perf/Documentation/perf-stat.txt | 5 ++++-
tools/perf/builtin-stat.c | 11 +++++++++++
2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/tools/perf/Documentation/perf-stat.txt b/tools/perf/Documentation/perf-stat.txt
index 04e150d83e7d..54b0734028a6 100644
--- a/tools/perf/Documentation/perf-stat.txt
+++ b/tools/perf/Documentation/perf-stat.txt
@@ -151,9 +151,12 @@ filter out the startup phase of the program, which is often very different.

-T::
--transaction::
-
Print statistics of transactional execution if supported.

+-U::
+--user::
+Collect events only in user mode execution
+
EXAMPLES
--------

diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index fec089f1c364..d191af942cb4 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -141,6 +141,7 @@ static unsigned int interval = 0;
static unsigned int initial_delay = 0;
static unsigned int unit_width = 4; /* strlen("unit") */
static bool forever = false;
+static bool mod_user = false;
static struct timespec ref_time;
static struct cpu_map *aggr_map;
static int (*aggr_get_id)(struct cpu_map *m, int cpu);
@@ -1809,6 +1810,7 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused)
"aggregate counts per physical processor core", AGGR_CORE),
OPT_UINTEGER('D', "delay", &initial_delay,
"ms to wait before starting measurement after program start"),
+ OPT_BOOLEAN('U', "user", &mod_user, "Count event only in user mode"),
OPT_END()
};
const char * const stat_usage[] = {
@@ -1913,6 +1915,15 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused)
if (add_default_attributes())
goto out;

+ if (mod_user) {
+ struct perf_evsel *evsel;
+
+ evlist__for_each(evsel_list, evsel) {
+ evsel->attr.exclude_kernel = 1;
+ evsel->attr.exclude_hv = 1;
+ }
+ }
+
target__validate(&target);

if (perf_evlist__create_maps(evsel_list, &target) < 0) {
--
2.3.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/