Skip to content

Commit 34433fd

Browse files
[BOLT] Add -print-mappings option to heatmaps (#97567)
Emit a mapping in the legend between the characters/buckets and the text sections, using: ```sh llvm-heatmap-bolt -print-mappings .. ``` Example: ``` Legend: .. Sections: a/A : .init 0x00000100-0x00000200 b/B : .plt 0x00000200-0x00000500 c/C : .text 0x00010000-0x000a0000 d/D : .fini 0x000a0000-0x000f0000 .. ```
1 parent 0d74031 commit 34433fd

File tree

5 files changed

+33
-1
lines changed

5 files changed

+33
-1
lines changed

bolt/docs/CommandLineArgumentReference.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,12 @@
283283

284284
List of functions to pad with amount of bytes
285285

286+
- `--print-mappings`
287+
288+
Print mappings in the legend, between characters/blocks and text sections
289+
(default false).
290+
291+
286292
- `--profile-format=<value>`
287293

288294
Format to dump profile output in aggregation mode, default is fdata
@@ -1240,4 +1246,4 @@
12401246

12411247
- `--print-options`
12421248

1243-
Print non-default options after command line parsing
1249+
Print non-default options after command line parsing

bolt/docs/Heatmaps.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ Other useful options are:
4141
```bash
4242
-line-size=<uint> - number of entries per line (default 256)
4343
-max-address=<uint> - maximum address considered valid for heatmap (default 4GB)
44+
-print-mappings=<bool> - print mappings in legend, between characters/blocks and text sections (default false)
4445
```
4546

4647
If you prefer to look at the data in a browser (or would like to share

bolt/include/bolt/Utils/CommandLineOpts.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ extern llvm::cl::opt<unsigned> ExecutionCountThreshold;
4040
extern llvm::cl::opt<unsigned> HeatmapBlock;
4141
extern llvm::cl::opt<unsigned long long> HeatmapMaxAddress;
4242
extern llvm::cl::opt<unsigned long long> HeatmapMinAddress;
43+
extern llvm::cl::opt<bool> HeatmapPrintMappings;
4344
extern llvm::cl::opt<bool> HotData;
4445
extern llvm::cl::opt<bool> HotFunctionsAtEnd;
4546
extern llvm::cl::opt<bool> HotText;

bolt/lib/Profile/Heatmap.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "llvm/Support/Debug.h"
1414
#include "llvm/Support/FileSystem.h"
1515
#include "llvm/Support/Format.h"
16+
#include "llvm/Support/FormatVariadic.h"
1617
#include "llvm/Support/MathExtras.h"
1718
#include "llvm/Support/raw_ostream.h"
1819
#include <algorithm>
@@ -164,6 +165,7 @@ void Heatmap::print(raw_ostream &OS) const {
164165

165166
// Print map legend
166167
OS << "Legend:\n";
168+
OS << "\nRanges:\n";
167169
uint64_t PrevValue = 0;
168170
for (unsigned I = 0; I < sizeof(Range) / sizeof(Range[0]); ++I) {
169171
const uint64_t Value = Range[I];
@@ -172,6 +174,22 @@ void Heatmap::print(raw_ostream &OS) const {
172174
OS << " : (" << PrevValue << ", " << Value << "]\n";
173175
PrevValue = Value;
174176
}
177+
if (opts::HeatmapPrintMappings) {
178+
OS << "\nSections:\n";
179+
unsigned SectionIdx = 0;
180+
for (auto TxtSeg : TextSections) {
181+
const char Upper = static_cast<char>('A' + ((SectionIdx++) % 26));
182+
const char Lower = static_cast<char>(std::tolower(Upper));
183+
OS << formatv(" {0}/{1} : {2,-10} ", Lower, Upper, TxtSeg.Name);
184+
if (MaxAddress > 0xffffffff)
185+
OS << format("0x%016" PRIx64, TxtSeg.BeginAddress) << "-"
186+
<< format("0x%016" PRIx64, TxtSeg.EndAddress) << "\n";
187+
else
188+
OS << format("0x%08" PRIx64, TxtSeg.BeginAddress) << "-"
189+
<< format("0x%08" PRIx64, TxtSeg.EndAddress) << "\n";
190+
}
191+
OS << "\n";
192+
}
175193

176194
// Pos - character position from right in hex form.
177195
auto printHeader = [&](unsigned Pos) {

bolt/lib/Utils/CommandLineOpts.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,12 @@ cl::opt<unsigned long long> HeatmapMinAddress(
105105
cl::desc("minimum address considered valid for heatmap (default 0)"),
106106
cl::Optional, cl::cat(HeatmapCategory));
107107

108+
cl::opt<bool> HeatmapPrintMappings(
109+
"print-mappings", cl::init(false),
110+
cl::desc("print mappings in the legend, between characters/blocks and text "
111+
"sections (default false)"),
112+
cl::Optional, cl::cat(HeatmapCategory));
113+
108114
cl::opt<bool> HotData("hot-data",
109115
cl::desc("hot data symbols support (relocation mode)"),
110116
cl::cat(BoltCategory));

0 commit comments

Comments
 (0)