[PATCH v1 20/26] perf annotate: Use generic hashmap for sym_samples
From: Ian Rogers
Date: Fri Nov 13 2026 - 16:51:42 EST
Convert annotated_source::samples in util/annotate.{c,h} to
DECLARE_HASHMAP(sym_samples_map, long, struct sym_hist_entry *) and use
hashmap__for_each() when freeing histogram entries.
Signed-off-by: Ian Rogers <irogers@xxxxxxxxxx>
---
tools/perf/util/annotate.c | 20 ++++++++++----------
tools/perf/util/annotate.h | 5 ++++-
2 files changed, 14 insertions(+), 11 deletions(-)
diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index d11add6424dc..c6325040452f 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -112,16 +112,16 @@ static struct annotated_source *annotated_source__new(void)
static __maybe_unused void annotated_source__delete(struct annotated_source *src)
{
- struct hashmap_entry *cur;
- size_t bkt;
+ long key;
+ struct sym_hist_entry *val;
if (src == NULL)
return;
if (src->samples) {
- hashmap__for_each_entry(src->samples, cur, bkt)
- zfree(&cur->pvalue);
- hashmap__free(src->samples);
+ hashmap__for_each(src->samples, key, val)
+ free(val);
+ sym_samples_map__free(src->samples);
}
zfree(&src->histograms);
free(src);
@@ -136,7 +136,7 @@ static int annotated_source__alloc_histograms(struct annotated_source *src,
if (src->histograms == NULL)
return -1;
- src->samples = hashmap__new(sym_hist_hash, sym_hist_equal, NULL);
+ src->samples = sym_samples_map__new(sym_hist_hash, sym_hist_equal, NULL);
if (!src->samples)
zfree(&src->histograms);
@@ -163,11 +163,11 @@ void symbol__annotate_zero_histograms(struct symbol *sym)
memset(notes->src->histograms, 0,
notes->src->nr_histograms * sizeof(*notes->src->histograms));
if (notes->src->samples) {
- struct hashmap_entry *cur;
- size_t bkt;
+ long key;
+ struct sym_hist_entry *val;
- hashmap__for_each_entry(notes->src->samples, cur, bkt)
- zfree(&cur->pvalue);
+ hashmap__for_each(notes->src->samples, key, val)
+ free(val);
hashmap__clear(notes->src->samples);
}
}
diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h
index 1b47c1156b9a..495c8602864c 100644
--- a/tools/perf/util/annotate.h
+++ b/tools/perf/util/annotate.h
@@ -312,10 +312,13 @@ struct cyc_hist {
* presented. It is deallocated right after symbol__{tui,tty,etc}_annotate
* returns.
*/
+struct sym_hist_entry;
+DECLARE_HASHMAP(sym_samples_map, long, struct sym_hist_entry *);
+
struct annotated_source {
struct list_head source;
struct sym_hist *histograms;
- struct hashmap *samples;
+ struct sym_samples_map *samples;
int nr_histograms;
int nr_events;
int nr_entries;
--
2.56.1.703.gf848ed807c-goog