33 #include <system_error>
38 using namespace sampleprof;
46 typedef std::pair<StringRef, const FunctionSamples *> NameFunctionSamples;
47 std::vector<NameFunctionSamples> V;
48 for (
const auto &
I : ProfileMap)
49 V.push_back(std::make_pair(
I.getKey(), &
I.second));
53 [](
const NameFunctionSamples &
A,
const NameFunctionSamples &
B) {
54 if (A.second->getTotalSamples() ==
B.second->getTotalSamples())
55 return A.first >
B.first;
56 return A.second->getTotalSamples() >
B.second->getTotalSamples();
59 for (
const auto &
I : V) {
60 if (std::error_code EC =
write(*
I.second))
82 for (
const auto &
I : SortedSamples.get()) {
85 OS.indent(Indent + 1);
94 OS <<
" " << J.first() <<
":" << J.second;
101 for (
const auto &
I : SortedCallsiteSamples.get())
102 for (
const auto &FS :
I->second) {
110 if (std::error_code EC =
write(CalleeSamples))
119 const auto &ret = NameTable.find(FName);
120 if (ret == NameTable.end())
126 void SampleProfileWriterBinary::addName(
StringRef FName) {
127 NameTable.insert(std::make_pair(FName, 0));
140 for (
const auto &FS : J.second) {
142 addName(CalleeSamples.
getName());
143 addNames(CalleeSamples);
160 for (
const auto &
I : ProfileMap) {
166 std::set<StringRef> V;
167 for (
const auto &
I : NameTable)
189 std::vector<ProfileSummaryEntry> &Entries =
Summary->getDetailedSummary();
191 for (
auto Entry : Entries) {
217 uint64_t CalleeSamples = J.second;
227 for (
const auto &FS : J.second) {
232 if (std::error_code EC =
writeBody(CalleeSamples))
259 std::unique_ptr<raw_ostream> OS;
267 return create(OS, Format);
283 std::unique_ptr<SampleProfileWriter> Writer;
297 return std::move(Writer);
303 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.
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.
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.
std::unique_ptr< ProfileSummary > Summary
Profile summary.
uint64_t getTotalSamples() const
Return the total number of samples collected inside the function.
Sample-based profile writer (binary format).
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)=0
Write sample profiles in S.
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.
virtual std::error_code writeHeader(const StringMap< FunctionSamples > &ProfileMap)=0
Write a file header for the profile file.
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).