LLVM 24.0.0git
llvm::sampleprof::SampleProfileWriterBinary Class Reference

Sample-based profile writer (binary format). More...

#include "llvm/ProfileData/SampleProfWriter.h"

Inheritance diagram for llvm::sampleprof::SampleProfileWriterBinary:
[legend]

Public Member Functions

 SampleProfileWriterBinary (std::unique_ptr< raw_ostream > &OS)
std::error_code writeSample (const FunctionSamples &S) override
 Write samples of a top-level function to a binary file.
Public Member Functions inherited from llvm::sampleprof::SampleProfileWriter
virtual ~SampleProfileWriter ()=default
virtual std::error_code write (const SampleProfileMap &ProfileMap)
 Write all the sample profiles in the given map of samples.
template<typename FunctionPruningStrategy = DefaultFunctionPruningStrategy>
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 necessary.
raw_ostreamgetOutputStream ()
virtual void setProfileSymbolList (ProfileSymbolList *PSL)
virtual void setToCompressAllSections ()
virtual void setUseMD5 ()
virtual void setPartialProfile ()
virtual void setUseCtxSplitLayout ()
virtual void setUseMD5ProfileSymbolList ()
virtual void setUseMD5IndexedTables ()
virtual void setUseCompositeProfile (bool)
void setFormatVersion (uint64_t V)
uint64_t getFormatVersion () const

Protected Member Functions

virtual MapVector< FunctionId, uint32_t > & getNameTable ()
virtual std::error_code writeMagicIdent (SampleProfileFormat Format)
virtual std::error_code writeNameTable ()
std::error_code writeHeader (const SampleProfileMap &ProfileMap) override
 Write a file header for the profile file.
std::error_code writeSummary ()
virtual std::error_code writeContextIdx (const SampleContext &Context)
std::error_code writeNameIdx (FunctionId FName)
std::error_code writeBody (const FunctionSamples &S, bool IsNested)
std::error_code writeLBRProfile (const FunctionSamples &S, bool IsNested)
std::error_code writeCompositeProfile (const FunctionSamples &S, bool IsNested)
 Interfaces for composite profile writing.
std::error_code writeProfileType (ProfTypes Type, function_ref< std::error_code()> WritePayload)
 Write one Type and the size-prefixed payload emitted by WritePayload.
void addName (FunctionId FName)
virtual void addContext (const SampleContext &Context)
void addNames (const FunctionSamples &S)
std::error_code writeCallsiteVTableProf (const CallsiteTypeMap &CallsiteTypeMap, raw_ostream &OS)
 Write CallsiteTypeMap to the output stream OS.
Protected Member Functions inherited from llvm::sampleprof::SampleProfileWriter
 SampleProfileWriter (std::unique_ptr< raw_ostream > &OS)
virtual std::error_code writeFuncProfiles (const SampleProfileMap &ProfileMap)
std::error_code writeWithSizeLimitInternal (SampleProfileMap &ProfileMap, size_t OutputSizeLimit, FunctionPruningStrategy *Strategy)
void computeSummary (const SampleProfileMap &ProfileMap)
 Compute summary for this profile.

Protected Attributes

std::unique_ptr< raw_ostreamPayloadSizeStream
 Reusable stream that counts payload bytes without retaining them.
bool WritingProfileType = false
 Whether a profile payload callback is currently being executed.
MapVector< FunctionId, uint32_tNameTable
bool WriteVTableProf = false
bool WriteCompositeProf = false
Protected Attributes inherited from llvm::sampleprof::SampleProfileWriter
size_t LineCount
 For writeWithSizeLimit in text mode, each newline takes 1 additional byte on Windows when actually written to the file, but not written to a memory buffer.
std::unique_ptr< raw_ostreamOutputStream
 Output stream where to emit the profile to.
std::unique_ptr< ProfileSummarySummary
 Profile summary.
SampleProfileFormat Format = SPF_None
 Profile format.
uint64_t FormatVersion = sampleprof::DefaultVersion
 Format version to write.

Friends

LLVM_ABI friend ErrorOr< std::unique_ptr< SampleProfileWriter > > SampleProfileWriter::create (std::unique_ptr< raw_ostream > &OS, SampleProfileFormat Format)

Additional Inherited Members

Static Public Member Functions inherited from llvm::sampleprof::SampleProfileWriter
static ErrorOr< std::unique_ptr< SampleProfileWriter > > create (StringRef Filename, SampleProfileFormat Format)
 Profile writer factory.
static ErrorOr< std::unique_ptr< SampleProfileWriter > > create (std::unique_ptr< raw_ostream > &OS, SampleProfileFormat Format)
 Create a new stream writer based on the value of Format.

Detailed Description

Sample-based profile writer (binary format).

Definition at line 214 of file SampleProfWriter.h.

Constructor & Destructor Documentation

◆ SampleProfileWriterBinary()

llvm::sampleprof::SampleProfileWriterBinary::SampleProfileWriterBinary ( std::unique_ptr< raw_ostream > & OS)
inline

Member Function Documentation

◆ addContext()

void SampleProfileWriterBinary::addContext ( const SampleContext & Context)
protectedvirtual

Reimplemented in llvm::sampleprof::SampleProfileWriterExtBinaryBase.

Definition at line 911 of file SampleProfWriter.cpp.

References addName().

Referenced by writeHeader().

◆ addName()

void SampleProfileWriterBinary::addName ( FunctionId FName)
protected

◆ addNames()

◆ getNameTable()

virtual MapVector< FunctionId, uint32_t > & llvm::sampleprof::SampleProfileWriterBinary::getNameTable ( )
inlineprotectedvirtual

Definition at line 222 of file SampleProfWriter.h.

References NameTable.

Referenced by addName(), writeCallsiteVTableProf(), writeLBRProfile(), and writeNameIdx().

◆ writeBody()

◆ writeCallsiteVTableProf()

std::error_code SampleProfileWriterBinary::writeCallsiteVTableProf ( const CallsiteTypeMap & CallsiteTypeMap,
raw_ostream & OS )
protected

Write CallsiteTypeMap to the output stream OS.

Definition at line 1072 of file SampleProfWriter.cpp.

References assert(), llvm::encodeULEB128(), getNameTable(), llvm::sampleprof::serializeTypeMap(), llvm::success, and WriteVTableProf.

Referenced by writeBody().

◆ writeCompositeProfile()

std::error_code SampleProfileWriterBinary::writeCompositeProfile ( const FunctionSamples & S,
bool IsNested )
protected

◆ writeContextIdx()

std::error_code SampleProfileWriterBinary::writeContextIdx ( const SampleContext & Context)
protectedvirtual

Reimplemented in llvm::sampleprof::SampleProfileWriterExtBinaryBase.

Definition at line 892 of file SampleProfWriter.cpp.

References assert(), and writeNameIdx().

Referenced by writeBody().

◆ writeHeader()

std::error_code SampleProfileWriterBinary::writeHeader ( const SampleProfileMap & ProfileMap)
overrideprotectedvirtual

◆ writeLBRProfile()

◆ writeMagicIdent()

◆ writeNameIdx()

◆ writeNameTable()

std::error_code SampleProfileWriterBinary::writeNameTable ( )
protectedvirtual

◆ writeProfileType()

std::error_code SampleProfileWriterBinary::writeProfileType ( ProfTypes Type,
function_ref< std::error_code()> WritePayload )
protected

Write one Type and the size-prefixed payload emitted by WritePayload.

The callback is invoked once to count its bytes and again to emit them, so both calls must produce identical output without external side effects.

Definition at line 1168 of file SampleProfWriter.cpp.

References llvm::encodeULEB128(), llvm::malformed, llvm::sampleprof::SampleProfileWriter::OutputStream, PayloadSizeStream, llvm::success, llvm::raw_ostream::tell(), llvm::too_large, and WritingProfileType.

Referenced by writeCompositeProfile().

◆ writeSample()

std::error_code SampleProfileWriterBinary::writeSample ( const FunctionSamples & S)
overridevirtual

Write samples of a top-level function to a binary file.

Returns
true if the samples were written successfully, false otherwise.

Implements llvm::sampleprof::SampleProfileWriter.

Reimplemented in llvm::sampleprof::SampleProfileWriterExtBinaryBase.

Definition at line 1268 of file SampleProfWriter.cpp.

References llvm::encodeULEB128(), llvm::sampleprof::FunctionSamples::getHeadSamples(), llvm::sampleprof::SampleProfileWriter::OutputStream, and writeBody().

◆ writeSummary()

◆ SampleProfileWriter::create

Member Data Documentation

◆ NameTable

◆ PayloadSizeStream

std::unique_ptr<raw_ostream> llvm::sampleprof::SampleProfileWriterBinary::PayloadSizeStream
protected

Reusable stream that counts payload bytes without retaining them.

Definition at line 243 of file SampleProfWriter.h.

Referenced by writeProfileType().

◆ WriteCompositeProf

bool llvm::sampleprof::SampleProfileWriterBinary::WriteCompositeProf = false
protected

◆ WriteVTableProf

bool llvm::sampleprof::SampleProfileWriterBinary::WriteVTableProf = false
protected

◆ WritingProfileType

bool llvm::sampleprof::SampleProfileWriterBinary::WritingProfileType = false
protected

Whether a profile payload callback is currently being executed.

Definition at line 245 of file SampleProfWriter.h.

Referenced by writeProfileType().


The documentation for this class was generated from the following files: