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

Configure Feed

Select the types of activity you want to include in your feed.

perf stat-shadow: In prepare_metric fix guard on reading NULL perf_stat_evsel

The aggr value is setup to always be non-null creating a redundant
guard for reading from it. Switch to using the perf_stat_evsel (ps)
and narrow the scope of aggr so that it is known valid when used.

Fixes: 3d65f6445fd93e3e ("perf stat-shadow: Read tool events directly")
Reported-by: Andres Freund <andres@anarazel.de>
Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Dapeng Mi <dapeng1.mi@linux.intel.com>
Cc: Dr. David Alan Gilbert <linux@treblig.org>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Clark <james.clark@linaro.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Falcon <thomas.falcon@intel.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Yang Li <yang.lee@linux.alibaba.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Ian Rogers and committed by
Arnaldo Carvalho de Melo
63b320aa bc105a89

+16 -8
+16 -8
tools/perf/util/stat-shadow.c
··· 57 57 bool is_tool_time = 58 58 tool_pmu__is_time_event(config, metric_events[i], &tool_aggr_idx); 59 59 struct perf_stat_evsel *ps = metric_events[i]->stats; 60 - struct perf_stat_aggr *aggr; 61 60 char *n; 62 61 double val; 63 62 ··· 81 82 } 82 83 } 83 84 /* Time events are always on CPU0, the first aggregation index. */ 84 - aggr = &ps->aggr[is_tool_time ? tool_aggr_idx : aggr_idx]; 85 - if (!aggr || !metric_events[i]->supported || aggr->counts.run == 0) { 85 + if (!ps || !metric_events[i]->supported) { 86 86 /* 87 87 * Not supported events will have a count of 0, which 88 88 * can be confusing in a metric. Explicitly set the ··· 91 93 val = NAN; 92 94 source_count = 0; 93 95 } else { 94 - val = aggr->counts.val; 95 - if (is_tool_time) 96 - val *= 1e-9; /* Convert time event nanoseconds to seconds. */ 97 - if (!source_count) 98 - source_count = evsel__source_count(metric_events[i]); 96 + struct perf_stat_aggr *aggr = 97 + &ps->aggr[is_tool_time ? tool_aggr_idx : aggr_idx]; 98 + 99 + if (aggr->counts.run == 0) { 100 + val = NAN; 101 + source_count = 0; 102 + } else { 103 + val = aggr->counts.val; 104 + if (is_tool_time) { 105 + /* Convert time event nanoseconds to seconds. */ 106 + val *= 1e-9; 107 + } 108 + if (!source_count) 109 + source_count = evsel__source_count(metric_events[i]); 110 + } 99 111 } 100 112 n = strdup(evsel__metric_id(metric_events[i])); 101 113 if (!n)