2011-01-12 05:56:53 +07:00
|
|
|
#ifndef __PERF_EVLIST_H
|
|
|
|
#define __PERF_EVLIST_H 1
|
|
|
|
|
|
|
|
#include <linux/list.h>
|
2014-09-04 04:02:59 +07:00
|
|
|
#include <api/fd/array.h>
|
2011-11-04 18:10:59 +07:00
|
|
|
#include <stdio.h>
|
2011-01-13 07:39:13 +07:00
|
|
|
#include "../perf.h"
|
2011-01-15 19:40:59 +07:00
|
|
|
#include "event.h"
|
2012-08-15 02:42:15 +07:00
|
|
|
#include "evsel.h"
|
2011-11-04 18:10:59 +07:00
|
|
|
#include "util.h"
|
2011-11-09 17:47:15 +07:00
|
|
|
#include <unistd.h>
|
2011-01-12 05:56:53 +07:00
|
|
|
|
2011-01-12 07:30:02 +07:00
|
|
|
struct pollfd;
|
2011-01-30 19:46:46 +07:00
|
|
|
struct thread_map;
|
|
|
|
struct cpu_map;
|
2013-12-20 00:43:45 +07:00
|
|
|
struct record_opts;
|
2011-01-12 07:30:02 +07:00
|
|
|
|
2011-01-13 07:39:13 +07:00
|
|
|
#define PERF_EVLIST__HLIST_BITS 8
|
|
|
|
#define PERF_EVLIST__HLIST_SIZE (1 << PERF_EVLIST__HLIST_BITS)
|
|
|
|
|
2014-09-08 23:26:35 +07:00
|
|
|
/**
|
|
|
|
* struct perf_mmap - perf's ring buffer mmap details
|
|
|
|
*
|
|
|
|
* @refcnt - e.g. code using PERF_EVENT_IOC_SET_OUTPUT to share this
|
|
|
|
*/
|
2013-02-06 04:12:42 +07:00
|
|
|
struct perf_mmap {
|
|
|
|
void *base;
|
|
|
|
int mask;
|
2014-09-08 23:26:35 +07:00
|
|
|
int refcnt;
|
2013-02-06 04:12:42 +07:00
|
|
|
unsigned int prev;
|
2013-10-02 20:46:39 +07:00
|
|
|
char event_copy[PERF_SAMPLE_MAX_SIZE];
|
2013-02-06 04:12:42 +07:00
|
|
|
};
|
|
|
|
|
2011-01-12 05:56:53 +07:00
|
|
|
struct perf_evlist {
|
|
|
|
struct list_head entries;
|
2011-01-13 07:39:13 +07:00
|
|
|
struct hlist_head heads[PERF_EVLIST__HLIST_SIZE];
|
2011-01-12 05:56:53 +07:00
|
|
|
int nr_entries;
|
2013-01-22 16:09:29 +07:00
|
|
|
int nr_groups;
|
perf evlist: Fix per thread mmap setup
The PERF_EVENT_IOC_SET_OUTPUT ioctl was returning -EINVAL when using
--pid when monitoring multithreaded apps, as we can only share a ring
buffer for events on the same thread if not doing per cpu.
Fix it by using per thread ring buffers.
Tested with:
[root@felicio ~]# tuna -t 26131 -CP | nl
1 thread ctxt_switches
2 pid SCHED_ rtpri affinity voluntary nonvoluntary cmd
3 26131 OTHER 0 0,1 10814276 2397830 chromium-browse
4 642 OTHER 0 0,1 14688 0 chromium-browse
5 26148 OTHER 0 0,1 713602 115479 chromium-browse
6 26149 OTHER 0 0,1 801958 2262 chromium-browse
7 26150 OTHER 0 0,1 1271128 248 chromium-browse
8 26151 OTHER 0 0,1 3 0 chromium-browse
9 27049 OTHER 0 0,1 36796 9 chromium-browse
10 618 OTHER 0 0,1 14711 0 chromium-browse
11 661 OTHER 0 0,1 14593 0 chromium-browse
12 29048 OTHER 0 0,1 28125 0 chromium-browse
13 26143 OTHER 0 0,1 2202789 781 chromium-browse
[root@felicio ~]#
So 11 threads under pid 26131, then:
[root@felicio ~]# perf record -F 50000 --pid 26131
[root@felicio ~]# grep perf_event /proc/`pidof perf`/maps | nl
1 7fa4a2538000-7fa4a25b9000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
2 7fa4a25b9000-7fa4a263a000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
3 7fa4a263a000-7fa4a26bb000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
4 7fa4a26bb000-7fa4a273c000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
5 7fa4a273c000-7fa4a27bd000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
6 7fa4a27bd000-7fa4a283e000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
7 7fa4a283e000-7fa4a28bf000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
8 7fa4a28bf000-7fa4a2940000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
9 7fa4a2940000-7fa4a29c1000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
10 7fa4a29c1000-7fa4a2a42000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
11 7fa4a2a42000-7fa4a2ac3000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
[root@felicio ~]#
11 mmaps, one per thread since we didn't specify any CPU list, so we need one
mmap per thread and:
[root@felicio ~]# perf record -F 50000 --pid 26131
^M
^C[ perf record: Woken up 79 times to write data ]
[ perf record: Captured and wrote 20.614 MB perf.data (~900639 samples) ]
[root@felicio ~]# perf report -D | grep PERF_RECORD_SAMPLE | cut -d/ -f2 | cut -d: -f1 | sort -n | uniq -c | sort -nr | nl
1 371310 26131
2 96516 26148
3 95694 26149
4 95203 26150
5 7291 26143
6 87 27049
7 76 661
8 60 29048
9 47 618
10 43 642
[root@felicio ~]#
Ok, one of the threads, 26151 was quiescent, so no samples there, but all the
others are there.
Then, if I specify one CPU:
[root@felicio ~]# perf record -F 50000 --pid 26131 --cpu 1
^C[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.680 MB perf.data (~29730 samples) ]
[root@felicio ~]# perf report -D | grep PERF_RECORD_SAMPLE | cut -d/ -f2 | cut -d: -f1 | sort -n | uniq -c | sort -nr | nl
1 8444 26131
2 2584 26149
3 2518 26148
4 2324 26150
5 123 26143
6 9 661
7 9 29048
[root@felicio ~]#
This machine has two cores, so fewer threads appeared on the radar, and:
[root@felicio ~]# grep perf_event /proc/`pidof perf`/maps | nl
1 7f484b922000-7f484b9a3000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
[root@felicio ~]#
Just one mmap, as now we can use just one per-cpu buffer instead of the
per-thread needed in the previous case.
For global profiling:
[root@felicio ~]# perf record -F 50000 -a
^C[ perf record: Woken up 26 times to write data ]
[ perf record: Captured and wrote 7.128 MB perf.data (~311412 samples) ]
[root@felicio ~]# grep perf_event /proc/`pidof perf`/maps | nl
1 7fb49b435000-7fb49b4b6000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
2 7fb49b4b6000-7fb49b537000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
[root@felicio ~]#
It uses per-cpu buffers.
For just one thread:
[root@felicio ~]# perf record -F 50000 --tid 26148
^C[ perf record: Woken up 2 times to write data ]
[ perf record: Captured and wrote 0.330 MB perf.data (~14426 samples) ]
[root@felicio ~]# perf report -D | grep PERF_RECORD_SAMPLE | cut -d/ -f2 | cut -d: -f1 | sort -n | uniq -c | sort -nr | nl
1 9969 26148
[root@felicio ~]#
[root@felicio ~]# grep perf_event /proc/`pidof perf`/maps | nl
1 7f286a51b000-7f286a59c000 rwxs 00000000 00:09 4064 anon_inode:[perf_event]
[root@felicio ~]#
Tested-by: David Ahern <dsahern@gmail.com>
Tested-by: Lin Ming <ming.m.lin@intel.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Tom Zanussi <tzanussi@gmail.com>
Link: http://lkml.kernel.org/r/20110426204401.GB1746@ghostprotocols.net
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2011-05-15 19:39:00 +07:00
|
|
|
int nr_mmaps;
|
2013-09-01 17:36:12 +07:00
|
|
|
size_t mmap_len;
|
2013-08-27 15:23:09 +07:00
|
|
|
int id_pos;
|
|
|
|
int is_pos;
|
|
|
|
u64 combined_sample_type;
|
2011-11-09 17:47:15 +07:00
|
|
|
struct {
|
|
|
|
int cork_fd;
|
|
|
|
pid_t pid;
|
|
|
|
} workload;
|
2011-01-29 18:08:13 +07:00
|
|
|
bool overwrite;
|
2014-09-04 04:02:59 +07:00
|
|
|
struct fdarray pollfd;
|
2011-01-13 07:39:13 +07:00
|
|
|
struct perf_mmap *mmap;
|
2011-01-30 20:59:43 +07:00
|
|
|
struct thread_map *threads;
|
|
|
|
struct cpu_map *cpus;
|
2011-10-06 05:11:32 +07:00
|
|
|
struct perf_evsel *selected;
|
2015-02-15 00:50:11 +07:00
|
|
|
struct events_stats stats;
|
2011-01-12 05:56:53 +07:00
|
|
|
};
|
|
|
|
|
perf tools: Save some loops using perf_evlist__id2evsel
Since we already ask for PERF_SAMPLE_ID and use it to quickly find the
associated evsel, add handler func + data to struct perf_evsel to avoid
using chains of if(strcmp(event_name)) and also to avoid all the linear
list searches via trace_event_find.
To demonstrate the technique convert 'perf sched' to it:
# perf sched record sleep 5m
And then:
Performance counter stats for '/tmp/oldperf sched lat':
646.929438 task-clock # 0.999 CPUs utilized
9 context-switches # 0.000 M/sec
0 CPU-migrations # 0.000 M/sec
20,901 page-faults # 0.032 M/sec
1,290,144,450 cycles # 1.994 GHz
<not supported> stalled-cycles-frontend
<not supported> stalled-cycles-backend
1,606,158,439 instructions # 1.24 insns per cycle
339,088,395 branches # 524.151 M/sec
4,550,735 branch-misses # 1.34% of all branches
0.647524759 seconds time elapsed
Versus:
Performance counter stats for 'perf sched lat':
473.564691 task-clock # 0.999 CPUs utilized
9 context-switches # 0.000 M/sec
0 CPU-migrations # 0.000 M/sec
20,903 page-faults # 0.044 M/sec
944,367,984 cycles # 1.994 GHz
<not supported> stalled-cycles-frontend
<not supported> stalled-cycles-backend
1,442,385,571 instructions # 1.53 insns per cycle
308,383,106 branches # 651.195 M/sec
4,481,784 branch-misses # 1.45% of all branches
0.474215751 seconds time elapsed
[root@emilia ~]#
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
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-1kbzpl74lwi6lavpqke2u2p3@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2011-11-29 02:57:40 +07:00
|
|
|
struct perf_evsel_str_handler {
|
|
|
|
const char *name;
|
|
|
|
void *handler;
|
|
|
|
};
|
|
|
|
|
2013-03-11 14:43:12 +07:00
|
|
|
struct perf_evlist *perf_evlist__new(void);
|
2013-09-01 17:36:14 +07:00
|
|
|
struct perf_evlist *perf_evlist__new_default(void);
|
2011-01-30 20:59:43 +07:00
|
|
|
void perf_evlist__init(struct perf_evlist *evlist, struct cpu_map *cpus,
|
|
|
|
struct thread_map *threads);
|
2011-01-19 06:41:45 +07:00
|
|
|
void perf_evlist__exit(struct perf_evlist *evlist);
|
2011-01-12 05:56:53 +07:00
|
|
|
void perf_evlist__delete(struct perf_evlist *evlist);
|
|
|
|
|
|
|
|
void perf_evlist__add(struct perf_evlist *evlist, struct perf_evsel *entry);
|
|
|
|
int perf_evlist__add_default(struct perf_evlist *evlist);
|
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 23:53:54 +07:00
|
|
|
int __perf_evlist__add_default_attrs(struct perf_evlist *evlist,
|
|
|
|
struct perf_event_attr *attrs, size_t nr_attrs);
|
2012-10-03 21:50:55 +07:00
|
|
|
|
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 23:53:54 +07:00
|
|
|
#define perf_evlist__add_default_attrs(evlist, array) \
|
|
|
|
__perf_evlist__add_default_attrs(evlist, array, ARRAY_SIZE(array))
|
2011-01-12 05:56:53 +07:00
|
|
|
|
2012-10-03 21:40:22 +07:00
|
|
|
int perf_evlist__add_newtp(struct perf_evlist *evlist,
|
|
|
|
const char *sys, const char *name, void *handler);
|
|
|
|
|
2012-09-27 01:07:39 +07:00
|
|
|
int perf_evlist__set_filter(struct perf_evlist *evlist, const char *filter);
|
2015-02-22 01:09:55 +07:00
|
|
|
int perf_evlist__set_filter_pid(struct perf_evlist *evlist, pid_t pid);
|
2015-02-22 02:33:47 +07:00
|
|
|
int perf_evlist__set_filter_pids(struct perf_evlist *evlist, size_t npids, pid_t *pids);
|
2012-09-27 01:07:39 +07:00
|
|
|
|
2012-06-27 23:08:42 +07:00
|
|
|
struct perf_evsel *
|
|
|
|
perf_evlist__find_tracepoint_by_id(struct perf_evlist *evlist, int id);
|
|
|
|
|
2013-08-29 11:29:51 +07:00
|
|
|
struct perf_evsel *
|
|
|
|
perf_evlist__find_tracepoint_by_name(struct perf_evlist *evlist,
|
|
|
|
const char *name);
|
|
|
|
|
2011-03-10 21:15:54 +07:00
|
|
|
void perf_evlist__id_add(struct perf_evlist *evlist, struct perf_evsel *evsel,
|
|
|
|
int cpu, int thread, u64 id);
|
2011-03-05 08:29:39 +07:00
|
|
|
|
2014-08-19 02:44:06 +07:00
|
|
|
int perf_evlist__add_pollfd(struct perf_evlist *evlist, int fd);
|
|
|
|
int perf_evlist__alloc_pollfd(struct perf_evlist *evlist);
|
2014-08-13 09:04:11 +07:00
|
|
|
int perf_evlist__filter_pollfd(struct perf_evlist *evlist, short revents_and_mask);
|
|
|
|
|
2014-08-19 03:25:59 +07:00
|
|
|
int perf_evlist__poll(struct perf_evlist *evlist, int timeout);
|
|
|
|
|
2011-01-13 07:39:13 +07:00
|
|
|
struct perf_evsel *perf_evlist__id2evsel(struct perf_evlist *evlist, u64 id);
|
|
|
|
|
2012-10-11 19:10:35 +07:00
|
|
|
struct perf_sample_id *perf_evlist__id2sid(struct perf_evlist *evlist, u64 id);
|
|
|
|
|
2013-11-06 01:32:36 +07:00
|
|
|
union perf_event *perf_evlist__mmap_read(struct perf_evlist *evlist, int idx);
|
2011-01-15 19:40:59 +07:00
|
|
|
|
2013-10-24 14:43:33 +07:00
|
|
|
void perf_evlist__mmap_consume(struct perf_evlist *evlist, int idx);
|
|
|
|
|
perf tools: Enable grouping logic for parsed events
This patch adds a functionality that allows to create event groups
based on the way they are specified on the command line. Adding
functionality to the '{}' group syntax introduced in earlier patch.
The current '--group/-g' option behaviour remains intact. If you
specify it for record/stat/top command, all the specified events
become members of a single group with the first event as a group
leader.
With the new '{}' group syntax you can create group like:
# perf record -e '{cycles,faults}' ls
resulting in single event group containing 'cycles' and 'faults'
events, with cycles event as group leader.
All groups are created with regards to threads and cpus. Thus
recording an event group within a 2 threads on server with
4 CPUs will create 8 separate groups.
Examples (first event in brackets is group leader):
# 1 group (cpu-clock,task-clock)
perf record --group -e cpu-clock,task-clock ls
perf record -e '{cpu-clock,task-clock}' ls
# 2 groups (cpu-clock,task-clock) (minor-faults,major-faults)
perf record -e '{cpu-clock,task-clock},{minor-faults,major-faults}' ls
# 1 group (cpu-clock,task-clock,minor-faults,major-faults)
perf record --group -e cpu-clock,task-clock -e minor-faults,major-faults ls
perf record -e '{cpu-clock,task-clock,minor-faults,major-faults}' ls
# 2 groups (cpu-clock,task-clock) (minor-faults,major-faults)
perf record -e '{cpu-clock,task-clock} -e '{minor-faults,major-faults}' \
-e instructions ls
# 1 group
# (cpu-clock,task-clock,minor-faults,major-faults,instructions)
perf record --group -e cpu-clock,task-clock \
-e minor-faults,major-faults -e instructions ls perf record -e
'{cpu-clock,task-clock,minor-faults,major-faults,instructions}' ls
It's possible to use standard event modifier for a group, which spans
over all events in the group and updates each event modifier settings,
for example:
# perf record -r '{faults:k,cache-references}:p'
resulting in ':kp' modifier being used for 'faults' and ':p' modifier
being used for 'cache-references' event.
Reviewed-by: Namhyung Kim <namhyung@kernel.org>
Signed-off-by: Jiri Olsa <jolsa@redhat.com>
Acked-by: Peter Zijlstra <peterz@infradead.org>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
Cc: Corey Ashford <cjashfor@linux.vnet.ibm.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>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ulrich Drepper <drepper@gmail.com>
Link: http://lkml.kernel.org/n/tip-ho42u0wcr8mn1otkalqi13qp@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2012-08-08 17:22:36 +07:00
|
|
|
int perf_evlist__open(struct perf_evlist *evlist);
|
2013-03-15 12:48:48 +07:00
|
|
|
void perf_evlist__close(struct perf_evlist *evlist);
|
2011-10-25 19:42:19 +07:00
|
|
|
|
2013-08-27 15:23:09 +07:00
|
|
|
void perf_evlist__set_id_pos(struct perf_evlist *evlist);
|
|
|
|
bool perf_can_sample_identifier(void);
|
2013-12-20 00:43:45 +07:00
|
|
|
void perf_evlist__config(struct perf_evlist *evlist, struct record_opts *opts);
|
|
|
|
int record_opts__config(struct record_opts *opts);
|
2011-11-08 23:41:57 +07:00
|
|
|
|
2011-11-09 17:47:15 +07:00
|
|
|
int perf_evlist__prepare_workload(struct perf_evlist *evlist,
|
2013-11-13 02:46:16 +07:00
|
|
|
struct target *target,
|
2013-03-11 14:43:17 +07:00
|
|
|
const char *argv[], bool pipe_output,
|
2014-01-04 00:56:49 +07:00
|
|
|
void (*exec_error)(int signo, siginfo_t *info,
|
|
|
|
void *ucontext));
|
2011-11-09 17:47:15 +07:00
|
|
|
int perf_evlist__start_workload(struct perf_evlist *evlist);
|
|
|
|
|
2014-10-17 22:16:00 +07:00
|
|
|
struct option;
|
|
|
|
|
2013-09-01 17:36:12 +07:00
|
|
|
int perf_evlist__parse_mmap_pages(const struct option *opt,
|
|
|
|
const char *str,
|
|
|
|
int unset);
|
|
|
|
|
2011-11-09 18:10:47 +07:00
|
|
|
int perf_evlist__mmap(struct perf_evlist *evlist, unsigned int pages,
|
|
|
|
bool overwrite);
|
2011-01-30 20:59:43 +07:00
|
|
|
void perf_evlist__munmap(struct perf_evlist *evlist);
|
|
|
|
|
2011-07-25 21:06:19 +07:00
|
|
|
void perf_evlist__disable(struct perf_evlist *evlist);
|
2011-08-25 23:17:55 +07:00
|
|
|
void perf_evlist__enable(struct perf_evlist *evlist);
|
2011-07-25 21:06:19 +07:00
|
|
|
|
2013-09-01 01:50:53 +07:00
|
|
|
int perf_evlist__disable_event(struct perf_evlist *evlist,
|
|
|
|
struct perf_evsel *evsel);
|
|
|
|
int perf_evlist__enable_event(struct perf_evlist *evlist,
|
|
|
|
struct perf_evsel *evsel);
|
2014-07-31 13:00:56 +07:00
|
|
|
int perf_evlist__enable_event_idx(struct perf_evlist *evlist,
|
|
|
|
struct perf_evsel *evsel, int idx);
|
2013-09-01 01:50:53 +07:00
|
|
|
|
2011-10-06 05:11:32 +07:00
|
|
|
void perf_evlist__set_selected(struct perf_evlist *evlist,
|
|
|
|
struct perf_evsel *evsel);
|
|
|
|
|
2011-01-30 20:59:43 +07:00
|
|
|
static inline void perf_evlist__set_maps(struct perf_evlist *evlist,
|
|
|
|
struct cpu_map *cpus,
|
|
|
|
struct thread_map *threads)
|
|
|
|
{
|
|
|
|
evlist->cpus = cpus;
|
|
|
|
evlist->threads = threads;
|
|
|
|
}
|
|
|
|
|
2013-11-13 02:46:16 +07:00
|
|
|
int perf_evlist__create_maps(struct perf_evlist *evlist, struct target *target);
|
2012-09-27 00:43:13 +07:00
|
|
|
int perf_evlist__apply_filters(struct perf_evlist *evlist);
|
2011-01-30 19:46:46 +07:00
|
|
|
|
2012-08-15 02:35:48 +07:00
|
|
|
void __perf_evlist__set_leader(struct list_head *list);
|
|
|
|
void perf_evlist__set_leader(struct perf_evlist *evlist);
|
|
|
|
|
2012-10-10 22:38:13 +07:00
|
|
|
u64 perf_evlist__read_format(struct perf_evlist *evlist);
|
2013-08-27 15:23:09 +07:00
|
|
|
u64 __perf_evlist__combined_sample_type(struct perf_evlist *evlist);
|
|
|
|
u64 perf_evlist__combined_sample_type(struct perf_evlist *evlist);
|
2012-08-15 02:42:15 +07:00
|
|
|
bool perf_evlist__sample_id_all(struct perf_evlist *evlist);
|
|
|
|
u16 perf_evlist__id_hdr_size(struct perf_evlist *evlist);
|
2011-05-21 22:49:00 +07:00
|
|
|
|
2012-08-02 22:23:46 +07:00
|
|
|
int perf_evlist__parse_sample(struct perf_evlist *evlist, union perf_event *event,
|
2012-09-26 22:48:18 +07:00
|
|
|
struct perf_sample *sample);
|
2012-08-02 21:42:57 +07:00
|
|
|
|
2012-08-15 02:42:15 +07:00
|
|
|
bool perf_evlist__valid_sample_type(struct perf_evlist *evlist);
|
|
|
|
bool perf_evlist__valid_sample_id_all(struct perf_evlist *evlist);
|
2012-10-10 22:38:13 +07:00
|
|
|
bool perf_evlist__valid_read_format(struct perf_evlist *evlist);
|
2012-01-27 21:34:20 +07:00
|
|
|
|
|
|
|
void perf_evlist__splice_list_tail(struct perf_evlist *evlist,
|
|
|
|
struct list_head *list,
|
|
|
|
int nr_entries);
|
2012-08-15 02:42:15 +07:00
|
|
|
|
|
|
|
static inline struct perf_evsel *perf_evlist__first(struct perf_evlist *evlist)
|
|
|
|
{
|
|
|
|
return list_entry(evlist->entries.next, struct perf_evsel, node);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline struct perf_evsel *perf_evlist__last(struct perf_evlist *evlist)
|
|
|
|
{
|
|
|
|
return list_entry(evlist->entries.prev, struct perf_evsel, node);
|
|
|
|
}
|
2012-09-07 00:54:11 +07:00
|
|
|
|
|
|
|
size_t perf_evlist__fprintf(struct perf_evlist *evlist, FILE *fp);
|
2013-02-06 04:12:42 +07:00
|
|
|
|
perf trace: Improve messages related to /proc/sys/kernel/perf_event_paranoid
kernel/events/core.c has:
/*
* perf event paranoia level:
* -1 - not paranoid at all
* 0 - disallow raw tracepoint access for unpriv
* 1 - disallow cpu events for unpriv
* 2 - disallow kernel profiling for unpriv
*/
int sysctl_perf_event_paranoid __read_mostly = 1;
So, with the default being 1, a non-root user can trace his stuff:
[acme@zoo ~]$ cat /proc/sys/kernel/perf_event_paranoid
1
[acme@zoo ~]$ yes > /dev/null &
[1] 15338
[acme@zoo ~]$ trace -p 15338 | head -5
0.005 ( 0.005 ms): write(fd: 1</dev/null>, buf: 0x7fe6db765000, count: 4096 ) = 4096
0.045 ( 0.001 ms): write(fd: 1</dev/null>, buf: 0x7fe6db765000, count: 4096 ) = 4096
0.085 ( 0.001 ms): write(fd: 1</dev/null>, buf: 0x7fe6db765000, count: 4096 ) = 4096
0.125 ( 0.001 ms): write(fd: 1</dev/null>, buf: 0x7fe6db765000, count: 4096 ) = 4096
0.165 ( 0.001 ms): write(fd: 1</dev/null>, buf: 0x7fe6db765000, count: 4096 ) = 4096
[acme@zoo ~]$
[acme@zoo ~]$ trace --duration 1 sleep 1
1002.148 (1001.218 ms): nanosleep(rqtp: 0x7fff46c79250 ) = 0
[acme@zoo ~]$
[acme@zoo ~]$ trace -- usleep 1 | tail -5
0.905 ( 0.002 ms): brk( ) = 0x1c82000
0.910 ( 0.003 ms): brk(brk: 0x1ca3000 ) = 0x1ca3000
0.913 ( 0.001 ms): brk( ) = 0x1ca3000
0.990 ( 0.059 ms): nanosleep(rqtp: 0x7fffe31a3280 ) = 0
0.995 ( 0.000 ms): exit_group(
[acme@zoo ~]$
But can't do system wide tracing:
[acme@zoo ~]$ trace
Error: Operation not permitted.
Hint: Check /proc/sys/kernel/perf_event_paranoid setting.
Hint: For system wide tracing it needs to be set to -1.
Hint: The current value is 1.
[acme@zoo ~]$
[acme@zoo ~]$ trace --cpu 0
Error: Operation not permitted.
Hint: Check /proc/sys/kernel/perf_event_paranoid setting.
Hint: For system wide tracing it needs to be set to -1.
Hint: The current value is 1.
[acme@zoo ~]$
If the paranoid level is >= 2, i.e. turn this perf stuff off for !root users:
[acme@zoo ~]$ sudo sh -c 'echo 2 > /proc/sys/kernel/perf_event_paranoid'
[acme@zoo ~]$ cat /proc/sys/kernel/perf_event_paranoid
2
[acme@zoo ~]$
[acme@zoo ~]$ trace usleep 1
Error: Permission denied.
Hint: Check /proc/sys/kernel/perf_event_paranoid setting.
Hint: For your workloads it needs to be <= 1
Hint: For system wide tracing it needs to be set to -1.
Hint: The current value is 2.
[acme@zoo ~]$
[acme@zoo ~]$ trace
Error: Permission denied.
Hint: Check /proc/sys/kernel/perf_event_paranoid setting.
Hint: For your workloads it needs to be <= 1
Hint: For system wide tracing it needs to be set to -1.
Hint: The current value is 2.
[acme@zoo ~]$
[acme@zoo ~]$ trace --cpu 1
Error: Permission denied.
Hint: Check /proc/sys/kernel/perf_event_paranoid setting.
Hint: For your workloads it needs to be <= 1
Hint: For system wide tracing it needs to be set to -1.
Hint: The current value is 2.
[acme@zoo ~]$
If the user manages to get what he/she wants, convincing root not
to be paranoid at all...
[root@zoo ~]# echo -1 > /proc/sys/kernel/perf_event_paranoid
[root@zoo ~]# cat /proc/sys/kernel/perf_event_paranoid
-1
[root@zoo ~]#
[acme@zoo ~]$ ps -eo user,pid,comm | grep Xorg
root 729 Xorg
[acme@zoo ~]$
[acme@zoo ~]$ trace -a --duration 0.001 -e \!select,ioctl,writev | grep Xorg | head -5
23.143 ( 0.003 ms): Xorg/729 setitimer(which: REAL, value: 0x7fffaadf16e0 ) = 0
23.152 ( 0.004 ms): Xorg/729 read(fd: 31, buf: 0x2544af0, count: 4096 ) = 8
23.161 ( 0.002 ms): Xorg/729 read(fd: 31, buf: 0x2544af0, count: 4096 ) = -1 EAGAIN Resource temporarily unavailable
23.175 ( 0.002 ms): Xorg/729 setitimer(which: REAL, value: 0x7fffaadf16e0 ) = 0
23.235 ( 0.002 ms): Xorg/729 setitimer(which: REAL, value: 0x7fffaadf16e0 ) = 0
[acme@zoo ~]$
Cc: Adrian Hunter <adrian.hunter@intel.com>
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: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-di28olfwd28rvkox7v3hqhu1@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2013-10-18 03:38:29 +07:00
|
|
|
int perf_evlist__strerror_open(struct perf_evlist *evlist, int err, char *buf, size_t size);
|
2014-12-12 04:03:01 +07:00
|
|
|
int perf_evlist__strerror_mmap(struct perf_evlist *evlist, int err, char *buf, size_t size);
|
2013-10-17 22:07:58 +07:00
|
|
|
|
2013-02-06 04:12:42 +07:00
|
|
|
static inline unsigned int perf_mmap__read_head(struct perf_mmap *mm)
|
|
|
|
{
|
|
|
|
struct perf_event_mmap_page *pc = mm->base;
|
2013-10-30 17:42:46 +07:00
|
|
|
int head = ACCESS_ONCE(pc->data_head);
|
2013-02-06 04:12:42 +07:00
|
|
|
rmb();
|
|
|
|
return head;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void perf_mmap__write_tail(struct perf_mmap *md,
|
|
|
|
unsigned long tail)
|
|
|
|
{
|
|
|
|
struct perf_event_mmap_page *pc = md->base;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ensure all reads are done before we write the tail out.
|
|
|
|
*/
|
2013-10-30 17:42:46 +07:00
|
|
|
mb();
|
2013-02-06 04:12:42 +07:00
|
|
|
pc->data_tail = tail;
|
|
|
|
}
|
|
|
|
|
2013-12-11 19:36:29 +07:00
|
|
|
bool perf_evlist__can_select_event(struct perf_evlist *evlist, const char *str);
|
2013-12-11 19:36:35 +07:00
|
|
|
void perf_evlist__to_front(struct perf_evlist *evlist,
|
|
|
|
struct perf_evsel *move_evsel);
|
|
|
|
|
2014-01-10 20:37:27 +07:00
|
|
|
/**
|
|
|
|
* __evlist__for_each - iterate thru all the evsels
|
|
|
|
* @list: list_head instance to iterate
|
|
|
|
* @evsel: struct evsel iterator
|
|
|
|
*/
|
|
|
|
#define __evlist__for_each(list, evsel) \
|
|
|
|
list_for_each_entry(evsel, list, node)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* evlist__for_each - iterate thru all the evsels
|
|
|
|
* @evlist: evlist instance to iterate
|
|
|
|
* @evsel: struct evsel iterator
|
|
|
|
*/
|
|
|
|
#define evlist__for_each(evlist, evsel) \
|
|
|
|
__evlist__for_each(&(evlist)->entries, evsel)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* __evlist__for_each_continue - continue iteration thru all the evsels
|
|
|
|
* @list: list_head instance to iterate
|
|
|
|
* @evsel: struct evsel iterator
|
|
|
|
*/
|
|
|
|
#define __evlist__for_each_continue(list, evsel) \
|
|
|
|
list_for_each_entry_continue(evsel, list, node)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* evlist__for_each_continue - continue iteration thru all the evsels
|
|
|
|
* @evlist: evlist instance to iterate
|
|
|
|
* @evsel: struct evsel iterator
|
|
|
|
*/
|
|
|
|
#define evlist__for_each_continue(evlist, evsel) \
|
|
|
|
__evlist__for_each_continue(&(evlist)->entries, evsel)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* __evlist__for_each_reverse - iterate thru all the evsels in reverse order
|
|
|
|
* @list: list_head instance to iterate
|
|
|
|
* @evsel: struct evsel iterator
|
|
|
|
*/
|
|
|
|
#define __evlist__for_each_reverse(list, evsel) \
|
|
|
|
list_for_each_entry_reverse(evsel, list, node)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* evlist__for_each_reverse - iterate thru all the evsels in reverse order
|
|
|
|
* @evlist: evlist instance to iterate
|
|
|
|
* @evsel: struct evsel iterator
|
|
|
|
*/
|
|
|
|
#define evlist__for_each_reverse(evlist, evsel) \
|
|
|
|
__evlist__for_each_reverse(&(evlist)->entries, evsel)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* __evlist__for_each_safe - safely iterate thru all the evsels
|
|
|
|
* @list: list_head instance to iterate
|
|
|
|
* @tmp: struct evsel temp iterator
|
|
|
|
* @evsel: struct evsel iterator
|
|
|
|
*/
|
|
|
|
#define __evlist__for_each_safe(list, tmp, evsel) \
|
|
|
|
list_for_each_entry_safe(evsel, tmp, list, node)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* evlist__for_each_safe - safely iterate thru all the evsels
|
|
|
|
* @evlist: evlist instance to iterate
|
|
|
|
* @evsel: struct evsel iterator
|
|
|
|
* @tmp: struct evsel temp iterator
|
|
|
|
*/
|
|
|
|
#define evlist__for_each_safe(evlist, tmp, evsel) \
|
|
|
|
__evlist__for_each_safe(&(evlist)->entries, tmp, evsel)
|
2013-12-11 19:36:29 +07:00
|
|
|
|
2014-07-31 13:00:52 +07:00
|
|
|
void perf_evlist__set_tracking_event(struct perf_evlist *evlist,
|
|
|
|
struct perf_evsel *tracking_evsel);
|
|
|
|
|
2011-01-12 05:56:53 +07:00
|
|
|
#endif /* __PERF_EVLIST_H */
|