Skip to content

Commit d8d259f

Browse files
committed
Modify block-size option
Created using spr 1.3.4
2 parents 5ab0498 + 0de8ff6 commit d8d259f

File tree

334 files changed

+23905
-21720
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

334 files changed

+23905
-21720
lines changed

bolt/docs/Heatmaps.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,12 @@ For the generation, the default bucket size was used with a line size of 128.
8989
Some useful options are:
9090

9191
```
92-
-block-size=<uint> - heatmap bucket size in bytes (default 64)
9392
-line-size=<uint> - number of entries per line (default 256).
9493
Use 128 if the heatmap doesn't fit screen horizontally.
94+
-block-size=<uint>[:<pow2>,...] - heatmap bucket size in bytes (default 64),
95+
optionally followed by power-of-two zoom-out scales to
96+
produce coarse grained heatmaps (default 6, 2, 6 =>
97+
4K, 16K, 1MB).
9598
-max-address=<uint> - maximum address considered valid for heatmap (default 4GB)
9699
-print-mappings - print mappings in the legend, between characters/blocks and text sections (default false)
97-
-heatmap-zoom-out=<uint>,... - print zoomed out heatmaps with given block sizes,
98-
must be multiples of block-size in ascending order.
99-
Suggested values: 4096 (default page size), 16384 (16k page),
100-
1048576 (1MB for XL workloads).
101100
```

bolt/include/bolt/Profile/Heatmap.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,9 @@ class Heatmap {
8686

8787
size_t size() const { return Map.size(); }
8888

89-
/// Increase bucket size to \p TargetSize, recomputing the heatmap.
90-
bool resizeBucket(uint64_t TargetSize);
89+
/// Increase bucket size by 2^\p Scale, recomputing the heatmap.
90+
/// Returns new bucket size.
91+
uint64_t resizeBucket(uint64_t Pow2Scale);
9192
};
9293

9394
} // namespace bolt

bolt/include/bolt/Utils/CommandLineOpts.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,19 @@ enum HeatmapModeKind {
2323
HM_Optional // perf2bolt --heatmap
2424
};
2525

26+
struct HeatmapBlockSpec {
27+
unsigned Initial{0}; // Initial block size in bytes.
28+
llvm::SmallVector<unsigned> Scales; // Pow2 zoom factors applied cumulatively.
29+
};
30+
31+
struct HeatmapBlockSpecParser : public llvm::cl::parser<HeatmapBlockSpec> {
32+
explicit HeatmapBlockSpecParser(llvm::cl::Option &O)
33+
: llvm::cl::parser<HeatmapBlockSpec>(O) {}
34+
// Return true on error.
35+
bool parse(llvm::cl::Option &O, llvm::StringRef ArgName, llvm::StringRef Arg,
36+
HeatmapBlockSpec &Val);
37+
};
38+
2639
extern HeatmapModeKind HeatmapMode;
2740
extern bool BinaryAnalysisMode;
2841

@@ -47,7 +60,8 @@ extern llvm::cl::opt<bool> EqualizeBBCounts;
4760
extern llvm::cl::opt<bool> ForcePatch;
4861
extern llvm::cl::opt<bool> RemoveSymtab;
4962
extern llvm::cl::opt<unsigned> ExecutionCountThreshold;
50-
extern llvm::cl::opt<unsigned> HeatmapBlock;
63+
extern llvm::cl::opt<HeatmapBlockSpec, false, HeatmapBlockSpecParser>
64+
HeatmapBlock;
5165
extern llvm::cl::opt<unsigned long long> HeatmapMaxAddress;
5266
extern llvm::cl::opt<unsigned long long> HeatmapMinAddress;
5367
extern llvm::cl::opt<bool> HeatmapPrintMappings;

bolt/lib/Core/BinaryFunction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3326,7 +3326,7 @@ void BinaryFunction::duplicateConstantIslands() {
33263326
static std::string constructFilename(std::string Filename,
33273327
std::string Annotation,
33283328
std::string Suffix) {
3329-
std::replace(Filename.begin(), Filename.end(), '/', '-');
3329+
llvm::replace(Filename, '/', '-');
33303330
if (!Annotation.empty())
33313331
Annotation.insert(0, "-");
33323332
if (Filename.size() + Annotation.size() + Suffix.size() > MAX_PATH) {

bolt/lib/Core/DIEBuilder.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -437,10 +437,10 @@ getUnitForOffset(DIEBuilder &Builder, DWARFContext &DWCtx,
437437
// This is a work around for XCode clang. There is a build error when we
438438
// pass DWCtx.compile_units() to llvm::upper_bound
439439
std::call_once(InitVectorFlag, initCUVector);
440-
auto CUIter = std::upper_bound(CUOffsets.begin(), CUOffsets.end(), Offset,
441-
[](uint64_t LHS, const DWARFUnit *RHS) {
442-
return LHS < RHS->getNextUnitOffset();
443-
});
440+
auto CUIter = llvm::upper_bound(CUOffsets, Offset,
441+
[](uint64_t LHS, const DWARFUnit *RHS) {
442+
return LHS < RHS->getNextUnitOffset();
443+
});
444444
CU = CUIter != CUOffsets.end() ? (*CUIter) : nullptr;
445445
}
446446
return CU;

bolt/lib/Passes/AsmDump.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ void dumpFunction(const BinaryFunction &BF) {
109109
}
110110

111111
std::string PrintName = BF.getPrintName();
112-
std::replace(PrintName.begin(), PrintName.end(), '/', '-');
112+
llvm::replace(PrintName, '/', '-');
113113
std::string Filename =
114114
opts::AsmDump.empty()
115115
? (PrintName + ".s")

bolt/lib/Passes/BinaryPasses.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ static const char *dynoStatsOptName(const bolt::DynoStats::Category C) {
3535

3636
OptNames[C] = bolt::DynoStats::Description(C);
3737

38-
std::replace(OptNames[C].begin(), OptNames[C].end(), ' ', '-');
38+
llvm::replace(OptNames[C], ' ', '-');
3939

4040
return OptNames[C].c_str();
4141
}

bolt/lib/Profile/DataAggregator.cpp

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,6 @@ FilterPID("pid",
6868
cl::Optional,
6969
cl::cat(AggregatorCategory));
7070

71-
static cl::list<uint64_t>
72-
HeatmapZoomOut("heatmap-zoom-out", cl::CommaSeparated,
73-
cl::desc("print secondary heatmaps with given bucket sizes"),
74-
cl::value_desc("bucket_size"), cl::Optional,
75-
cl::cat(HeatmapCategory));
76-
7771
static cl::opt<bool>
7872
IgnoreBuildID("ignore-build-id",
7973
cl::desc("continue even if build-ids in input binary and perf.data mismatch"),
@@ -1320,8 +1314,9 @@ std::error_code DataAggregator::printLBRHeatMap() {
13201314
opts::HeatmapMaxAddress = 0xffffffffffffffff;
13211315
opts::HeatmapMinAddress = KernelBaseAddr;
13221316
}
1323-
Heatmap HM(opts::HeatmapBlock, opts::HeatmapMinAddress,
1324-
opts::HeatmapMaxAddress, getTextSections(BC));
1317+
opts::HeatmapBlockSpec HMBS = opts::HeatmapBlock;
1318+
Heatmap HM(HMBS.Initial, opts::HeatmapMinAddress, opts::HeatmapMaxAddress,
1319+
getTextSections(BC));
13251320
auto getSymbolValue = [&](const MCSymbol *Symbol) -> uint64_t {
13261321
if (Symbol)
13271322
if (ErrorOr<uint64_t> SymValue = BC->getSymbolValue(*Symbol))
@@ -1371,10 +1366,9 @@ std::error_code DataAggregator::printLBRHeatMap() {
13711366
HM.printCDF(opts::HeatmapOutput + ".csv");
13721367
HM.printSectionHotness(opts::HeatmapOutput + "-section-hotness.csv");
13731368
}
1374-
// Provide coarse-grained heatmap if requested via --heatmap-zoom-out
1375-
for (const uint64_t NewBucketSize : opts::HeatmapZoomOut) {
1376-
if (!HM.resizeBucket(NewBucketSize))
1377-
break;
1369+
// Provide coarse-grained heatmaps if requested via zoom-out scales
1370+
for (const uint64_t NewBucketSizeScale : HMBS.Scales) {
1371+
uint64_t NewBucketSize = HM.resizeBucket(NewBucketSizeScale);
13781372
if (opts::HeatmapOutput == "-")
13791373
HM.print(opts::HeatmapOutput);
13801374
else

bolt/lib/Profile/Heatmap.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ void Heatmap::print(StringRef FileName) const {
5555
errs() << "error opening output file: " << EC.message() << '\n';
5656
exit(1);
5757
}
58+
outs() << "HEATMAP: dumping heatmap with bucket size " << BucketSize << " to "
59+
<< FileName << '\n';
5860
print(OS);
5961
}
6062

@@ -365,17 +367,12 @@ void Heatmap::printSectionHotness(raw_ostream &OS) const {
365367
100.0 * UnmappedHotness / NumTotalCounts);
366368
}
367369

368-
bool Heatmap::resizeBucket(uint64_t TargetSize) {
369-
if (TargetSize <= BucketSize)
370-
return false;
370+
uint64_t Heatmap::resizeBucket(uint64_t Pow2Scale) {
371371
std::map<uint64_t, uint64_t> NewMap;
372-
for (const auto [Bucket, Count] : Map) {
373-
const uint64_t Address = Bucket * BucketSize;
374-
NewMap[Address / TargetSize] += Count;
375-
}
372+
for (const auto [Bucket, Count] : Map)
373+
NewMap[Bucket >> Pow2Scale] += Count;
376374
Map = NewMap;
377-
BucketSize = TargetSize;
378-
return true;
375+
return BucketSize <<= Pow2Scale;
379376
}
380377
} // namespace bolt
381378
} // namespace llvm

bolt/lib/Utils/CommandLineOpts.cpp

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,38 @@ ExecutionCountThreshold("execution-count-threshold",
103103
cl::Hidden,
104104
cl::cat(BoltOptCategory));
105105

106-
cl::opt<unsigned>
107-
HeatmapBlock("block-size",
108-
cl::desc("size of a heat map block in bytes (default 64)"),
109-
cl::init(64), cl::cat(HeatmapCategory));
106+
bool HeatmapBlockSpecParser::parse(cl::Option &O, StringRef ArgName,
107+
StringRef Arg, HeatmapBlockSpec &Val) {
108+
auto [InitialPart, ScalesPart] = Arg.split(':');
109+
if (InitialPart.getAsInteger(10, Val.Initial)) {
110+
O.error("'" + Arg +
111+
"' value invalid for block-size initial_size argument");
112+
return true;
113+
}
114+
// Scales part is optional.
115+
if (ScalesPart.empty())
116+
return false;
117+
SmallVector<StringRef> Scales;
118+
ScalesPart.split(Scales, ',');
119+
for (StringRef Scale : Scales) {
120+
unsigned &ScaleVal = Val.Scales.emplace_back(0);
121+
if (Scale.getAsInteger(10, ScaleVal)) {
122+
O.error("'" + Scale + "' value invalid for block-size scale argument");
123+
return true;
124+
}
125+
}
126+
return false;
127+
}
128+
129+
cl::opt<opts::HeatmapBlockSpec, false, opts::HeatmapBlockSpecParser>
130+
HeatmapBlock(
131+
"block-size", cl::value_desc("initial_size{:pow2_scale1,...}"),
132+
cl::desc("size of a heat map block in bytes (default 64), optionally "
133+
"followed by a comma-separated list of cumulative scales "
134+
"represented as powers of 2 to produce zoomed-out heatmaps "
135+
"(default 6, 2, 6 = 4k, 16k, 1M block sizes)."),
136+
cl::init(HeatmapBlockSpec{/*Initial*/ 64, /*Scales*/ {6, 2, 6}}),
137+
cl::cat(HeatmapCategory));
110138

111139
cl::opt<unsigned long long> HeatmapMaxAddress(
112140
"max-address", cl::init(0xffffffff),

0 commit comments

Comments
 (0)