99#ifndef BOLT_PROFILE_HEATMAP_H
1010#define BOLT_PROFILE_HEATMAP_H
1111
12+ #include " llvm/ADT/StringMap.h"
1213#include " llvm/ADT/StringRef.h"
1314#include < cstdint>
1415#include < map>
@@ -57,9 +58,9 @@ class Heatmap {
5758 }
5859
5960 // / Register a single sample at \p Address.
60- void registerAddress (uint64_t Address) {
61+ void registerAddress (uint64_t Address, uint64_t Count ) {
6162 if (!ignoreAddress (Address))
62- ++ Map[Address / BucketSize];
63+ Map[Address / BucketSize] += Count ;
6364 }
6465
6566 // / Register \p Count samples at [\p StartAddress, \p EndAddress ].
@@ -77,9 +78,22 @@ class Heatmap {
7778
7879 void printCDF (raw_ostream &OS) const ;
7980
80- void printSectionHotness (StringRef Filename) const ;
81+ // / Struct describing individual section hotness.
82+ struct SectionStats {
83+ uint64_t Samples{0 };
84+ uint64_t Buckets{0 };
85+ };
8186
82- void printSectionHotness (raw_ostream &OS) const ;
87+ // / Mapping from section name to associated \p SectionStats. Special entries:
88+ // / - [total] for total stats,
89+ // / - [unmapped] for samples outside any section, if non-zero.
90+ using SectionStatsMap = StringMap<SectionStats>;
91+
92+ SectionStatsMap computeSectionStats () const ;
93+
94+ void printSectionHotness (const SectionStatsMap &, StringRef Filename) const ;
95+
96+ void printSectionHotness (const SectionStatsMap &, raw_ostream &OS) const ;
8397
8498 size_t size () const { return Map.size (); }
8599};
0 commit comments