36 #include <system_error> 41 using namespace sampleprof;
49 typedef std::pair<StringRef, const FunctionSamples *> NameFunctionSamples;
50 std::vector<NameFunctionSamples> V;
51 for (
const auto &
I : ProfileMap)
52 V.push_back(std::make_pair(
I.getKey(), &
I.second));
56 [](
const NameFunctionSamples &A,
const NameFunctionSamples &
B) {
57 if (A.second->getTotalSamples() ==
B.second->getTotalSamples())
58 return A.first >
B.first;
59 return A.second->getTotalSamples() >
B.second->getTotalSamples();
62 for (
const auto &
I : V) {
63 if (std::error_code EC =
write(*
I.second))
73 if (std::error_code EC = writeFuncOffsetTable())
94 for (
const auto &
I : SortedSamples.get()) {
106 OS <<
" " << J.first() <<
":" << J.second;
113 for (
const auto &
I : SortedCallsiteSamples.get())
114 for (
const auto &FS :
I->second) {
122 if (std::error_code EC =
write(CalleeSamples))
131 const auto &ret = NameTable.find(FName);
132 if (ret == NameTable.end())
138 void SampleProfileWriterBinary::addName(
StringRef FName) {
139 NameTable.insert(std::make_pair(FName, 0));
152 for (
const auto &FS : J.second) {
154 addName(CalleeSamples.
getName());
155 addNames(CalleeSamples);
161 for (
const auto &
I : NameTable)
170 std::set<StringRef> V;
171 stablizeNameTable(V);
187 uint64_t FuncOffsetTableStart = OS.
tell();
188 if (OFS.seek(TableOffset) == (uint64_t)-1)
191 Writer.
write(FuncOffsetTableStart);
192 if (OFS.seek(FuncOffsetTableStart) == (uint64_t)-1)
199 for (
auto entry : FuncOffsetTable) {
200 writeNameIdx(
entry.first);
208 std::set<StringRef> V;
209 stablizeNameTable(V);
240 if (
auto EC = writeSummary())
244 for (
const auto &
I : ProfileMap) {
262 Writer.
write(static_cast<uint64_t>(-2));
273 std::vector<ProfileSummaryEntry> &Entries =
Summary->getDetailedSummary();
275 for (
auto Entry : Entries) {
285 if (std::error_code EC = writeNameIdx(S.
getName()))
301 uint64_t CalleeSamples = J.second;
302 if (std::error_code EC = writeNameIdx(Callee))
309 uint64_t NumCallsites = 0;
311 NumCallsites += J.second.size();
314 for (
const auto &FS : J.second) {
319 if (std::error_code EC = writeBody(CalleeSamples))
353 std::unique_ptr<raw_ostream> OS;
361 return create(OS, Format);
375 std::unique_ptr<SampleProfileWriter> Writer;
391 return std::move(Writer);
397 for (
const auto &
I : ProfileMap) {
virtual std::error_code writeMagicIdent() override
Represents either an error or a value T.
This class represents lattice values for constants.
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.
virtual 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.
amdgpu Simplify well known AMD library false Value Value const Twine & Name
std::error_code writeNameIdx(StringRef FName)
virtual std::error_code writeMagicIdent() override
virtual std::error_code writeNameTable() override
Representation of a single sample record.
virtual std::error_code writeHeader(const StringMap< FunctionSamples > &ProfileMap) override
Write a file header for the profile file.
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.
virtual std::error_code write(const FunctionSamples &S) override
Write samples of a top-level function to a binary file.
virtual 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.
void write(ArrayRef< value_type > Val)
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()
Adapter to write values to a stream in a particular byte order.
A raw_ostream that writes to a file descriptor.
Represents the relative location of an instruction.
StringRef getName() const
Return the function name.
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.
uint64_t tell() const
tell - Return the current offset with the file.
print Instructions which execute on loop entry
StringRef - Represent a constant reference to a string, i.e.
std::error_code writeSummary()
std::error_code writeFuncOffsetTable()
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).