ContextShouldBeInlined = 0x2, // Leaf of context should be inlined
};
-// Represents a callsite with caller function name and line location
+// Represents a context frame with function name and line location
struct SampleContextFrame {
- StringRef CallerName;
- LineLocation Callsite;
+ StringRef FuncName;
+ LineLocation Location;
- SampleContextFrame() : Callsite(0, 0) {}
+ SampleContextFrame() : Location(0, 0) {}
- SampleContextFrame(StringRef CallerName, LineLocation Callsite)
- : CallerName(CallerName), Callsite(Callsite) {}
+ SampleContextFrame(StringRef FuncName, LineLocation Location)
+ : FuncName(FuncName), Location(Location) {}
bool operator==(const SampleContextFrame &That) const {
- return Callsite == That.Callsite && CallerName == That.CallerName;
+ return Location == That.Location && FuncName == That.FuncName;
}
bool operator!=(const SampleContextFrame &That) const {
std::string toString(bool OutputLineLocation) const {
std::ostringstream OContextStr;
- OContextStr << CallerName.str();
+ OContextStr << FuncName.str();
if (OutputLineLocation) {
- OContextStr << ":" << Callsite.LineOffset;
- if (Callsite.Discriminator)
- OContextStr << "." << Callsite.Discriminator;
+ OContextStr << ":" << Location.LineOffset;
+ if (Location.Discriminator)
+ OContextStr << "." << Location.Discriminator;
}
return OContextStr.str();
}
};
static inline hash_code hash_value(const SampleContextFrame &arg) {
- return hash_combine(arg.CallerName, arg.Callsite.LineOffset,
- arg.Callsite.Discriminator);
+ return hash_combine(arg.FuncName, arg.Location.LineOffset,
+ arg.Location.Discriminator);
}
using SampleContextFrameVector = SmallVector<SampleContextFrame, 10>;
ContextStateMask CState = RawContext) {
assert(CState != UnknownContext);
FullContext = Context;
- Name = Context.back().CallerName;
+ Name = Context.back().FuncName;
State = CState;
}
while (I < std::min(FullContext.size(), That.FullContext.size())) {
auto &Context1 = FullContext[I];
auto &Context2 = That.FullContext[I];
- auto V = Context1.CallerName.compare(Context2.CallerName);
+ auto V = Context1.FuncName.compare(Context2.FuncName);
if (V)
return V == -1;
- if (Context1.Callsite != Context2.Callsite)
- return Context1.Callsite < Context2.Callsite;
+ if (Context1.Location != Context2.Location)
+ return Context1.Location < Context2.Location;
I++;
}
return false;
ThatContext = ThatContext.take_front(ThisContext.size());
// Compare Leaf frame first
- if (ThisContext.back().CallerName != ThatContext.back().CallerName)
+ if (ThisContext.back().FuncName != ThatContext.back().FuncName)
return false;
// Compare leading context
return ThisContext.drop_back() == ThatContext.drop_back();
auto Frames = Context.getContextFrames();
encodeULEB128(Frames.size(), OS);
for (auto &Callsite : Frames) {
- if (std::error_code EC = writeNameIdx(Callsite.CallerName))
+ if (std::error_code EC = writeNameIdx(Callsite.FuncName))
return EC;
- encodeULEB128(Callsite.Callsite.LineOffset, OS);
- encodeULEB128(Callsite.Callsite.Discriminator, OS);
+ encodeULEB128(Callsite.Location.LineOffset, OS);
+ encodeULEB128(Callsite.Location.Discriminator, OS);
}
}
const SampleContext &Context) {
if (Context.hasContext()) {
for (auto &Callsite : Context.getContextFrames())
- SampleProfileWriterBinary::addName(Callsite.CallerName);
+ SampleProfileWriterBinary::addName(Callsite.FuncName);
CSNameTable.insert(std::make_pair(Context, 0));
} else {
SampleProfileWriterBinary::addName(Context.getName());
for (auto &Callsite : Context.getContextFrames()) {
// Create child node at parent line/disc location
if (AllowCreate) {
- ContextNode = ContextNode->getOrCreateChildContext(CallSiteLoc,
- Callsite.CallerName);
+ ContextNode =
+ ContextNode->getOrCreateChildContext(CallSiteLoc, Callsite.FuncName);
} else {
ContextNode =
- ContextNode->getChildContext(CallSiteLoc, Callsite.CallerName);
+ ContextNode->getChildContext(CallSiteLoc, Callsite.FuncName);
}
- CallSiteLoc = Callsite.Callsite;
+ CallSiteLoc = Callsite.Location;
}
assert((!AllowCreate || ContextNode) &&
namespace sampleprof {
inline std::string getCallSite(const SampleContextFrame &Callsite) {
- std::string CallsiteStr = Callsite.CallerName.str();
+ std::string CallsiteStr = Callsite.FuncName.str();
CallsiteStr += ":";
- CallsiteStr += Twine(Callsite.Callsite.LineOffset).str();
- if (Callsite.Callsite.Discriminator > 0) {
+ CallsiteStr += Twine(Callsite.Location.LineOffset).str();
+ if (Callsite.Location.Discriminator > 0) {
CallsiteStr += ".";
- CallsiteStr += Twine(Callsite.Callsite.Discriminator).str();
+ CallsiteStr += Twine(Callsite.Location.Discriminator).str();
}
return CallsiteStr;
}
FunctionSamples &FunctionProfile, const SampleContextFrame &LeafLoc,
uint64_t Count) {
// Filter out invalid negative(int type) lineOffset
- if (LeafLoc.Callsite.LineOffset & 0x80000000)
+ if (LeafLoc.Location.LineOffset & 0x80000000)
return;
// Use the maximum count of samples with same line location
ErrorOr<uint64_t> R = FunctionProfile.findSamplesAt(
- LeafLoc.Callsite.LineOffset, LeafLoc.Callsite.Discriminator);
+ LeafLoc.Location.LineOffset, LeafLoc.Location.Discriminator);
uint64_t PreviousCount = R ? R.get() : 0;
if (PreviousCount <= Count) {
- FunctionProfile.addBodySamples(LeafLoc.Callsite.LineOffset,
- LeafLoc.Callsite.Discriminator,
+ FunctionProfile.addBodySamples(LeafLoc.Location.LineOffset,
+ LeafLoc.Location.Discriminator,
Count - PreviousCount);
}
}
const SampleContextFrameVector &FrameVec, uint64_t Count) {
// Get top level profile
FunctionSamples *FunctionProfile =
- &getTopLevelFunctionProfile(FrameVec[0].CallerName);
+ &getTopLevelFunctionProfile(FrameVec[0].FuncName);
FunctionProfile->addTotalSamples(Count);
for (size_t I = 1; I < FrameVec.size(); I++) {
FunctionSamplesMap &SamplesMap =
- FunctionProfile->functionSamplesAt(FrameVec[I - 1].Callsite);
+ FunctionProfile->functionSamplesAt(FrameVec[I - 1].Location);
auto Ret =
- SamplesMap.emplace(FrameVec[I].CallerName.str(), FunctionSamples());
+ SamplesMap.emplace(FrameVec[I].FuncName.str(), FunctionSamples());
if (Ret.second) {
- SampleContext Context(FrameVec[I].CallerName);
+ SampleContext Context(FrameVec[I].FuncName);
Ret.first->second.setContext(Context);
}
FunctionProfile = &Ret.first->second;
FunctionSamples &FunctionProfile =
getLeafProfileAndAddTotalSamples(FrameVec, Count);
FunctionProfile.addCalledTargetSamples(
- FrameVec.back().Callsite.LineOffset,
- FrameVec.back().Callsite.Discriminator, CalleeName, Count);
+ FrameVec.back().Location.LineOffset,
+ FrameVec.back().Location.Discriminator, CalleeName, Count);
}
// Add head samples for callee.
FunctionSamples &CalleeProfile = getTopLevelFunctionProfile(CalleeName);
auto LeafLoc = Binary->getInlineLeafFrameLoc(SourceOffset);
if (!LeafLoc.hasValue())
continue;
- FunctionProfile.addCalledTargetSamples(LeafLoc->Callsite.LineOffset,
- LeafLoc->Callsite.Discriminator,
+ FunctionProfile.addCalledTargetSamples(LeafLoc->Location.LineOffset,
+ LeafLoc->Location.Discriminator,
CalleeName, Count);
// Record head sample for called target(callee)
SampleContextFrameVector CalleeCtx(ContextId.begin(), ContextId.end());
- assert(CalleeCtx.back().CallerName == LeafLoc->CallerName &&
+ assert(CalleeCtx.back().FuncName == LeafLoc->FuncName &&
"Leaf function name doesn't match");
CalleeCtx.back() = *LeafLoc;
CalleeCtx.emplace_back(CalleeName, LineLocation(0, 0));
CalleeContext = CalleeContext.drop_back();
CallerContext.assign(CalleeContext.begin(), CalleeContext.end());
SampleContextFrame CallerFrame = CallerContext.back();
- CallerContext.back().Callsite = LineLocation(0, 0);
+ CallerContext.back().Location = LineLocation(0, 0);
return CallerFrame;
}
if (!EstimatedCallCount && !CalleeProfile.getBodySamples().size())
EstimatedCallCount = 1;
CallerProfile.addCalledTargetSamples(
- CallerLeafFrameLoc.Callsite.LineOffset,
- CallerLeafFrameLoc.Callsite.Discriminator,
+ CallerLeafFrameLoc.Location.LineOffset,
+ CallerLeafFrameLoc.Location.Discriminator,
CalleeProfile.getContext().getName(), EstimatedCallCount);
- CallerProfile.addBodySamples(CallerLeafFrameLoc.Callsite.LineOffset,
- CallerLeafFrameLoc.Callsite.Discriminator,
+ CallerProfile.addBodySamples(CallerLeafFrameLoc.Location.LineOffset,
+ CallerLeafFrameLoc.Location.Discriminator,
EstimatedCallCount);
CallerProfile.addTotalSamples(EstimatedCallCount);
}
SampleContextFrameVector CallerContextId;
SampleContextFrame &&CallerLeafFrameLoc =
getCallerContext(CalleeContextId, CallerContextId);
- uint64_t CallerIndex = CallerLeafFrameLoc.Callsite.LineOffset;
+ uint64_t CallerIndex = CallerLeafFrameLoc.Location.LineOffset;
assert(CallerIndex &&
"Inferred caller's location index shouldn't be zero!");
FunctionSamples &CallerProfile =
// frame's probe id, like:
// Inlined stack: [foo:1, bar:2], the ContextId will be "foo:1 @ bar"
auto LeafFrame = NewContextStack.back();
- LeafFrame.Callsite = LineLocation(0, 0);
+ LeafFrame.Location = LineLocation(0, 0);
NewContextStack.pop_back();
// Compress the context string except for the leaf frame
CSProfileGenerator::compressRecursionContext(NewContextStack);
ContextTrieNode *CurNode = &RootContext;
bool IsLeaf = true;
for (const auto &Callsite : reverse(Context)) {
- StringRef CallerName = Callsite.CallerName;
- LineLocation CallsiteLoc = IsLeaf ? LineLocation(0, 0) : Callsite.Callsite;
+ StringRef CallerName = Callsite.FuncName;
+ LineLocation CallsiteLoc = IsLeaf ? LineLocation(0, 0) : Callsite.Location;
CurNode = CurNode->getOrCreateChildContext(CallsiteLoc, CallerName);
IsLeaf = false;
}
const auto &ChildFrame = Frames[I--];
PrevNode = CurrNode;
CurrNode =
- CurrNode->getChildContext(ChildFrame.Callsite, ChildFrame.CallerName);
+ CurrNode->getChildContext(ChildFrame.Location, ChildFrame.FuncName);
if (CurrNode && CurrNode->getFunctionSize().hasValue())
Size = CurrNode->getFunctionSize().getValue();
}
// Compress the context string except for the leaf frame
auto LeafFrame = ContextVec.back();
- LeafFrame.Callsite = LineLocation(0, 0);
+ LeafFrame.Location = LineLocation(0, 0);
ContextVec.pop_back();
CSProfileGenerator::compressRecursionContext(ContextVec);
CSProfileGenerator::trimContext(ContextVec);