Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf stream: Use evsel rather than evsel->idx

An evsel idx may not be stable due to sorting, evlist removal,
etc. Avoid use of the idx where the evsel itself can be used to avoid
these problems.

Reviewed-by: James Clark <james.clark@linaro.org>
Reviewed-by: Namhyung Kim <namhyung@kernel.org>
Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Chen Ni <nichen@iscas.ac.cn>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/r/20241114230713.330701-2-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Ian Rogers and committed by
Arnaldo Carvalho de Melo
2f0539fa 518413d8

+10 -11
+2 -2
tools/perf/builtin-diff.c
··· 1020 1020 continue; 1021 1021 1022 1022 es_base = evsel_streams__entry(data_base->evlist_streams, 1023 - evsel_base->core.idx); 1023 + evsel_base); 1024 1024 if (!es_base) 1025 1025 return -1; 1026 1026 1027 1027 es_pair = evsel_streams__entry(data_pair->evlist_streams, 1028 - evsel_pair->core.idx); 1028 + evsel_pair); 1029 1029 if (!es_pair) 1030 1030 return -1; 1031 1031
+3 -4
tools/perf/util/stream.c
··· 52 52 goto err; 53 53 54 54 s->nr_streams_max = nr_streams_max; 55 - s->evsel_idx = -1; 56 55 } 57 56 58 57 els->ev_streams = es; ··· 138 139 139 140 hists__output_resort(hists, NULL); 140 141 init_hot_callchain(hists, &es[i]); 141 - es[i].evsel_idx = pos->core.idx; 142 + es[i].evsel = pos; 142 143 i++; 143 144 } 144 145 ··· 165 166 } 166 167 167 168 struct evsel_streams *evsel_streams__entry(struct evlist_streams *els, 168 - int evsel_idx) 169 + const struct evsel *evsel) 169 170 { 170 171 struct evsel_streams *es = els->ev_streams; 171 172 172 173 for (int i = 0; i < els->nr_evsel; i++) { 173 - if (es[i].evsel_idx == evsel_idx) 174 + if (es[i].evsel == evsel) 174 175 return &es[i]; 175 176 } 176 177
+5 -5
tools/perf/util/stream.h
··· 2 2 #ifndef __PERF_STREAM_H 3 3 #define __PERF_STREAM_H 4 4 5 - #include "callchain.h" 5 + struct callchain_node; 6 + struct evlist; 7 + struct evsel; 6 8 7 9 struct stream { 8 10 struct callchain_node *cnode; ··· 13 11 14 12 struct evsel_streams { 15 13 struct stream *streams; 14 + const struct evsel *evsel; 16 15 int nr_streams_max; 17 16 int nr_streams; 18 - int evsel_idx; 19 17 u64 streams_hits; 20 18 }; 21 19 ··· 24 22 int nr_evsel; 25 23 }; 26 24 27 - struct evlist; 28 - 29 25 void evlist_streams__delete(struct evlist_streams *els); 30 26 31 27 struct evlist_streams *evlist__create_streams(struct evlist *evlist, 32 28 int nr_streams_max); 33 29 34 30 struct evsel_streams *evsel_streams__entry(struct evlist_streams *els, 35 - int evsel_idx); 31 + const struct evsel *evsel); 36 32 37 33 void evsel_streams__match(struct evsel_streams *es_base, 38 34 struct evsel_streams *es_pair);