12#ifndef LLVM_PROFILEDATA_SAMPLEPROFWRITER_H
13#define LLVM_PROFILEDATA_SAMPLEPROFWRITER_H
25#include <system_error>
66 virtual void Erase(
size_t CurrentOutputSize) = 0;
70 std::vector<NameFunctionSamples> SortedFunctions;
86 void Erase(
size_t CurrentOutputSize)
override;
108 template <
typename FunctionPruningStrategy = DefaultFunctionPruningStrategy>
110 size_t OutputSizeLimit) {
138 "Unsupported format version");
154 size_t OutputSizeLimit,
204 bool MarkFlatProfiles =
false;
222 virtual std::error_code writeNameTable();
224 std::error_code writeSummary();
225 virtual std::error_code writeContextIdx(
const SampleContext &Context);
226 std::error_code writeNameIdx(
FunctionId FName);
252const std::array<SmallVector<SecHdrTableEntry, 8>,
NumOfLayout>
287 :
public SampleProfileWriterBinary {
330 assert(Entry.Flags == 0 &&
331 "resetSecLayout has to be called before any flag setting");
342 template <
class SecFlagType>
345 if (Entry.Type ==
Type)
401 void allocSecHdrTable();
402 std::error_code writeSecHdrTable();
404 std::error_code compressAndOutput();
414 std::unique_ptr<raw_ostream> LocalBufStream;
424 std::vector<SecHdrTableEntry> SecHdrTable;
433 bool UseMD5ProfSymList =
false;
436 bool UseMD5IndexedTables =
false;
437 size_t NumNested = 0;
458 std::error_code writeCustomSection(
SecType Type)
override {
464 "Unsupported layout");
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
Provides ErrorOr<T> smart pointer.
This file defines the EytzingerTableSpan class, a non-owning view of a buffer formatted as a complete...
This file implements a map that provides insertion order iteration.
static constexpr StringLiteral Filename
static void write(bool isBE, void *P, T V)
Represents either an error or a value T.
This class implements a map that also provides access to all stored values in a deterministic order.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Represent a constant reference to a string, i.e.
The instances of the Type class are immutable: once they are created, they are never changed.
This class implements an extremely fast bulk output stream that can only output to a stream.
DefaultFunctionPruningStrategy(SampleProfileMap &ProfileMap, size_t OutputSizeLimit)
void Erase(size_t CurrentOutputSize) override
In this default implementation, functions with fewest samples are dropped first.
This class represents a function that is read from a sample profile.
When writing a profile with size limit, user may want to use a different strategy to reduce function ...
virtual void Erase(size_t CurrentOutputSize)=0
SampleProfileWriter::writeWithSizeLimit() calls this after every write iteration if the output size s...
virtual ~FunctionPruningStrategy()=default
FunctionPruningStrategy(SampleProfileMap &ProfileMap, size_t OutputSizeLimit)
ProfileMap A reference to the original profile map.
SampleProfileMap & ProfileMap
Representation of the samples collected for a function.
ProfileSymbolList records the list of function symbols shown up in the binary used to generate the pr...
This class provides operator overloads to the map container using MD5 as the key type,...
SampleProfileWriterBinary(std::unique_ptr< raw_ostream > &OS)
virtual void addContext(const SampleContext &Context)
MapVector< FunctionId, uint32_t > NameTable
void addNames(const FunctionSamples &S)
std::error_code writeCallsiteVTableProf(const CallsiteTypeMap &CallsiteTypeMap, raw_ostream &OS)
Write CallsiteTypeMap to the output stream OS.
virtual MapVector< FunctionId, uint32_t > & getNameTable()
void addName(FunctionId FName)
std::error_code writeNameTableSection(const SampleProfileMap &ProfileMap)
unsigned findUnwrittenEntry(SecType Type)
void setUseCtxSplitLayout() override
SmallVector< SecHdrTableEntry, 8 > SectionHdrLayout
void setUseMD5() override
std::error_code writeFuncOffsetTable(bool IsNested)
std::error_code writeFuncMetadata(const SampleProfileMap &Profiles)
void setToCompressSection(SecType Type)
virtual std::error_code writeCustomSection(SecType Type)=0
virtual std::error_code writeOneSection(SecType Type, const SampleProfileMap &ProfileMap)
void setUseMD5ProfileSymbolList() override
std::error_code writeCSNameTableSection()
std::error_code writeCSNameIdx(const SampleContext &Context)
virtual void verifySecLayout(SectionLayout SL)=0
void setProfileSymbolList(ProfileSymbolList *PSL) override
void setUseMD5IndexedTables() override
void setPartialProfile() override
virtual std::error_code writeSections(const SampleProfileMap &ProfileMap)=0
std::error_code writeNameTable() override
std::error_code writeMD5ProfileSymbolListSection()
std::error_code writeLegacyFuncOffsetTable()
std::error_code writeStringBasedProfileSymbolListSection()
void resetSecLayout(SectionLayout SL)
void addSectionFlag(SecType Type, SecFlagType Flag)
std::error_code writeProfileSymbolListSection()
std::error_code writeEytzingerFuncOffsetTable(bool IsNested)
void setToCompressAllSections() override
std::error_code writeEytzingerNameTableSection(const SampleProfileMap &ProfileMap)
uint64_t SecLBRProfileStart
std::error_code writeContextIdx(const SampleContext &Context) override
std::error_code writeSample(const FunctionSamples &S) override
Write samples of a top-level function to a binary file.
SampleProfileWriterExtBinary(std::unique_ptr< raw_ostream > &OS)
SampleProfileWriterText(std::unique_ptr< raw_ostream > &OS)
std::error_code writeHeader(const SampleProfileMap &ProfileMap) override
Write a file header for the profile file.
void setUseCtxSplitLayout() override
std::error_code writeSample(const FunctionSamples &S) override
Write samples to a text file.
virtual void setUseCtxSplitLayout()
SampleProfileWriter(std::unique_ptr< raw_ostream > &OS)
std::unique_ptr< ProfileSummary > Summary
Profile summary.
virtual std::error_code writeSample(const FunctionSamples &S)=0
Write sample profiles in S.
SampleProfileFormat Format
Profile format.
std::error_code writeWithSizeLimitInternal(SampleProfileMap &ProfileMap, size_t OutputSizeLimit, FunctionPruningStrategy *Strategy)
virtual void setUseMD5ProfileSymbolList()
raw_ostream & getOutputStream()
void computeSummary(const SampleProfileMap &ProfileMap)
Compute summary for this profile.
virtual void setPartialProfile()
virtual std::error_code writeFuncProfiles(const SampleProfileMap &ProfileMap)
std::unique_ptr< raw_ostream > OutputStream
Output stream where to emit the profile to.
virtual void setToCompressAllSections()
virtual void setUseMD5IndexedTables()
std::error_code writeWithSizeLimit(SampleProfileMap &ProfileMap, size_t OutputSizeLimit)
Write sample profiles up to given size limit, using the pruning strategy to drop some functions if ne...
virtual void setProfileSymbolList(ProfileSymbolList *PSL)
uint64_t getFormatVersion() const
uint64_t FormatVersion
Format version to write.
size_t LineCount
For writeWithSizeLimit in text mode, each newline takes 1 additional byte on Windows when actually wr...
static ErrorOr< std::unique_ptr< SampleProfileWriter > > create(StringRef Filename, SampleProfileFormat Format)
Profile writer factory.
virtual std::error_code writeHeader(const SampleProfileMap &ProfileMap)=0
Write a file header for the profile file.
void setFormatVersion(uint64_t V)
virtual ~SampleProfileWriter()=default
static bool formatVersionIsSupported(uint64_t Version)
SortedVectorMap< LineLocation, TypeCountMap, 0 > CallsiteTypeMap
static void addSecFlag(SecHdrTableEntry &Entry, SecFlagType Flag)
const std::array< SmallVector< SecHdrTableEntry, 8 >, NumOfLayout > ExtBinaryHdrLayoutTable
@ SecFlagPartial
SecFlagPartial means the profile is for common/shared code.
static constexpr uint64_t DefaultVersion
This is an optimization pass for GlobalISel generic memory operations.
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Implement std::hash so that hash_code can be used in STL containers.