diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2011-11-08 11:41:57 -0500 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2011-11-28 07:25:31 -0500 |
commit | 0f82ebc452f921590e216b28eee0b41f5e434a48 (patch) | |
tree | 96f8f0df01f362f3184e3dbc1137809e4d0aa065 /tools/perf/util | |
parent | a8c9ae18d810e1ae12b6ec960907e9af63171d3a (diff) |
perf evsel: Introduce config attr method
Out of the code in 'perf record', so that we can share option parsing,
etc. Eventually will be used by 'perf top', but first 'trace' will use
it.
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-hzjqsgnte1esk90ytq0ap98v@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/util')
-rw-r--r-- | tools/perf/util/evlist.c | 16 | ||||
-rw-r--r-- | tools/perf/util/evlist.h | 4 | ||||
-rw-r--r-- | tools/perf/util/evsel.c | 70 | ||||
-rw-r--r-- | tools/perf/util/evsel.h | 4 |
4 files changed, 94 insertions, 0 deletions
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index 3bc5a287a9f9..b774341e797f 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c | |||
@@ -46,6 +46,22 @@ struct perf_evlist *perf_evlist__new(struct cpu_map *cpus, | |||
46 | return evlist; | 46 | return evlist; |
47 | } | 47 | } |
48 | 48 | ||
49 | void perf_evlist__config_attrs(struct perf_evlist *evlist, | ||
50 | struct perf_record_opts *opts) | ||
51 | { | ||
52 | struct perf_evsel *evsel; | ||
53 | |||
54 | if (evlist->cpus->map[0] < 0) | ||
55 | opts->no_inherit = true; | ||
56 | |||
57 | list_for_each_entry(evsel, &evlist->entries, node) { | ||
58 | perf_evsel__config(evsel, opts); | ||
59 | |||
60 | if (evlist->nr_entries > 1) | ||
61 | evsel->attr.sample_type |= PERF_SAMPLE_ID; | ||
62 | } | ||
63 | } | ||
64 | |||
49 | static void perf_evlist__purge(struct perf_evlist *evlist) | 65 | static void perf_evlist__purge(struct perf_evlist *evlist) |
50 | { | 66 | { |
51 | struct perf_evsel *pos, *n; | 67 | struct perf_evsel *pos, *n; |
diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h index ec71c82935bd..231c06f8286b 100644 --- a/tools/perf/util/evlist.h +++ b/tools/perf/util/evlist.h | |||
@@ -10,6 +10,7 @@ | |||
10 | struct pollfd; | 10 | struct pollfd; |
11 | struct thread_map; | 11 | struct thread_map; |
12 | struct cpu_map; | 12 | struct cpu_map; |
13 | struct perf_record_opts; | ||
13 | 14 | ||
14 | #define PERF_EVLIST__HLIST_BITS 8 | 15 | #define PERF_EVLIST__HLIST_BITS 8 |
15 | #define PERF_EVLIST__HLIST_SIZE (1 << PERF_EVLIST__HLIST_BITS) | 16 | #define PERF_EVLIST__HLIST_SIZE (1 << PERF_EVLIST__HLIST_BITS) |
@@ -64,6 +65,9 @@ union perf_event *perf_evlist__mmap_read(struct perf_evlist *self, int idx); | |||
64 | 65 | ||
65 | int perf_evlist__open(struct perf_evlist *evlist, bool group); | 66 | int perf_evlist__open(struct perf_evlist *evlist, bool group); |
66 | 67 | ||
68 | void perf_evlist__config_attrs(struct perf_evlist *evlist, | ||
69 | struct perf_record_opts *opts); | ||
70 | |||
67 | int perf_evlist__alloc_mmap(struct perf_evlist *evlist); | 71 | int perf_evlist__alloc_mmap(struct perf_evlist *evlist); |
68 | int perf_evlist__mmap(struct perf_evlist *evlist, int pages, bool overwrite); | 72 | int perf_evlist__mmap(struct perf_evlist *evlist, int pages, bool overwrite); |
69 | void perf_evlist__munmap(struct perf_evlist *evlist); | 73 | void perf_evlist__munmap(struct perf_evlist *evlist); |
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index e42626422587..b38eaa34b28e 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c | |||
@@ -53,6 +53,76 @@ struct perf_evsel *perf_evsel__new(struct perf_event_attr *attr, int idx) | |||
53 | return evsel; | 53 | return evsel; |
54 | } | 54 | } |
55 | 55 | ||
56 | void perf_evsel__config(struct perf_evsel *evsel, struct perf_record_opts *opts) | ||
57 | { | ||
58 | struct perf_event_attr *attr = &evsel->attr; | ||
59 | int track = !evsel->idx; /* only the first counter needs these */ | ||
60 | |||
61 | attr->sample_id_all = opts->sample_id_all_avail ? 1 : 0; | ||
62 | attr->inherit = !opts->no_inherit; | ||
63 | attr->read_format = PERF_FORMAT_TOTAL_TIME_ENABLED | | ||
64 | PERF_FORMAT_TOTAL_TIME_RUNNING | | ||
65 | PERF_FORMAT_ID; | ||
66 | |||
67 | attr->sample_type |= PERF_SAMPLE_IP | PERF_SAMPLE_TID; | ||
68 | |||
69 | /* | ||
70 | * We default some events to a 1 default interval. But keep | ||
71 | * it a weak assumption overridable by the user. | ||
72 | */ | ||
73 | if (!attr->sample_period || (opts->user_freq != UINT_MAX && | ||
74 | opts->user_interval != ULLONG_MAX)) { | ||
75 | if (opts->freq) { | ||
76 | attr->sample_type |= PERF_SAMPLE_PERIOD; | ||
77 | attr->freq = 1; | ||
78 | attr->sample_freq = opts->freq; | ||
79 | } else { | ||
80 | attr->sample_period = opts->default_interval; | ||
81 | } | ||
82 | } | ||
83 | |||
84 | if (opts->no_samples) | ||
85 | attr->sample_freq = 0; | ||
86 | |||
87 | if (opts->inherit_stat) | ||
88 | attr->inherit_stat = 1; | ||
89 | |||
90 | if (opts->sample_address) { | ||
91 | attr->sample_type |= PERF_SAMPLE_ADDR; | ||
92 | attr->mmap_data = track; | ||
93 | } | ||
94 | |||
95 | if (opts->call_graph) | ||
96 | attr->sample_type |= PERF_SAMPLE_CALLCHAIN; | ||
97 | |||
98 | if (opts->system_wide) | ||
99 | attr->sample_type |= PERF_SAMPLE_CPU; | ||
100 | |||
101 | if (opts->sample_id_all_avail && | ||
102 | (opts->sample_time || opts->system_wide || | ||
103 | !opts->no_inherit || opts->cpu_list)) | ||
104 | attr->sample_type |= PERF_SAMPLE_TIME; | ||
105 | |||
106 | if (opts->raw_samples) { | ||
107 | attr->sample_type |= PERF_SAMPLE_TIME; | ||
108 | attr->sample_type |= PERF_SAMPLE_RAW; | ||
109 | attr->sample_type |= PERF_SAMPLE_CPU; | ||
110 | } | ||
111 | |||
112 | if (opts->no_delay) { | ||
113 | attr->watermark = 0; | ||
114 | attr->wakeup_events = 1; | ||
115 | } | ||
116 | |||
117 | attr->mmap = track; | ||
118 | attr->comm = track; | ||
119 | |||
120 | if (opts->target_pid == -1 && opts->target_tid == -1 && !opts->system_wide) { | ||
121 | attr->disabled = 1; | ||
122 | attr->enable_on_exec = 1; | ||
123 | } | ||
124 | } | ||
125 | |||
56 | int perf_evsel__alloc_fd(struct perf_evsel *evsel, int ncpus, int nthreads) | 126 | int perf_evsel__alloc_fd(struct perf_evsel *evsel, int ncpus, int nthreads) |
57 | { | 127 | { |
58 | int cpu, thread; | 128 | int cpu, thread; |
diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index b1d15e6f7ae3..6421c07f5015 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h | |||
@@ -67,6 +67,7 @@ struct perf_evsel { | |||
67 | struct cpu_map; | 67 | struct cpu_map; |
68 | struct thread_map; | 68 | struct thread_map; |
69 | struct perf_evlist; | 69 | struct perf_evlist; |
70 | struct perf_record_opts; | ||
70 | 71 | ||
71 | struct perf_evsel *perf_evsel__new(struct perf_event_attr *attr, int idx); | 72 | struct perf_evsel *perf_evsel__new(struct perf_event_attr *attr, int idx); |
72 | void perf_evsel__init(struct perf_evsel *evsel, | 73 | void perf_evsel__init(struct perf_evsel *evsel, |
@@ -74,6 +75,9 @@ void perf_evsel__init(struct perf_evsel *evsel, | |||
74 | void perf_evsel__exit(struct perf_evsel *evsel); | 75 | void perf_evsel__exit(struct perf_evsel *evsel); |
75 | void perf_evsel__delete(struct perf_evsel *evsel); | 76 | void perf_evsel__delete(struct perf_evsel *evsel); |
76 | 77 | ||
78 | void perf_evsel__config(struct perf_evsel *evsel, | ||
79 | struct perf_record_opts *opts); | ||
80 | |||
77 | int perf_evsel__alloc_fd(struct perf_evsel *evsel, int ncpus, int nthreads); | 81 | int perf_evsel__alloc_fd(struct perf_evsel *evsel, int ncpus, int nthreads); |
78 | int perf_evsel__alloc_id(struct perf_evsel *evsel, int ncpus, int nthreads); | 82 | int perf_evsel__alloc_id(struct perf_evsel *evsel, int ncpus, int nthreads); |
79 | int perf_evsel__alloc_counts(struct perf_evsel *evsel, int ncpus); | 83 | int perf_evsel__alloc_counts(struct perf_evsel *evsel, int ncpus); |