29 using namespace llvm::sampleprof;
41 auto &OS = *OutputStream;
48 for (
const auto &
I : SortedSamples.get()) {
51 OS.indent(Indent + 1);
60 OS <<
" " << J.first() <<
":" << J.second;
67 for (
const auto &
I : SortedCallsiteSamples.get()) {
75 if (std::error_code EC =
write(CalleeSamples))
84 const auto &ret = NameTable.find(FName);
85 if (ret == NameTable.end())
91 void SampleProfileWriterBinary::addName(
StringRef FName) {
92 auto NextIdx = NameTable.size();
93 NameTable.insert(std::make_pair(FName, NextIdx));
107 addName(CalleeSamples.
getName());
108 addNames(CalleeSamples);
114 auto &OS = *OutputStream;
120 computeSummary(ProfileMap);
121 if (
auto EC = writeSummary())
125 for (
const auto &
I : ProfileMap) {
132 for (
auto N : NameTable) {
140 auto &OS = *OutputStream;
146 std::vector<ProfileSummaryEntry> &Entries = Summary->getDetailedSummary();
148 for (
auto Entry : Entries) {
156 auto &OS = *OutputStream;
158 if (std::error_code EC = writeNameIdx(S.
getName()))
174 uint64_t CalleeSamples = J.second;
175 if (std::error_code EC = writeNameIdx(Callee))
188 if (std::error_code EC = writeBody(CalleeSamples))
215 std::unique_ptr<raw_ostream> OS;
223 return create(OS, Format);
239 std::unique_ptr<SampleProfileWriter> Writer;
253 return std::move(Writer);
259 for (
const auto &
I : ProfileMap) {
Represents either an error or a value T.
const BodySampleMap & getBodySamples() const
Return all the samples collected in the body of the function.
static const ArrayRef< uint32_t > DefaultCutoffs
A vector of useful cutoff values for detailed summary.
const StringRef & getName() const
Return the function name.
const CallTargetMap & getCallTargets() const
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)
uint64_t getHeadSamples() const
Return the total number of samples collected at the head of the function.
Representation of a single sample record.
static uint64_t SPVersion()
Sort a LocationT->SampleT map by LocationT.
uint64_t getTotalSamples() const
Return the total number of samples collected inside the function.
Sample-based profile writer (binary format).
static void write(bool isBE, void *P, T V)
std::error_code write(const FunctionSamples &S) override
Write samples of a top-level function to a binary file.
const CallsiteSampleMap & getCallsiteSamples() const
Return all the callsite samples collected in the body of the function.
uint64_t getSamples() const
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)
The file should be opened in text mode on platforms that make this distinction.
std::unique_ptr< ProfileSummary > getSummary()
static uint64_t SPMagic()
A raw_ostream that writes to a file descriptor.
Represents the relative location of an instruction.
Provides ErrorOr<T> smart pointer.
void encodeULEB128(uint64_t Value, raw_ostream &OS, unsigned Padding=0)
Utility function to encode a ULEB128 value to an output stream.
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).