Skip to content

Commit d65fbe4

Browse files
committed
[𝘀𝗽𝗿] initial version
Created using spr 1.3.4
2 parents 54aa16d + ced7a93 commit d65fbe4

File tree

14 files changed

+263
-216
lines changed

14 files changed

+263
-216
lines changed

bolt/include/bolt/Core/BinaryFunction.h

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -386,8 +386,8 @@ class BinaryFunction {
386386
/// Profile match ratio.
387387
float ProfileMatchRatio{0.0f};
388388

389-
/// Raw branch count for this function in the profile.
390-
uint64_t RawBranchCount{0};
389+
/// Raw sample/branch count for this function in the profile.
390+
uint64_t RawSampleCount{0};
391391

392392
/// Dynamically executed function bytes, used for density computation.
393393
uint64_t SampleCountInBytes{0};
@@ -1880,13 +1880,12 @@ class BinaryFunction {
18801880
/// Return COUNT_NO_PROFILE if there's no profile info.
18811881
uint64_t getExecutionCount() const { return ExecutionCount; }
18821882

1883-
/// Return the raw profile information about the number of branch
1884-
/// executions corresponding to this function.
1885-
uint64_t getRawBranchCount() const { return RawBranchCount; }
1883+
/// Return the raw profile information about the number of samples (basic
1884+
/// profile) or branch executions (branch profile) recorded in this function.
1885+
uint64_t getRawSampleCount() const { return RawSampleCount; }
18861886

1887-
/// Set the profile data about the number of branch executions corresponding
1888-
/// to this function.
1889-
void setRawBranchCount(uint64_t Count) { RawBranchCount = Count; }
1887+
/// Set raw count of samples or branches recorded in this function.
1888+
void setRawSampleCount(uint64_t Count) { RawSampleCount = Count; }
18901889

18911890
/// Return the number of dynamically executed bytes, from raw perf data.
18921891
uint64_t getSampleCountInBytes() const { return SampleCountInBytes; }

bolt/include/bolt/Profile/DataAggregator.h

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,6 @@ class DataAggregator : public DataReader {
9292
uint64_t Addr;
9393
};
9494

95-
/// Used for parsing specific pre-aggregated input files.
96-
struct AggregatedLBREntry {
97-
enum Type : char { BRANCH = 0, FT, FT_EXTERNAL_ORIGIN, TRACE };
98-
Location From;
99-
Location To;
100-
uint64_t Count;
101-
uint64_t Mispreds;
102-
Type EntryType;
103-
};
104-
10595
struct Trace {
10696
uint64_t From;
10797
uint64_t To;
@@ -131,7 +121,6 @@ class DataAggregator : public DataReader {
131121
/// and use them later for processing and assigning profile.
132122
std::unordered_map<Trace, TakenBranchInfo, TraceHash> BranchLBRs;
133123
std::unordered_map<Trace, FTInfo, TraceHash> FallthroughLBRs;
134-
std::vector<AggregatedLBREntry> AggregatedLBRs;
135124
std::unordered_map<uint64_t, uint64_t> BasicSamples;
136125
std::vector<PerfMemSample> MemSamples;
137126

@@ -416,14 +405,7 @@ class DataAggregator : public DataReader {
416405
/// F 41be90 41be90 4
417406
/// B 4b1942 39b57f0 3 0
418407
/// B 4b196f 4b19e0 2 0
419-
void parsePreAggregated();
420-
421-
/// Parse the full output of pre-aggregated LBR samples generated by
422-
/// an external tool.
423-
std::error_code parsePreAggregatedLBRSamples();
424-
425-
/// Process parsed pre-aggregated data.
426-
void processPreAggregated();
408+
std::error_code parsePreAggregated();
427409

428410
/// If \p Address falls into the binary address space based on memory
429411
/// mapping info \p MMI, then adjust it for further processing by subtracting

bolt/include/bolt/Profile/DataReader.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,9 @@ struct FuncSampleData {
252252
/// Get the number of samples recorded in [Start, End)
253253
uint64_t getSamples(uint64_t Start, uint64_t End) const;
254254

255+
/// Returns the total number of samples recorded in this function.
256+
uint64_t getSamples() const;
257+
255258
/// Aggregation helper
256259
DenseMap<uint64_t, size_t> Index;
257260

bolt/include/bolt/Profile/Heatmap.h

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
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
};

bolt/lib/Core/BinaryFunction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ void BinaryFunction::print(raw_ostream &OS, std::string Annotation) {
473473
OS << "\n Image : 0x" << Twine::utohexstr(getImageAddress());
474474
if (ExecutionCount != COUNT_NO_PROFILE) {
475475
OS << "\n Exec Count : " << ExecutionCount;
476-
OS << "\n Branch Count: " << RawBranchCount;
476+
OS << "\n Branch Count: " << RawSampleCount;
477477
OS << "\n Profile Acc : " << format("%.1f%%", ProfileMatchRatio * 100.0f);
478478
}
479479

bolt/lib/Passes/BinaryPasses.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1445,7 +1445,7 @@ Error PrintProgramStats::runOnFunctions(BinaryContext &BC) {
14451445
if (!Function.hasProfile())
14461446
continue;
14471447

1448-
uint64_t SampleCount = Function.getRawBranchCount();
1448+
uint64_t SampleCount = Function.getRawSampleCount();
14491449
TotalSampleCount += SampleCount;
14501450

14511451
if (Function.hasValidProfile()) {

0 commit comments

Comments
 (0)