LLVM 20.0.0git
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
llvm::sampleprof::SampleProfileWriter Class Referenceabstract

Sample-based profile writer. Base class. More...

#include "llvm/ProfileData/SampleProfWriter.h"

Inheritance diagram for llvm::sampleprof::SampleProfileWriter:
Inheritance graph
[legend]

Public Member Functions

virtual ~SampleProfileWriter ()=default
 
virtual std::error_code writeSample (const FunctionSamples &S)=0
 Write sample profiles in S.
 
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 resetSecLayout (SectionLayout SL)
 

Static Public Member Functions

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.
 

Protected Member Functions

 SampleProfileWriter (std::unique_ptr< raw_ostream > &OS)
 
virtual std::error_code writeHeader (const SampleProfileMap &ProfileMap)=0
 Write a file header for the profile file.
 
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

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.
 

Detailed Description

Sample-based profile writer. Base class.

Definition at line 89 of file SampleProfWriter.h.

Constructor & Destructor Documentation

◆ ~SampleProfileWriter()

virtual llvm::sampleprof::SampleProfileWriter::~SampleProfileWriter ( )
virtualdefault

◆ SampleProfileWriter()

llvm::sampleprof::SampleProfileWriter::SampleProfileWriter ( std::unique_ptr< raw_ostream > &  OS)
inlineprotected

Definition at line 134 of file SampleProfWriter.h.

Member Function Documentation

◆ computeSummary()

void SampleProfileWriter::computeSummary ( const SampleProfileMap ProfileMap)
protected

◆ create() [1/2]

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

Create a new stream writer based on the value of Format.

Create a sample profile stream writer based on the specified format.

For testing.

Parameters
OSThe output stream to store the profile data to.
FormatEncoding format for the profile file.
Returns
an error code indicating the status of the created writer.

Definition at line 904 of file SampleProfWriter.cpp.

References Format, OS, llvm::sampleprof::FunctionSamples::ProfileIsCS, llvm::sampleprof::FunctionSamples::ProfileIsProbeBased, llvm::sampleprof::SPF_Binary, llvm::sampleprof::SPF_Ext_Binary, llvm::sampleprof::SPF_GCC, llvm::sampleprof::SPF_Text, llvm::unrecognized_format, and llvm::unsupported_writing_format.

◆ create() [2/2]

ErrorOr< std::unique_ptr< SampleProfileWriter > > SampleProfileWriter::create ( StringRef  Filename,
SampleProfileFormat  Format 
)
static

Profile writer factory.

Create a sample profile file writer based on the specified format.

Create a new file writer based on the value of Format.

Parameters
FilenameThe file to create.
FormatEncoding format for the profile file.
Returns
an error code indicating the status of the created writer.

Definition at line 883 of file SampleProfWriter.cpp.

References create(), Format, llvm::sys::fs::OF_None, llvm::sys::fs::OF_TextWithCRLF, OS, llvm::sampleprof::SPF_Binary, and llvm::sampleprof::SPF_Ext_Binary.

Referenced by create().

◆ getOutputStream()

raw_ostream & llvm::sampleprof::SampleProfileWriter::getOutputStream ( )
inline

Definition at line 114 of file SampleProfWriter.h.

References OutputStream.

◆ resetSecLayout()

virtual void llvm::sampleprof::SampleProfileWriter::resetSecLayout ( SectionLayout  SL)
inlinevirtual

Reimplemented in llvm::sampleprof::SampleProfileWriterExtBinaryBase.

Definition at line 131 of file SampleProfWriter.h.

◆ setPartialProfile()

virtual void llvm::sampleprof::SampleProfileWriter::setPartialProfile ( )
inlinevirtual

Reimplemented in llvm::sampleprof::SampleProfileWriterExtBinaryBase.

Definition at line 130 of file SampleProfWriter.h.

◆ setProfileSymbolList()

virtual void llvm::sampleprof::SampleProfileWriter::setProfileSymbolList ( ProfileSymbolList PSL)
inlinevirtual

Reimplemented in llvm::sampleprof::SampleProfileWriterExtBinaryBase.

Definition at line 127 of file SampleProfWriter.h.

◆ setToCompressAllSections()

virtual void llvm::sampleprof::SampleProfileWriter::setToCompressAllSections ( )
inlinevirtual

Reimplemented in llvm::sampleprof::SampleProfileWriterExtBinaryBase.

Definition at line 128 of file SampleProfWriter.h.

◆ setUseMD5()

virtual void llvm::sampleprof::SampleProfileWriter::setUseMD5 ( )
inlinevirtual

Reimplemented in llvm::sampleprof::SampleProfileWriterExtBinaryBase.

Definition at line 129 of file SampleProfWriter.h.

◆ write()

std::error_code SampleProfileWriter::write ( const SampleProfileMap ProfileMap)
virtual

Write all the sample profiles in the given map of samples.

Returns
status code of the file update operation.

Reimplemented in llvm::sampleprof::SampleProfileWriterExtBinaryBase.

Definition at line 153 of file SampleProfWriter.cpp.

References llvm::success, writeFuncProfiles(), and writeHeader().

Referenced by writeWithSizeLimitInternal().

◆ writeFuncProfiles()

std::error_code SampleProfileWriter::writeFuncProfiles ( const SampleProfileMap ProfileMap)
protectedvirtual

◆ writeHeader()

virtual std::error_code llvm::sampleprof::SampleProfileWriter::writeHeader ( const SampleProfileMap ProfileMap)
protectedpure virtual

Write a file header for the profile file.

Implemented in llvm::sampleprof::SampleProfileWriterText, and llvm::sampleprof::SampleProfileWriterBinary.

Referenced by write().

◆ writeSample()

virtual std::error_code llvm::sampleprof::SampleProfileWriter::writeSample ( const FunctionSamples S)
pure virtual

Write sample profiles in S.

Returns
status code of the file update operation.

Implemented in llvm::sampleprof::SampleProfileWriterText, llvm::sampleprof::SampleProfileWriterBinary, and llvm::sampleprof::SampleProfileWriterExtBinaryBase.

Referenced by writeFuncProfiles().

◆ writeWithSizeLimit()

template<typename FunctionPruningStrategy = DefaultFunctionPruningStrategy>
std::error_code llvm::sampleprof::SampleProfileWriter::writeWithSizeLimit ( SampleProfileMap ProfileMap,
size_t  OutputSizeLimit 
)
inline

Write sample profiles up to given size limit, using the pruning strategy to drop some functions if necessary.

Returns
status code of the file update operation.

Definition at line 108 of file SampleProfWriter.h.

References writeWithSizeLimitInternal().

◆ writeWithSizeLimitInternal()

std::error_code SampleProfileWriter::writeWithSizeLimitInternal ( SampleProfileMap ProfileMap,
size_t  OutputSizeLimit,
FunctionPruningStrategy Strategy 
)
protected

Member Data Documentation

◆ Format

SampleProfileFormat llvm::sampleprof::SampleProfileWriter::Format = SPF_None
protected

◆ LineCount

size_t llvm::sampleprof::SampleProfileWriter::LineCount
protected

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.

This needs to be accounted for when rewriting the profile.

Definition at line 150 of file SampleProfWriter.h.

Referenced by llvm::sampleprof::SampleProfileWriterText::writeHeader(), llvm::sampleprof::SampleProfileWriterText::writeSample(), and writeWithSizeLimitInternal().

◆ OutputStream

std::unique_ptr<raw_ostream> llvm::sampleprof::SampleProfileWriter::OutputStream
protected

◆ Summary

std::unique_ptr<ProfileSummary> llvm::sampleprof::SampleProfileWriter::Summary
protected

Profile summary.

Definition at line 156 of file SampleProfWriter.h.

Referenced by computeSummary(), and llvm::sampleprof::SampleProfileWriterBinary::writeSummary().


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