4 #include "parse-events.h"
6 typedef void (*setup_probe_fn_t
)(struct perf_evsel
*evsel
);
8 static int perf_do_probe_api(setup_probe_fn_t fn
, int cpu
, const char *str
)
10 struct perf_evlist
*evlist
;
11 struct perf_evsel
*evsel
;
12 int err
= -EAGAIN
, fd
;
14 evlist
= perf_evlist__new();
18 if (parse_events(evlist
, str
))
21 evsel
= perf_evlist__first(evlist
);
23 fd
= sys_perf_event_open(&evsel
->attr
, -1, cpu
, -1, 0);
30 fd
= sys_perf_event_open(&evsel
->attr
, -1, cpu
, -1, 0);
40 perf_evlist__delete(evlist
);
44 static bool perf_probe_api(setup_probe_fn_t fn
)
46 const char *try[] = {"cycles:u", "instructions:u", "cpu-clock", NULL
};
50 cpus
= cpu_map__new(NULL
);
54 cpu_map__delete(cpus
);
57 ret
= perf_do_probe_api(fn
, cpu
, try[i
++]);
60 } while (ret
== -EAGAIN
&& try[i
]);
65 static void perf_probe_sample_identifier(struct perf_evsel
*evsel
)
67 evsel
->attr
.sample_type
|= PERF_SAMPLE_IDENTIFIER
;
70 bool perf_can_sample_identifier(void)
72 return perf_probe_api(perf_probe_sample_identifier
);
75 void perf_evlist__config(struct perf_evlist
*evlist
,
76 struct perf_record_opts
*opts
)
78 struct perf_evsel
*evsel
;
79 bool use_sample_identifier
= false;
82 * Set the evsel leader links before we configure attributes,
83 * since some might depend on this info.
86 perf_evlist__set_leader(evlist
);
88 if (evlist
->cpus
->map
[0] < 0)
89 opts
->no_inherit
= true;
91 list_for_each_entry(evsel
, &evlist
->entries
, node
)
92 perf_evsel__config(evsel
, opts
);
94 if (evlist
->nr_entries
> 1) {
95 struct perf_evsel
*first
= perf_evlist__first(evlist
);
97 list_for_each_entry(evsel
, &evlist
->entries
, node
) {
98 if (evsel
->attr
.sample_type
== first
->attr
.sample_type
)
100 use_sample_identifier
= perf_can_sample_identifier();
103 list_for_each_entry(evsel
, &evlist
->entries
, node
)
104 perf_evsel__set_sample_id(evsel
, use_sample_identifier
);
107 perf_evlist__set_id_pos(evlist
);