aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util/evsel.c
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/evsel.c
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/evsel.c')
-rw-r--r--tools/perf/util/evsel.c70
1 files changed, 70 insertions, 0 deletions
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;