diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2015-09-30 16:49:49 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2015-09-30 17:34:39 -0400 |
commit | 7f8d1ade1b19f684ed3a7c4fb1dc5d347127b438 (patch) | |
tree | 965af8015bcc5a9375e8858bf6aea52f5e45357c /tools | |
parent | dfc431cbdc3a3c0556f1cd462d724d107cc15a9e (diff) |
perf tools: By default use the most precise "cycles" hw counter available
If the user doesn't specify any event, try the most precise "cycles"
available, i.e. start by "cycles:ppp" and go on removing "p" till it
works.
E.g.
$ perf record usleep 1
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.017 MB perf.data (11 samples) ]
$ perf evlist
cycles:pp
$ perf evlist -v
cycles:pp: size: 112, { sample_period, sample_freq }: 4000, sample_type:
IP|TID|TIME|PERIOD, disabled: 1, inherit: 1, mmap: 1, comm: 1, freq: 1,
enable_on_exec: 1, task: 1, precise_ip: 2, sample_id_all: 1,
exclude_guest: 1, mmap2: 1, comm_exec: 1
$ grep 'model name' /proc/cpuinfo | head -1
model name : Intel(R) Core(TM) i7-3667U CPU @ 2.00GHz
$
When 'cycles' appears explicitely is specified this will not be tried,
i.e. the user has full control of the level of precision to be used:
$ perf record -e cycles usleep 1
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.016 MB perf.data (9 samples) ]
$ perf evlist
cycles
$ perf evlist -v
cycles: size: 112, { sample_period, sample_freq }: 4000, sample_type:
IP|TID|TIME|PERIOD, disabled: 1, inherit: 1, mmap: 1, comm: 1, freq: 1,
enable_on_exec: 1, task: 1, sample_id_all: 1, exclude_guest: 1, mmap2:
1, comm_exec: 1
$
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Borislav Petkov <bp@suse.de>
Cc: Chandler Carruth <chandlerc@gmail.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Wang Nan <wangnan0@huawei.com>
Link: https://www.youtube.com/watch?v=nXaxk27zwlk
Link: http://lkml.kernel.org/n/tip-b1ywebmt22pi78vjxau01wth@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/perf/util/evlist.c | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index 89546228b8ed..e7e195d867ea 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c | |||
@@ -205,6 +205,20 @@ void perf_evlist__set_leader(struct perf_evlist *evlist) | |||
205 | } | 205 | } |
206 | } | 206 | } |
207 | 207 | ||
208 | static void perf_event_attr__set_max_precise_ip(struct perf_event_attr *attr) | ||
209 | { | ||
210 | attr->precise_ip = 3; | ||
211 | |||
212 | while (attr->precise_ip != 0) { | ||
213 | int fd = sys_perf_event_open(attr, 0, -1, -1, 0); | ||
214 | if (fd != -1) { | ||
215 | close(fd); | ||
216 | break; | ||
217 | } | ||
218 | --attr->precise_ip; | ||
219 | } | ||
220 | } | ||
221 | |||
208 | int perf_evlist__add_default(struct perf_evlist *evlist) | 222 | int perf_evlist__add_default(struct perf_evlist *evlist) |
209 | { | 223 | { |
210 | struct perf_event_attr attr = { | 224 | struct perf_event_attr attr = { |
@@ -215,13 +229,15 @@ int perf_evlist__add_default(struct perf_evlist *evlist) | |||
215 | 229 | ||
216 | event_attr_init(&attr); | 230 | event_attr_init(&attr); |
217 | 231 | ||
232 | perf_event_attr__set_max_precise_ip(&attr); | ||
233 | |||
218 | evsel = perf_evsel__new(&attr); | 234 | evsel = perf_evsel__new(&attr); |
219 | if (evsel == NULL) | 235 | if (evsel == NULL) |
220 | goto error; | 236 | goto error; |
221 | 237 | ||
222 | /* use strdup() because free(evsel) assumes name is allocated */ | 238 | /* use asprintf() because free(evsel) assumes name is allocated */ |
223 | evsel->name = strdup("cycles"); | 239 | if (asprintf(&evsel->name, "cycles%.*s", |
224 | if (!evsel->name) | 240 | attr.precise_ip ? attr.precise_ip + 1 : 0, ":ppp") < 0) |
225 | goto error_free; | 241 | goto error_free; |
226 | 242 | ||
227 | perf_evlist__add(evlist, evsel); | 243 | perf_evlist__add(evlist, evsel); |