|
LLVM 24.0.0git
|
Representation of a single sample record. More...
#include "llvm/ProfileData/SampleProf.h"
Classes | |
| struct | CallTargetComparator |
Public Types | |
| using | CallTarget = std::pair<FunctionId, uint64_t> |
| using | SortedCallTargetSet = SmallVector<CallTarget> |
| using | CallTargetMap = SortedVectorMap<FunctionId, uint64_t, 0> |
Public Member Functions | |
| SampleRecord ()=default | |
| sampleprof_error | addSamples (uint64_t S, uint64_t Weight=1) |
Increment the number of samples for this record by S. | |
| uint64_t | removeSamples (uint64_t S) |
Decrease the number of samples for this record by S. | |
| sampleprof_error | addCalledTarget (FunctionId F, uint64_t S, uint64_t Weight=1) |
Add called function F with samples S. | |
| uint64_t | removeCalledTarget (FunctionId F) |
| Remove called function from the call target map. | |
| bool | hasCalls () const |
| Return true if this sample record contains function calls. | |
| uint64_t | getSamples () const |
| const CallTargetMap & | getCallTargets () const LLVM_LIFETIME_BOUND |
| Return the call targets collected in this sample record. | |
| SortedCallTargetSet | getSortedCallTargets () const |
| uint64_t | getCallTargetSum () const |
| LLVM_ABI sampleprof_error | merge (const SampleRecord &Other, uint64_t Weight=1) |
Merge the samples in Other into this record. | |
| LLVM_ABI void | print (raw_ostream &OS, unsigned Indent) const |
Print the sample record to the stream OS indented by Indent. | |
| LLVM_ABI void | dump () const |
| LLVM_ABI std::error_code | serialize (raw_ostream &OS, const MapVector< FunctionId, uint32_t > &NameTable) const |
| Serialize the sample record to the output stream using ULEB128 encoding. | |
| bool | operator== (const SampleRecord &Other) const |
| bool | operator!= (const SampleRecord &Other) const |
Static Public Member Functions | |
| static SortedCallTargetSet | sortCallTargets (const CallTargetMap &Targets) |
| Sort call targets in descending order of call frequency. | |
| static const CallTargetMap | adjustCallTargets (const CallTargetMap &Targets, float DistributionFactor) |
| Prorate call targets by a distribution factor. | |
Representation of a single sample record.
A sample record is represented by a positive integer value, which indicates how frequently was the associated line location executed.
Additionally, if the associated location contains a function call, the record will hold a list of all the possible called targets and the types for virtual table dispatches. For direct calls, this will be the exact function being invoked. For indirect calls (function pointers, virtual table dispatch), this will be a list of one or more functions. For virtual table dispatches, this record will also hold the type of the object.
Definition at line 395 of file SampleProf.h.
| using llvm::sampleprof::SampleRecord::CallTarget = std::pair<FunctionId, uint64_t> |
Definition at line 397 of file SampleProf.h.
Definition at line 408 of file SampleProf.h.
Definition at line 407 of file SampleProf.h.
|
default |
Referenced by merge(), operator!=(), and operator==().
|
inline |
Add called function F with samples S.
Optionally scale sample count S by Weight.
Sample counts accumulate using saturating arithmetic, to avoid wrapping around unsigned integers.
Definition at line 437 of file SampleProf.h.
References llvm::counter_overflow, F, llvm::SaturatingMultiplyAdd(), llvm::success, and uint64_t.
Referenced by merge().
|
inline |
Increment the number of samples for this record by S.
Optionally scale sample count S by Weight.
Sample counts accumulate using saturating arithmetic, to avoid wrapping around unsigned integers.
Definition at line 416 of file SampleProf.h.
References llvm::counter_overflow, llvm::SaturatingMultiplyAdd(), llvm::success, and uint64_t.
Referenced by merge().
|
inlinestatic |
Prorate call targets by a distribution factor.
Definition at line 488 of file SampleProf.h.
| LLVM_DUMP_METHOD void SampleRecord::dump | ( | ) | const |
Definition at line 193 of file SampleProf.cpp.
References llvm::dbgs(), LLVM_DUMP_METHOD, and print().
|
inline |
Return the call targets collected in this sample record.
The returned reference may be invalidated by subsequent modifications to this SampleRecord.
Definition at line 466 of file SampleProf.h.
References const, and LLVM_LIFETIME_BOUND.
Referenced by llvm::sampleprof::SampleProfileWriterBinary::addNames(), and serialize().
|
inline |
Definition at line 473 of file SampleProf.h.
|
inline |
Definition at line 462 of file SampleProf.h.
References uint64_t.
Referenced by dumpFunctionProfileJson(), and serialize().
|
inline |
Definition at line 469 of file SampleProf.h.
References sortCallTargets().
Referenced by dumpFunctionProfileJson(), print(), and serialize().
|
inline |
Return true if this sample record contains function calls.
Definition at line 460 of file SampleProf.h.
Referenced by print().
| sampleprof_error SampleRecord::merge | ( | const SampleRecord & | Other, |
| uint64_t | Weight = 1 ) |
Merge the samples in Other into this record.
Optionally scale sample counts by Weight.
Definition at line 142 of file SampleProf.cpp.
References addCalledTarget(), addSamples(), I, llvm::mergeSampleProfErrors(), llvm::Other, and SampleRecord().
|
inline |
Definition at line 513 of file SampleProf.h.
References llvm::Other, and SampleRecord().
|
inline |
Definition at line 509 of file SampleProf.h.
References llvm::Other, and SampleRecord().
| void SampleRecord::print | ( | raw_ostream & | OS, |
| unsigned | Indent ) const |
Print the sample record to the stream OS indented by Indent.
Definition at line 182 of file SampleProf.cpp.
References getSortedCallTargets(), hasCalls(), and I.
Referenced by dump(), and llvm::sampleprof::operator<<().
|
inline |
Remove called function from the call target map.
Return the target sample count of the called function.
Definition at line 449 of file SampleProf.h.
References llvm::Count, F, I, and uint64_t.
Decrease the number of samples for this record by S.
Return the amout of samples actually decreased.
Definition at line 425 of file SampleProf.h.
References uint64_t.
| std::error_code SampleRecord::serialize | ( | raw_ostream & | OS, |
| const MapVector< FunctionId, uint32_t > & | NameTable ) const |
Serialize the sample record to the output stream using ULEB128 encoding.
The NameTable is used to map function names to their IDs.
Definition at line 153 of file SampleProf.cpp.
References llvm::encodeULEB128(), llvm::MapVector< KeyT, ValueT, MapType, VectorType, N >::end(), llvm::MapVector< KeyT, ValueT, MapType, VectorType, N >::find(), getCallTargets(), getSamples(), getSortedCallTargets(), llvm::size(), llvm::success, and llvm::truncated_name_table.
Referenced by llvm::sampleprof::SampleProfileWriterBinary::writeBody().
|
inlinestatic |
Sort call targets in descending order of call frequency.
Definition at line 481 of file SampleProf.h.
References llvm::sort(), and llvm::to_vector_of().
Referenced by getSortedCallTargets(), and GetSortedValueDataFromCallTargets().