12#ifndef LLVM_PROFILEDATA_SAMPLEPROFWRITER_H
13#define LLVM_PROFILEDATA_SAMPLEPROFWRITER_H
26#include <system_error>
67 virtual void Erase(
size_t CurrentOutputSize) = 0;
71 std::vector<NameFunctionSamples> SortedFunctions;
87 void Erase(
size_t CurrentOutputSize)
override;
109 template <
typename FunctionPruningStrategy = DefaultFunctionPruningStrategy>
111 size_t OutputSizeLimit) {
137 "Unsupported format version");
153 size_t OutputSizeLimit,
203 bool MarkFlatProfiles =
false;
221 virtual std::error_code writeNameTable();
223 std::error_code writeSummary();
224 virtual std::error_code writeContextIdx(
const SampleContext &Context);
225 std::error_code writeNameIdx(
FunctionId FName);
251const std::array<SmallVector<SecHdrTableEntry, 8>,
NumOfLayout>
306 static std::pair<offset_type, offset_type>
329 :
public SampleProfileWriterBinary {
368 assert(Entry.Flags == 0 &&
369 "resetSecLayout has to be called before any flag setting");
380 template <
class SecFlagType>
383 if (Entry.Type ==
Type)
387 template <
class SecFlagType>
437 void allocSecHdrTable();
438 std::error_code writeSecHdrTable();
440 std::error_code compressAndOutput();
450 std::unique_ptr<raw_ostream> LocalBufStream;
460 std::vector<SecHdrTableEntry> SecHdrTable;
486 std::error_code writeCustomSection(
SecType Type)
override {
492 "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.
Trait class for writing the on-disk function offset hash table mapping function name GUIDs to their o...
static key_type GetInternalKey(key_type_ref Key)
static void EmitData(raw_ostream &Out, key_type_ref K, data_type_ref V, offset_type Len)
static void EmitKey(raw_ostream &Out, key_type_ref K, offset_type Len)
static bool EqualKey(key_type_ref LHS, key_type_ref RHS)
static hash_value_type ComputeHash(key_type_ref Key)
uint64_t external_key_type
uint64_t internal_key_type
static std::pair< offset_type, offset_type > EmitKeyDataLength(raw_ostream &Out, key_type_ref K, data_type_ref V)
static external_key_type GetExternalKey(internal_key_type Key)
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)
void setUseCtxSplitLayout() override
SmallVector< SecHdrTableEntry, 8 > SectionHdrLayout
void setUseMD5() override
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, uint32_t LayoutIdx, const SampleProfileMap &ProfileMap)
std::error_code writeFuncOffsetTable()
std::error_code writeCSNameTableSection()
std::error_code writeCSNameIdx(const SampleContext &Context)
virtual void verifySecLayout(SectionLayout SL)=0
void setProfileSymbolList(ProfileSymbolList *PSL) 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 writeStringBasedProfileSymbolListSection()
void resetSecLayout(SectionLayout SL)
void addSectionFlag(SecType Type, SecFlagType Flag)
std::error_code writeProfileSymbolListSection()
void setToCompressAllSections() override
void addSectionFlag(uint32_t SectionIdx, SecFlagType Flag)
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)
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()
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)
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
std::map< LineLocation, TypeCountMap > CallsiteTypeMap
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...
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
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.
Adapter to write values to a stream in a particular byte order.