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>
@@ -45,6 +46,10 @@ class Heatmap {
4546 // / Map section names to their address range.
4647 const std::vector<SectionNameAndRange> TextSections;
4748
49+ uint64_t getNumBuckets (uint64_t Begin, uint64_t End) const {
50+ return End / BucketSize + !!(End % BucketSize) - Begin / BucketSize;
51+ };
52+
4853public:
4954 explicit Heatmap (uint64_t BucketSize = 4096 , uint64_t MinAddress = 0 ,
5055 uint64_t MaxAddress = std::numeric_limits<uint64_t >::max(),
@@ -57,9 +62,9 @@ class Heatmap {
5762 }
5863
5964 // / Register a single sample at \p Address.
60- void registerAddress (uint64_t Address) {
65+ void registerAddress (uint64_t Address, uint64_t Count ) {
6166 if (!ignoreAddress (Address))
62- ++ Map[Address / BucketSize];
67+ Map[Address / BucketSize] += Count ;
6368 }
6469
6570 // / Register \p Count samples at [\p StartAddress, \p EndAddress ].
@@ -77,9 +82,22 @@ class Heatmap {
7782
7883 void printCDF (raw_ostream &OS) const ;
7984
80- void printSectionHotness (StringRef Filename) const ;
85+ // / Struct describing individual section hotness.
86+ struct SectionStats {
87+ uint64_t Samples{0 };
88+ uint64_t Buckets{0 };
89+ };
90+
91+ // / Mapping from section name to associated \p SectionStats. Special entries:
92+ // / - [total] for total stats,
93+ // / - [unmapped] for samples outside any section, if non-zero.
94+ using SectionStatsMap = StringMap<SectionStats>;
95+
96+ SectionStatsMap computeSectionStats () const ;
97+
98+ void printSectionHotness (const SectionStatsMap &, StringRef Filename) const ;
8199
82- void printSectionHotness (raw_ostream &OS) const ;
100+ void printSectionHotness (const SectionStatsMap &, raw_ostream &OS) const ;
83101
84102 size_t size () const { return Map.size (); }
85103};
0 commit comments