aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2011-11-08 11:41:57 -0500
committerArnaldo Carvalho de Melo <acme@redhat.com>2011-11-28 07:25:31 -0500
commit0f82ebc452f921590e216b28eee0b41f5e434a48 (patch)
tree96f8f0df01f362f3184e3dbc1137809e4d0aa065 /tools/perf/util
parenta8c9ae18d810e1ae12b6ec960907e9af63171d3a (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.c16
-rw-r--r--tools/perf/util/evlist.h4
-rw-r--r--tools/perf/util/evsel.c70
-rw-r--r--tools/perf/util/evsel.h4
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
49void 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
49static void perf_evlist__purge(struct perf_evlist *evlist) 65static 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 @@
10struct pollfd; 10struct pollfd;
11struct thread_map; 11struct thread_map;
12struct cpu_map; 12struct cpu_map;
13struct 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
65int perf_evlist__open(struct perf_evlist *evlist, bool group); 66int perf_evlist__open(struct perf_evlist *evlist, bool group);
66 67
68void perf_evlist__config_attrs(struct perf_evlist *evlist,
69 struct perf_record_opts *opts);
70
67int perf_evlist__alloc_mmap(struct perf_evlist *evlist); 71int perf_evlist__alloc_mmap(struct perf_evlist *evlist);
68int perf_evlist__mmap(struct perf_evlist *evlist, int pages, bool overwrite); 72int perf_evlist__mmap(struct perf_evlist *evlist, int pages, bool overwrite);
69void perf_evlist__munmap(struct perf_evlist *evlist); 73void 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
56void 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
56int perf_evsel__alloc_fd(struct perf_evsel *evsel, int ncpus, int nthreads) 126int 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 {
67struct cpu_map; 67struct cpu_map;
68struct thread_map; 68struct thread_map;
69struct perf_evlist; 69struct perf_evlist;
70struct perf_record_opts;
70 71
71struct perf_evsel *perf_evsel__new(struct perf_event_attr *attr, int idx); 72struct perf_evsel *perf_evsel__new(struct perf_event_attr *attr, int idx);
72void perf_evsel__init(struct perf_evsel *evsel, 73void perf_evsel__init(struct perf_evsel *evsel,
@@ -74,6 +75,9 @@ void perf_evsel__init(struct perf_evsel *evsel,
74void perf_evsel__exit(struct perf_evsel *evsel); 75void perf_evsel__exit(struct perf_evsel *evsel);
75void perf_evsel__delete(struct perf_evsel *evsel); 76void perf_evsel__delete(struct perf_evsel *evsel);
76 77
78void perf_evsel__config(struct perf_evsel *evsel,
79 struct perf_record_opts *opts);
80
77int perf_evsel__alloc_fd(struct perf_evsel *evsel, int ncpus, int nthreads); 81int perf_evsel__alloc_fd(struct perf_evsel *evsel, int ncpus, int nthreads);
78int perf_evsel__alloc_id(struct perf_evsel *evsel, int ncpus, int nthreads); 82int perf_evsel__alloc_id(struct perf_evsel *evsel, int ncpus, int nthreads);
79int perf_evsel__alloc_counts(struct perf_evsel *evsel, int ncpus); 83int perf_evsel__alloc_counts(struct perf_evsel *evsel, int ncpus);