perf annotate: Calculate instruction overhead using hashmap

Use annotated_source.samples hashmap instead of addr array in the
struct sym_hist.

Reviewed-by: Ian Rogers <irogers@google.com>
Reviewed-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Andi Kleen <ak@linux.intel.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Link: https://lore.kernel.org/r/20240304230815.1440583-3-namhyung@kernel.org
This commit is contained in:
Namhyung Kim
2024-03-04 15:08:13 -08:00
parent d3e7cad6f3
commit 8015457584
3 changed files with 52 additions and 17 deletions

View File

@@ -28,21 +28,29 @@ static const char *const col_names[] = {
static int perf_gtk__get_percent(char *buf, size_t size, struct symbol *sym,
struct disasm_line *dl, int evidx)
{
struct annotation *notes;
struct sym_hist *symhist;
struct sym_hist_entry *entry;
double percent = 0.0;
const char *markup;
int ret = 0;
u64 nr_samples = 0;
strcpy(buf, "");
if (dl->al.offset == (s64) -1)
return 0;
symhist = annotation__histogram(symbol__annotation(sym), evidx);
if (!symbol_conf.event_group && !symhist->addr[dl->al.offset].nr_samples)
notes = symbol__annotation(sym);
symhist = annotation__histogram(notes, evidx);
entry = annotated_source__hist_entry(notes->src, evidx, dl->al.offset);
if (entry)
nr_samples = entry->nr_samples;
if (!symbol_conf.event_group && nr_samples == 0)
return 0;
percent = 100.0 * symhist->addr[dl->al.offset].nr_samples / symhist->nr_samples;
percent = 100.0 * nr_samples / symhist->nr_samples;
markup = perf_gtk__get_percent_color(percent);
if (markup)