]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
perf stream: Use evsel rather than evsel->idx
authorIan Rogers <irogers@google.com>
Thu, 14 Nov 2024 23:07:11 +0000 (15:07 -0800)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Mon, 23 Dec 2024 16:53:08 +0000 (13:53 -0300)
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>
tools/perf/builtin-diff.c
tools/perf/util/stream.c
tools/perf/util/stream.h

index 196969538e58cc0e3ccfd5bafe2822928358d617..ae490d58af9203b87d71ab3bb0ac21ddfbfab407 100644 (file)
@@ -1020,12 +1020,12 @@ static int process_base_stream(struct data__file *data_base,
                        continue;
 
                es_base = evsel_streams__entry(data_base->evlist_streams,
-                                              evsel_base->core.idx);
+                                              evsel_base);
                if (!es_base)
                        return -1;
 
                es_pair = evsel_streams__entry(data_pair->evlist_streams,
-                                              evsel_pair->core.idx);
+                                              evsel_pair);
                if (!es_pair)
                        return -1;
 
index 545e44981a276e7e9298de16d06e7ea7b1b754dc..3de4a6130853905ae1b1ca6b8104022e5002ba30 100644 (file)
@@ -52,7 +52,6 @@ static struct evlist_streams *evlist_streams__new(int nr_evsel,
                        goto err;
 
                s->nr_streams_max = nr_streams_max;
-               s->evsel_idx = -1;
        }
 
        els->ev_streams = es;
@@ -139,7 +138,7 @@ static int evlist__init_callchain_streams(struct evlist *evlist,
 
                hists__output_resort(hists, NULL);
                init_hot_callchain(hists, &es[i]);
-               es[i].evsel_idx = pos->core.idx;
+               es[i].evsel = pos;
                i++;
        }
 
@@ -166,12 +165,12 @@ struct evlist_streams *evlist__create_streams(struct evlist *evlist,
 }
 
 struct evsel_streams *evsel_streams__entry(struct evlist_streams *els,
-                                          int evsel_idx)
+                                          const struct evsel *evsel)
 {
        struct evsel_streams *es = els->ev_streams;
 
        for (int i = 0; i < els->nr_evsel; i++) {
-               if (es[i].evsel_idx == evsel_idx)
+               if (es[i].evsel == evsel)
                        return &es[i];
        }
 
index bee768874feaa65787966fa24972a03472371c4a..50f7e6e04982e0e9d4a997ed8670cf9ff5756114 100644 (file)
@@ -2,7 +2,9 @@
 #ifndef __PERF_STREAM_H
 #define __PERF_STREAM_H
 
-#include "callchain.h"
+struct callchain_node;
+struct evlist;
+struct evsel;
 
 struct stream {
        struct callchain_node   *cnode;
@@ -11,9 +13,9 @@ struct stream {
 
 struct evsel_streams {
        struct stream           *streams;
+       const struct evsel      *evsel;
        int                     nr_streams_max;
        int                     nr_streams;
-       int                     evsel_idx;
        u64                     streams_hits;
 };
 
@@ -22,15 +24,13 @@ struct evlist_streams {
        int                     nr_evsel;
 };
 
-struct evlist;
-
 void evlist_streams__delete(struct evlist_streams *els);
 
 struct evlist_streams *evlist__create_streams(struct evlist *evlist,
                                              int nr_streams_max);
 
 struct evsel_streams *evsel_streams__entry(struct evlist_streams *els,
-                                          int evsel_idx);
+                                          const struct evsel *evsel);
 
 void evsel_streams__match(struct evsel_streams *es_base,
                          struct evsel_streams *es_pair);