34 #include <system_error> 39 using namespace sampleprof;
47 typedef std::pair<StringRef, const FunctionSamples *> NameFunctionSamples;
48 std::vector<NameFunctionSamples> V;
49 for (
const auto &
I : ProfileMap)
50 V.push_back(std::make_pair(
I.getKey(), &
I.second));
54 [](
const NameFunctionSamples &A,
const NameFunctionSamples &
B) {
55 if (A.second->getTotalSamples() ==
B.second->getTotalSamples())
56 return A.first >
B.first;
57 return A.second->getTotalSamples() >
B.second->getTotalSamples();
60 for (
const auto &
I : V) {
61 if (std::error_code EC =
write(*
I.second))
83 for (
const auto &
I : SortedSamples.get()) {
95 OS <<
" " << J.first() <<
":" << J.second;
102 for (
const auto &
I : SortedCallsiteSamples.get())
103 for (
const auto &FS :
I->second) {
111 if (std::error_code EC =
write(CalleeSamples))
120 const auto &ret = NameTable.find(FName);
121 if (ret == NameTable.end())
127 void SampleProfileWriterBinary::addName(
StringRef FName) {
128 NameTable.insert(std::make_pair(FName, 0));
141 for (
const auto &FS : J.second) {
143 addName(CalleeSamples.
getName());
144 addNames(CalleeSamples);
150 for (
const auto &
I : NameTable)
159 std::set<StringRef> V;
160 stablizeNameTable(V);
173 std::set<StringRef> V;
174 stablizeNameTable(V);
205 if (
auto EC = writeSummary())
209 for (
const auto &
I : ProfileMap) {
225 std::vector<ProfileSummaryEntry> &Entries =
Summary->getDetailedSummary();
227 for (
auto Entry : Entries) {
237 if (std::error_code EC = writeNameIdx(S.
getName()))
253 uint64_t CalleeSamples = J.second;
254 if (std::error_code EC = writeNameIdx(Callee))
261 uint64_t NumCallsites = 0;
263 NumCallsites += J.second.size();
266 for (
const auto &FS : J.second) {
271 if (std::error_code EC = writeBody(CalleeSamples))
296 std::unique_ptr<raw_ostream> OS;
304 return create(OS, Format);
318 std::unique_ptr<SampleProfileWriter> Writer;
334 return std::move(Writer);
340 for (
const auto &
I : ProfileMap) {
virtual std::error_code writeMagicIdent() override
Represents either an error or a value T.
Compute iterated dominance frontiers using a linear time algorithm.
uint64_t MD5Hash(StringRef Str)
Helper to compute and return lower 64 bits of the given string's MD5 hash.
std::unique_ptr< raw_ostream > OutputStream
Output stream where to emit the profile to.
static const ArrayRef< uint32_t > DefaultCutoffs
A vector of useful cutoff values for detailed summary.
const StringRef & getName() const
Return the function name.
std::error_code writeHeader(const StringMap< FunctionSamples > &ProfileMap) override
Write a file header for the profile file.
Representation of the samples collected for a function.
std::error_code writeNameIdx(StringRef FName)
virtual std::error_code writeMagicIdent() override
virtual std::error_code writeNameTable() override
Representation of a single sample record.
static uint64_t SPVersion()
amdgpu Simplify well known AMD library false Value * Callee
Sort a LocationT->SampleT map by LocationT.
uint64_t getHeadSamples() const
Return the total number of branch samples that have the function as the branch target.
virtual std::error_code writeNameTable() override
std::unique_ptr< ProfileSummary > Summary
Profile summary.
uint64_t getSamples() const
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
const BodySampleMap & getBodySamples() const
Return all the samples collected in the body of the function.
std::error_code write(const FunctionSamples &S) override
Write samples of a top-level function to a binary file.
void stablizeNameTable(std::set< StringRef > &V)
virtual std::error_code write(const FunctionSamples &S)=0
Write sample profiles in S.
unsigned encodeULEB128(uint64_t Value, raw_ostream &OS, unsigned PadTo=0)
Utility function to encode a ULEB128 value to an output stream.
static ErrorOr< std::unique_ptr< SampleProfileWriter > > create(StringRef Filename, SampleProfileFormat Format)
Profile writer factory.
void addRecord(const sampleprof::FunctionSamples &FS)
StringMap - This is an unconventional map that is specialized for handling keys that are "strings"...
std::error_code writeBody(const FunctionSamples &S)
std::unique_ptr< ProfileSummary > getSummary()
A raw_ostream that writes to a file descriptor.
Represents the relative location of an instruction.
const CallTargetMap & getCallTargets() const
static uint64_t SPMagic(SampleProfileFormat Format=SPF_Binary)
Provides ErrorOr<T> smart pointer.
virtual std::error_code writeHeader(const StringMap< FunctionSamples > &ProfileMap)=0
Write a file header for the profile file.
uint64_t getTotalSamples() const
Return the total number of samples collected inside the function.
const CallsiteSampleMap & getCallsiteSamples() const
Return all the callsite samples collected in the body of the function.
StringRef - Represent a constant reference to a string, i.e.
std::error_code writeSummary()
void computeSummary(const StringMap< FunctionSamples > &ProfileMap)
Compute summary for this profile.
std::error_code write(const FunctionSamples &S) override
Write samples to a text file.
Sample-based profile writer (text format).