LLVM  4.0.0
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
llvm::sampleprof::SampleProfileReader Class Referenceabstract

Sample-based profile reader. More...

#include <SampleProfReader.h>

Inheritance diagram for llvm::sampleprof::SampleProfileReader:
[legend]
Collaboration diagram for llvm::sampleprof::SampleProfileReader:
[legend]

Public Member Functions

 SampleProfileReader (std::unique_ptr< MemoryBuffer > B, LLVMContext &C)
 
virtual ~SampleProfileReader ()
 
virtual std::error_code readHeader ()=0
 Read and validate the file header. More...
 
virtual std::error_code read ()=0
 Read sample profiles from the associated file. More...
 
void dumpFunctionProfile (StringRef FName, raw_ostream &OS=dbgs())
 Print the profile for FName on stream OS. More...
 
void dump (raw_ostream &OS=dbgs())
 Print all the profiles on stream OS. More...
 
FunctionSamplesgetSamplesFor (const Function &F)
 Return the samples collected for function F. More...
 
StringMap< FunctionSamples > & getProfiles ()
 Return all the profiles. More...
 
void reportError (int64_t LineNumber, Twine Msg) const
 Report a parse error message. More...
 
ProfileSummarygetSummary ()
 Return the profile summary. More...
 

Static Public Member Functions

static ErrorOr
< std::unique_ptr
< SampleProfileReader > > 
create (const Twine &Filename, LLVMContext &C)
 Create a sample profile reader appropriate to the file format. More...
 
static ErrorOr
< std::unique_ptr
< SampleProfileReader > > 
create (std::unique_ptr< MemoryBuffer > &B, LLVMContext &C)
 Create a sample profile reader from the supplied memory buffer. More...
 

Protected Member Functions

void computeSummary ()
 Compute summary for this profile. More...
 

Protected Attributes

StringMap< FunctionSamplesProfiles
 Map every function to its associated profile. More...
 
LLVMContextCtx
 LLVM context used to emit diagnostics. More...
 
std::unique_ptr< MemoryBufferBuffer
 Memory buffer holding the profile file. More...
 
std::unique_ptr< ProfileSummarySummary
 Profile summary information. More...
 

Detailed Description

Sample-based profile reader.

Each profile contains sample counts for all the functions executed. Inside each function, statements are annotated with the collected samples on all the instructions associated with that statement.

For this to produce meaningful data, the program needs to be compiled with some debug information (at minimum, line numbers: -gline-tables-only). Otherwise, it will be impossible to match IR instructions to the line numbers collected by the profiler.

From the profile file, we are interested in collecting the following information:

The reader supports two file formats: text and binary. The text format is useful for debugging and testing, while the binary format is more compact and I/O efficient. They can both be used interchangeably.

Definition at line 257 of file SampleProfReader.h.

Constructor & Destructor Documentation

llvm::sampleprof::SampleProfileReader::SampleProfileReader ( std::unique_ptr< MemoryBuffer B,
LLVMContext C 
)
inline

Definition at line 259 of file SampleProfReader.h.

virtual llvm::sampleprof::SampleProfileReader::~SampleProfileReader ( )
inlinevirtual

Definition at line 262 of file SampleProfReader.h.

Member Function Documentation

void SampleProfileReader::computeSummary ( )
protected
ErrorOr< std::unique_ptr< SampleProfileReader > > SampleProfileReader::create ( const Twine Filename,
LLVMContext C 
)
static

Create a sample profile reader appropriate to the file format.

Create a sample profile reader based on the format of the input file.

Parameters
FilenameThe file to open.
ReaderThe reader to instantiate according to Filename's format.
CThe LLVM context to use to emit diagnostics.
Returns
an error code indicating the status of the created reader.

Definition at line 759 of file SampleProfReader.cpp.

References C, and setupMemoryBuffer().

ErrorOr< std::unique_ptr< SampleProfileReader > > SampleProfileReader::create ( std::unique_ptr< MemoryBuffer > &  B,
LLVMContext C 
)
static

Create a sample profile reader from the supplied memory buffer.

Create a sample profile reader based on the format of the input data.

Parameters
BThe memory buffer to create the reader from (assumes ownership).
ReaderThe reader to instantiate according to Filename's format.
CThe LLVM context to use to emit diagnostics.
Returns
an error code indicating the status of the created reader.

Definition at line 776 of file SampleProfReader.cpp.

References llvm::sampleprof::SampleProfileReaderText::hasFormat(), llvm::sampleprof::SampleProfileReaderBinary::hasFormat(), llvm::sampleprof::SampleProfileReaderGCC::hasFormat(), and llvm::unrecognized_format.

void SampleProfileReader::dump ( raw_ostream OS = dbgs())

Print all the profiles on stream OS.

Dump all the function profiles found on stream OS.

Definition at line 45 of file SampleProfReader.cpp.

References I.

void SampleProfileReader::dumpFunctionProfile ( StringRef  FName,
raw_ostream OS = dbgs() 
)

Print the profile for FName on stream OS.

Dump the function profile for FName.

Parameters
FNameName of the function to print.
OSStream to emit the output to.

Definition at line 39 of file SampleProfReader.cpp.

StringMap<FunctionSamples>& llvm::sampleprof::SampleProfileReader::getProfiles ( )
inline

Return all the profiles.

Definition at line 282 of file SampleProfReader.h.

References Profiles.

FunctionSamples* llvm::sampleprof::SampleProfileReader::getSamplesFor ( const Function F)
inline

Return the samples collected for function F.

Definition at line 277 of file SampleProfReader.h.

References llvm::Value::getName(), and Profiles.

ProfileSummary& llvm::sampleprof::SampleProfileReader::getSummary ( )
inline

Return the profile summary.

Definition at line 299 of file SampleProfReader.h.

References Summary.

virtual std::error_code llvm::sampleprof::SampleProfileReader::read ( )
pure virtual
virtual std::error_code llvm::sampleprof::SampleProfileReader::readHeader ( )
pure virtual
void llvm::sampleprof::SampleProfileReader::reportError ( int64_t  LineNumber,
Twine  Msg 
) const
inline

Report a parse error message.

Definition at line 285 of file SampleProfReader.h.

References Buffer, Ctx, and llvm::LLVMContext::diagnose().

Member Data Documentation

std::unique_ptr<MemoryBuffer> llvm::sampleprof::SampleProfileReader::Buffer
protected

Memory buffer holding the profile file.

Definition at line 313 of file SampleProfReader.h.

Referenced by reportError().

LLVMContext& llvm::sampleprof::SampleProfileReader::Ctx
protected

LLVM context used to emit diagnostics.

Definition at line 310 of file SampleProfReader.h.

Referenced by reportError().

StringMap<FunctionSamples> llvm::sampleprof::SampleProfileReader::Profiles
protected

Map every function to its associated profile.

The profile of every function executed at runtime is collected in the structure FunctionSamples. This maps function objects to their corresponding profiles.

Definition at line 307 of file SampleProfReader.h.

Referenced by getProfiles(), and getSamplesFor().

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

Profile summary information.

Definition at line 316 of file SampleProfReader.h.

Referenced by getSummary().


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