Skip to content

[memprof] Add IndexedMemProfData::addFrame #118724

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions llvm/include/llvm/ProfileData/MemProf.h
Original file line number Diff line number Diff line change
Expand Up @@ -1023,6 +1023,12 @@ struct IndexedMemProfData {

// A map to hold call stack id to call stacks.
llvm::MapVector<CallStackId, llvm::SmallVector<FrameId>> CallStacks;

FrameId addFrame(const Frame &F) {
const FrameId Id = F.hash();
Frames.try_emplace(Id, F);
return Id;
}
};

struct FrameStat {
Expand Down
11 changes: 3 additions & 8 deletions llvm/lib/ProfileData/MemProfReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -584,9 +584,7 @@ Error RawMemProfReader::symbolizeAndFilterStackFrames(
GuidToSymbolName.insert({Guid, CanonicalName.str()});
}

const FrameId Hash = F.hash();
MemProfData.Frames.insert({Hash, F});
SymbolizedFrame[VAddr].push_back(Hash);
SymbolizedFrame[VAddr].push_back(MemProfData.addFrame(F));
}
}

Expand Down Expand Up @@ -769,11 +767,8 @@ void YAMLMemProfReader::parse(StringRef YAMLData) {
auto AddCallStack = [&](ArrayRef<Frame> CallStack) -> CallStackId {
SmallVector<FrameId> IndexedCallStack;
IndexedCallStack.reserve(CallStack.size());
for (const Frame &F : CallStack) {
FrameId Id = F.hash();
MemProfData.Frames.try_emplace(Id, F);
IndexedCallStack.push_back(Id);
}
for (const Frame &F : CallStack)
IndexedCallStack.push_back(MemProfData.addFrame(F));
CallStackId CSId = hashCallStack(IndexedCallStack);
MemProfData.CallStacks.try_emplace(CSId, std::move(IndexedCallStack));
return CSId;
Expand Down
8 changes: 4 additions & 4 deletions llvm/unittests/ProfileData/MemProfTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,8 +430,8 @@ TEST(MemProf, BaseMemProfReader) {
/*Column=*/5, /*IsInlineFrame=*/true);
Frame F2(/*Hash=*/IndexedMemProfRecord::getGUID("bar"), /*LineOffset=*/10,
/*Column=*/2, /*IsInlineFrame=*/false);
MemProfData.Frames.insert({F1.hash(), F1});
MemProfData.Frames.insert({F2.hash(), F2});
MemProfData.addFrame(F1);
MemProfData.addFrame(F2);

llvm::SmallVector<FrameId> CallStack{F1.hash(), F2.hash()};
CallStackId CSId = hashCallStack(CallStack);
Expand Down Expand Up @@ -466,8 +466,8 @@ TEST(MemProf, BaseMemProfReaderWithCSIdMap) {
/*Column=*/5, /*IsInlineFrame=*/true);
Frame F2(/*Hash=*/IndexedMemProfRecord::getGUID("bar"), /*LineOffset=*/10,
/*Column=*/2, /*IsInlineFrame=*/false);
MemProfData.Frames.insert({F1.hash(), F1});
MemProfData.Frames.insert({F2.hash(), F2});
MemProfData.addFrame(F1);
MemProfData.addFrame(F2);

llvm::SmallVector<FrameId> CallStack = {F1.hash(), F2.hash()};
CallStackId CSId = hashCallStack(CallStack);
Expand Down
Loading