Re: [PATCH v1 0/2] perf stat: Support --all-kernel and --all-user

From: Arnaldo Carvalho de Melo
Date: Mon Sep 30 2019 - 17:21:22 EST


Em Mon, Sep 30, 2019 at 11:21:36AM -0700, Andi Kleen escreveu:
> On Sun, Sep 29, 2019 at 05:29:13PM +0200, Jiri Olsa wrote:
> > On Wed, Sep 25, 2019 at 10:02:16AM +0800, Jin Yao wrote:
> > > This patch series supports the new options "--all-kernel" and "--all-user"
> > > in perf-stat.

> > > For example,

> > > root@kbl:~# perf stat -e cycles,instructions --all-kernel --all-user -a -- sleep 1

> > > Performance counter stats for 'system wide':

> > > 19,156,665 cycles:k
> > > 7,265,342 instructions:k # 0.38 insn per cycle
> > > 4,511,186,293 cycles:u
> > > 121,881,436 instructions:u # 0.03 insn per cycle

> > I think we should follow --all-kernel/--all-user behaviour from record
> > command, adding extra events seems like unnecesary complexity to me

> I think it's useful. Makes it easy to do kernel/user break downs.
> perf record should support the same.

Don't we have this already with:

[root@quaco ~]# perf stat -e cycles:u,instructions:u,cycles:k,instructions:k -a -- sleep 1

Performance counter stats for 'system wide':

69,937,445 cycles:u
23,459,595 instructions:u # 0.34 insn per cycle
51,040,704 cycles:k
11,368,152 instructions:k # 0.22 insn per cycle

1.002887417 seconds time elapsed

[root@quaco ~]# perf record -e cycles:u,instructions:u,cycles:k,instructions:k -a -- sleep 1
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 1.340 MB perf.data (927 samples) ]
[root@quaco ~]# perf evlist
cycles:u
instructions:u
cycles:k
instructions:k
[root@quaco ~]#

To make it shorter we could have:

diff --git a/tools/perf/util/parse-events.l b/tools/perf/util/parse-events.l
index 7469497cd28e..7df28b0e9682 100644
--- a/tools/perf/util/parse-events.l
+++ b/tools/perf/util/parse-events.l
@@ -313,11 +313,11 @@ aux-output { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_AUX_OUTPUT); }
<<EOF>> { BEGIN(INITIAL); }
}

-cpu-cycles|cycles { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_CPU_CYCLES); }
+cpu-cycles|cycles|cyc { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_CPU_CYCLES); }
stalled-cycles-frontend|idle-cycles-frontend { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_STALLED_CYCLES_FRONTEND); }
stalled-cycles-backend|idle-cycles-backend { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_STALLED_CYCLES_BACKEND); }
-instructions { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_INSTRUCTIONS); }
+instructions|insn|ins { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_INSTRUCTIONS); }
cache-misses { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_CACHE_MISSES); }
branch-instructions|branches { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_BRANCH_INSTRUCTIONS); }
branch-misses { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_BRANCH_MISSES); }

And another thing that comes to mind is to make -M metrics be accepted
as -e arg, as someone suggested recently (Andi?), and also make it set
its events honouring the :k or :u modifiers:

[root@quaco ~]# perf stat -M ipc
^C
Performance counter stats for 'system wide':

15,030,011 inst_retired.any # 0.3 IPC
54,449,797 cpu_clk_unhalted.thread

1.186531715 seconds time elapsed


[root@quaco ~]# perf stat -M ipc:k,ipc:u
Cannot find metric or group `ipc:k'

Usage: perf stat [<options>] [<command>]

-M, --metrics <metric/metric group list>
monitor specified metrics or metric groups (separated by ,)
[root@quaco ~]#


- Arnaldo