Skip to content

Commit f08cc25

Browse files
captain5050acmel
authored andcommitted
perf evsel: Add accessor for tool_event
Currently tool events use a dedicated variable within the evsel. Later changes will move this to the unused struct perf_event_attr config for these events. Add an accessor to allow the later change to be well typed and avoid changing all uses. Signed-off-by: Ian Rogers <[email protected]> Link: https://lore.kernel.org/r/[email protected] Cc: Ravi Bangoria <[email protected]> Cc: Sandipan Das <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Yang Jihong <[email protected]> Cc: Dominique Martinet <[email protected]> Cc: Clément Le Goffic <[email protected]> Cc: Colin Ian King <[email protected]> Cc: Howard Chu <[email protected]> Cc: Ze Gao <[email protected]> Cc: Yicong Yang <[email protected]> Cc: Changbin Du <[email protected]> Cc: Junhao He <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Adrian Hunter <[email protected]> Cc: Weilin Wang <[email protected]> Cc: Arnaldo Carvalho de Melo <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Will Deacon <[email protected]> Cc: James Clark <[email protected]> Cc: Mike Leach <[email protected]> Cc: Jing Zhang <[email protected]> Cc: Leo Yan <[email protected]> Cc: Oliver Upton <[email protected]> Cc: Benjamin Gray <[email protected]> Cc: Andi Kleen <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Kan Liang <[email protected]> Cc: Athira Jajeev <[email protected]> Cc: [email protected] Cc: Sun Haiyong <[email protected]> Cc: Tiezhu Yang <[email protected]> Cc: Xu Yang <[email protected]> Cc: John Garry <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Veronika Molnarova <[email protected]> Cc: Dr. David Alan Gilbert <[email protected]> Cc: [email protected] Cc: [email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 9253207 commit f08cc25

File tree

4 files changed

+21
-16
lines changed

4 files changed

+21
-16
lines changed

tools/perf/builtin-stat.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,14 +294,14 @@ static int read_single_counter(struct evsel *counter, int cpu_map_idx, int threa
294294
* terminates. Use the wait4 values in that case.
295295
*/
296296
if (err && cpu_map_idx == 0 &&
297-
(counter->tool_event == PERF_TOOL_USER_TIME ||
298-
counter->tool_event == PERF_TOOL_SYSTEM_TIME)) {
297+
(evsel__tool_event(counter) == PERF_TOOL_USER_TIME ||
298+
evsel__tool_event(counter) == PERF_TOOL_SYSTEM_TIME)) {
299299
u64 val, *start_time;
300300
struct perf_counts_values *count =
301301
perf_counts(counter->counts, cpu_map_idx, thread);
302302

303303
start_time = xyarray__entry(counter->start_times, cpu_map_idx, thread);
304-
if (counter->tool_event == PERF_TOOL_USER_TIME)
304+
if (evsel__tool_event(counter) == PERF_TOOL_USER_TIME)
305305
val = ru_stats.ru_utime_usec_stat.mean;
306306
else
307307
val = ru_stats.ru_stime_usec_stat.mean;

tools/perf/util/evsel.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -773,7 +773,7 @@ const char *evsel__name(struct evsel *evsel)
773773

774774
case PERF_TYPE_SOFTWARE:
775775
if (evsel__is_tool(evsel))
776-
evsel__tool_name(evsel->tool_event, bf, sizeof(bf));
776+
evsel__tool_name(evsel__tool_event(evsel), bf, sizeof(bf));
777777
else
778778
evsel__sw_name(evsel, bf, sizeof(bf));
779779
break;
@@ -811,7 +811,7 @@ const char *evsel__metric_id(const struct evsel *evsel)
811811
return evsel->metric_id;
812812

813813
if (evsel__is_tool(evsel))
814-
return perf_tool_event__to_str(evsel->tool_event);
814+
return perf_tool_event__to_str(evsel__tool_event(evsel));
815815

816816
return "unknown";
817817
}
@@ -1503,8 +1503,8 @@ void evsel__exit(struct evsel *evsel)
15031503
evsel->per_pkg_mask = NULL;
15041504
zfree(&evsel->metric_events);
15051505
perf_evsel__object.fini(evsel);
1506-
if (evsel->tool_event == PERF_TOOL_SYSTEM_TIME ||
1507-
evsel->tool_event == PERF_TOOL_USER_TIME)
1506+
if (evsel__tool_event(evsel) == PERF_TOOL_SYSTEM_TIME ||
1507+
evsel__tool_event(evsel) == PERF_TOOL_USER_TIME)
15081508
xyarray__delete(evsel->start_times);
15091509
}
15101510

@@ -1785,7 +1785,7 @@ static int evsel__read_tool(struct evsel *evsel, int cpu_map_idx, int thread)
17851785

17861786
count = perf_counts(evsel->counts, cpu_map_idx, thread);
17871787

1788-
switch (evsel->tool_event) {
1788+
switch (evsel__tool_event(evsel)) {
17891789
case PERF_TOOL_DURATION_TIME:
17901790
/*
17911791
* Pretend duration_time is only on the first CPU and thread, or
@@ -1800,7 +1800,7 @@ static int evsel__read_tool(struct evsel *evsel, int cpu_map_idx, int thread)
18001800
break;
18011801
case PERF_TOOL_USER_TIME:
18021802
case PERF_TOOL_SYSTEM_TIME: {
1803-
bool system = evsel->tool_event == PERF_TOOL_SYSTEM_TIME;
1803+
bool system = evsel__tool_event(evsel) == PERF_TOOL_SYSTEM_TIME;
18041804

18051805
start_time = xyarray__entry(evsel->start_times, cpu_map_idx, thread);
18061806
fd = FD(evsel, cpu_map_idx, thread);
@@ -2072,8 +2072,8 @@ static int __evsel__prepare_open(struct evsel *evsel, struct perf_cpu_map *cpus,
20722072
perf_evsel__alloc_fd(&evsel->core, perf_cpu_map__nr(cpus), nthreads) < 0)
20732073
return -ENOMEM;
20742074

2075-
if ((evsel->tool_event == PERF_TOOL_SYSTEM_TIME ||
2076-
evsel->tool_event == PERF_TOOL_USER_TIME) &&
2075+
if ((evsel__tool_event(evsel) == PERF_TOOL_SYSTEM_TIME ||
2076+
evsel__tool_event(evsel) == PERF_TOOL_USER_TIME) &&
20772077
!evsel->start_times) {
20782078
evsel->start_times = xyarray__new(perf_cpu_map__nr(cpus), nthreads, sizeof(__u64));
20792079
if (!evsel->start_times)
@@ -2262,7 +2262,7 @@ static int evsel__open_cpu(struct evsel *evsel, struct perf_cpu_map *cpus,
22622262
int pid = -1, err, old_errno;
22632263
enum rlimit_action set_rlimit = NO_CHANGE;
22642264

2265-
if (evsel->tool_event == PERF_TOOL_DURATION_TIME) {
2265+
if (evsel__tool_event(evsel) == PERF_TOOL_DURATION_TIME) {
22662266
if (evsel->core.attr.sample_period) /* no sampling */
22672267
return -EINVAL;
22682268
evsel->start_time = rdclock();
@@ -2304,9 +2304,9 @@ static int evsel__open_cpu(struct evsel *evsel, struct perf_cpu_map *cpus,
23042304
if (!evsel->cgrp && !evsel->core.system_wide)
23052305
pid = perf_thread_map__pid(threads, thread);
23062306

2307-
if (evsel->tool_event == PERF_TOOL_USER_TIME ||
2308-
evsel->tool_event == PERF_TOOL_SYSTEM_TIME) {
2309-
bool system = evsel->tool_event == PERF_TOOL_SYSTEM_TIME;
2307+
if (evsel__tool_event(evsel) == PERF_TOOL_USER_TIME ||
2308+
evsel__tool_event(evsel) == PERF_TOOL_SYSTEM_TIME) {
2309+
bool system = evsel__tool_event(evsel) == PERF_TOOL_SYSTEM_TIME;
23102310
__u64 *start_time = NULL;
23112311

23122312
if (evsel->core.attr.sample_period) {

tools/perf/util/evsel.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,11 @@ static inline bool evsel__is_retire_lat(const struct evsel *evsel)
330330
return evsel->retire_lat;
331331
}
332332

333+
static inline enum perf_tool_event evsel__tool_event(const struct evsel *evsel)
334+
{
335+
return evsel->tool_event;
336+
}
337+
333338
const char *evsel__group_name(struct evsel *evsel);
334339
int evsel__group_desc(struct evsel *evsel, char *buf, size_t size);
335340

tools/perf/util/stat-shadow.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ static int prepare_metric(const struct metric_expr *mexp,
380380
struct stats *stats;
381381
double scale;
382382

383-
switch (metric_events[i]->tool_event) {
383+
switch (evsel__tool_event(metric_events[i])) {
384384
case PERF_TOOL_DURATION_TIME:
385385
stats = &walltime_nsecs_stats;
386386
scale = 1e-9;

0 commit comments

Comments
 (0)