[PATCH v1 22/26] perf annotate-data: Use generic hashmap for type_hist samples

From: Ian Rogers

Date: Fri Nov 13 2026 - 16:51:57 EST


Convert type_hist::samples in util/annotate-data.{c,h} and
ui/browsers/annotate-data.c to
DECLARE_HASHMAP(type_hist_map, int, struct type_hist_entry *).

Signed-off-by: Ian Rogers <irogers@xxxxxxxxxx>
---
tools/perf/util/annotate-data.c | 10 +++++-----
tools/perf/util/annotate-data.h | 5 ++++-
2 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/tools/perf/util/annotate-data.c b/tools/perf/util/annotate-data.c
index 2332d465f975..dabbbb34fcd8 100644
--- a/tools/perf/util/annotate-data.c
+++ b/tools/perf/util/annotate-data.c
@@ -2059,12 +2059,12 @@ static int alloc_data_type_histograms(struct annotated_data_type *adt, int nr_en
static void delete_data_type_histograms(struct annotated_data_type *adt)
{
for (int i = 0; i < adt->nr_histograms; i++) {
- struct hashmap *map = &adt->histograms[i].samples;
- struct hashmap_entry *pos, *tmp;
- size_t bkt;
+ struct type_hist_map *map = &adt->histograms[i].samples;
+ int offset;
+ struct type_hist_entry *entry;

- hashmap__for_each_entry_safe(map, pos, tmp, bkt)
- free(pos->pvalue);
+ hashmap__for_each_safe(map, offset, entry)
+ free(entry);
hashmap__clear(map);
}

diff --git a/tools/perf/util/annotate-data.h b/tools/perf/util/annotate-data.h
index 184262c73562..b5b780d26004 100644
--- a/tools/perf/util/annotate-data.h
+++ b/tools/perf/util/annotate-data.h
@@ -8,6 +8,7 @@
#include <linux/types.h>
#include "dwarf-regs.h"
#include "annotate.h"
+#include "hashmap.h"

#ifdef HAVE_LIBDW_SUPPORT
#include "debuginfo.h"
@@ -81,6 +82,8 @@ struct type_hist_entry {
u64 period;
};

+DECLARE_HASHMAP(type_hist_map, int, struct type_hist_entry *);
+
/**
* struct type_hist - Type histogram for each event
* @nr_samples: Total number of samples in this data type
@@ -90,7 +93,7 @@ struct type_hist_entry {
struct type_hist {
u64 nr_samples;
u64 period;
- struct hashmap samples;
+ struct type_hist_map samples;
};

/**
--
2.56.1.703.gf848ed807c-goog