linux-kernel-test/tools/perf
Arnaldo Carvalho de Melo 79695e1bb6 perf stat: Initialize default events wrt exclude_{guest,host}
When no event is specified the tools use perf_evlist__add_default(), that will
call event_attr_init to initialize the KVM exclusion bits.

When the change was made to the tools so that by default guest samples would be
excluded, the changes were made just to the parsing routines and to
perf_evlist__add_default(), not to perf_evlist__add_attrs, that is used so far
just by perf stat to add multiple events, according to the level of detail
specified.

Recently the tools were changed to reconstruct the event name from all the
details in perf_event_attr, not just from .type and .config, but taking into
account all the feature bits (.exclude_{guest,host,user,kernel,etc},
.precise_ip, etc).

That is when we noticed that the default for perf stat wasn't the one for the
rest of the tools, i.e. the .exclude_guest bit wasn't being set.

I.e. the default, that doesn't call event_attr_init was showing the :HG
modifier:

  $ perf stat usleep 1

   Performance counter stats for 'usleep 1':

            0.942119 task-clock                #    0.454 CPUs utilized
                   1 context-switches          #    0.001 M/sec
                   0 CPU-migrations            #    0.000 K/sec
                 126 page-faults               #    0.134 M/sec
             693,193 cycles:HG                 #    0.736 GHz                     [40.11%]
             407,461 stalled-cycles-frontend:HG #   58.78% frontend cycles idle    [72.29%]
             365,403 stalled-cycles-backend:HG #   52.71% backend  cycles idle
             465,982 instructions:HG           #    0.67  insns per cycle
                                               #    0.87  stalled cycles per insn
              89,760 branches:HG               #   95.275 M/sec
               6,178 branch-misses:HG          #    6.88% of all branches

         0.002077228 seconds time elapsed

While if one explicitely specifies the same events, which will make the parsing code
to be called and thus event_attr_init is called:

  $ perf stat -e task-clock,context-switches,migrations,page-faults,cycles,stalled-cycles-frontend,stalled-cycles-backend,instructions,branches,branch-misses usleep 1

   Performance counter stats for 'usleep 1':

            1.040349 task-clock                #    0.500 CPUs utilized
                   2 context-switches          #    0.002 M/sec
                   0 CPU-migrations            #    0.000 K/sec
                 127 page-faults               #    0.122 M/sec
             587,966 cycles                    #    0.565 GHz                     [13.18%]
             459,167 stalled-cycles-frontend   #   78.09% frontend cycles idle
             390,249 stalled-cycles-backend    #   66.37% backend  cycles idle
             504,006 instructions              #    0.86  insns per cycle
                                               #    0.91  stalled cycles per insn
              96,455 branches                  #   92.714 M/sec
               6,522 branch-misses             #    6.76% of all branches         [96.12%]

         0.002078681 seconds time elapsed

Fix it by introducing a perf_evlist__add_default_attrs method that will call
evlist_attr_init in all the perf_event_attr entries before adding the events.

Reported-by: Ingo Molnar <mingo@kernel.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-4eysr236r0pgiyum9epwxw7s@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2012-05-30 14:02:38 -03:00
..
arch perf tools: Use scnprintf where applicable 2012-03-14 12:36:19 -03:00
bench perf tool: Fix perf stack to non executable on x86_64 2012-02-06 19:14:17 -02:00
config perf report: Add a simple GTK2-based 'perf report' browser 2012-03-19 15:13:29 -03:00
Documentation Merge branch 'linus' into perf/urgent 2012-05-30 10:59:04 +02:00
python perf python: Use attr.watermark in twatch.py 2012-01-30 18:38:23 -02:00
scripts perf script: Add drop monitor script 2011-09-29 16:41:37 -03:00
ui perf annotate browser: Fix help window entry for navigating to hottest line 2012-05-30 12:31:44 -03:00
util perf stat: Initialize default events wrt exclude_{guest,host} 2012-05-30 14:02:38 -03:00
.gitignore perf tools: Ignore auto-generated bison/flex files 2012-04-14 13:50:39 -03:00
builtin-annotate.c perf tools: Convert critical messages to ui__error() 2012-05-29 11:53:42 -03:00
builtin-bench.c perf bench: Also allow measuring memset() 2012-01-24 20:25:32 -02:00
builtin-buildid-cache.c perf buildid: add perfconfig option to specify buildid cache dir 2010-06-05 09:34:04 -03:00
builtin-buildid-list.c perf buildid-list: Work better with pipe mode 2012-05-22 13:03:54 -03:00
builtin-diff.c perf diff: Fix to work with new hists design 2012-03-22 15:12:09 -03:00
builtin-evlist.c perf evlist: Explicititely initialize input_name 2012-05-23 21:47:51 -03:00
builtin-help.c perf options: Type check all the remaining OPT_ variants 2010-05-17 16:22:41 -03:00
builtin-inject.c perf inject: Fix broken perf inject -b 2012-05-22 12:59:28 -03:00
builtin-kmem.c perf: Have perf use the new libtraceevent.a library 2012-04-25 13:28:48 +02:00
builtin-kvm.c perf kvm: Do guest-only counting by default 2012-01-06 15:47:37 -02:00
builtin-list.c perf list: Allow filtering list of events 2011-02-17 15:38:58 -02:00
builtin-lock.c perf: Have perf use the new libtraceevent.a library 2012-04-25 13:28:48 +02:00
builtin-probe.c perf probe: Detect probe target when m/x options are absent 2012-05-11 13:58:53 -03:00
builtin-record.c perf tools: Convert critical messages to ui__error() 2012-05-29 11:53:42 -03:00
builtin-report.c perf report: Use the right symbol for annotation 2012-05-30 12:25:52 -03:00
builtin-sched.c perf: Have perf use the new libtraceevent.a library 2012-04-25 13:28:48 +02:00
builtin-script.c perf: Have perf use the new libtraceevent.a library 2012-04-25 13:28:48 +02:00
builtin-stat.c perf stat: Initialize default events wrt exclude_{guest,host} 2012-05-30 14:02:38 -03:00
builtin-test.c perf test: Move parse event automated tests to separated object 2012-05-22 11:19:16 -03:00
builtin-timechart.c perf report: Accept fifos as input file 2011-12-23 17:01:03 -02:00
builtin-top.c perf tools: Convert critical messages to ui__error() 2012-05-29 11:53:42 -03:00
builtin.h perf tools: Make perf.data more self-descriptive (v8) 2011-10-07 17:01:24 -03:00
command-list.txt perf evlist: New command to list the names of events present in a perf.data file 2011-03-15 11:10:48 -03:00
CREDITS
design.txt perf: Fix few typos + cosmetics 2010-01-13 17:39:44 +01:00
Makefile perf tools: Do not use _FORTIFY_SOURCE when DEBUG=1 is specified 2012-05-24 14:48:39 -03:00
MANIFEST perf tools: Fix out of tree compiles 2012-02-13 22:46:41 -02:00
perf-archive.sh perf archive: Correct cutting of symbolic link 2012-04-14 13:52:15 -03:00
perf.c perf tools: Simplify debugfs mountpoint handling code 2011-11-28 10:11:28 -02:00
perf.h perf record: Fix branch_stack type in perf_record_opts 2012-05-25 18:32:44 -03:00