Skip to content

[memprof] Add IndexedMemProfData::addCallStack #118920

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 6, 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
12 changes: 12 additions & 0 deletions llvm/include/llvm/ProfileData/MemProf.h
Original file line number Diff line number Diff line change
Expand Up @@ -1029,6 +1029,18 @@ struct IndexedMemProfData {
Frames.try_emplace(Id, F);
return Id;
}

CallStackId addCallStack(ArrayRef<FrameId> CS) {
CallStackId CSId = hashCallStack(CS);
CallStacks.try_emplace(CSId, CS);
return CSId;
}

CallStackId addCallStack(SmallVector<FrameId> &&CS) {
CallStackId CSId = hashCallStack(CS);
CallStacks.try_emplace(CSId, std::move(CS));
return CSId;
}
};

struct FrameStat {
Expand Down
14 changes: 4 additions & 10 deletions llvm/lib/ProfileData/MemProfReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -500,8 +500,7 @@ Error RawMemProfReader::mapRawProfileToRecords() {
Callstack.append(Frames.begin(), Frames.end());
}

CallStackId CSId = hashCallStack(Callstack);
MemProfData.CallStacks.insert({CSId, Callstack});
CallStackId CSId = MemProfData.addCallStack(Callstack);

// We attach the memprof record to each function bottom-up including the
// first non-inline frame.
Expand All @@ -520,11 +519,8 @@ Error RawMemProfReader::mapRawProfileToRecords() {
// Some functions may have only callsite data and no allocation data. Here
// we insert a new entry for callsite data if we need to.
IndexedMemProfRecord &Record = MemProfData.Records[Id];
for (LocationPtr Loc : Locs) {
CallStackId CSId = hashCallStack(*Loc);
MemProfData.CallStacks.insert({CSId, *Loc});
Record.CallSiteIds.push_back(CSId);
}
for (LocationPtr Loc : Locs)
Record.CallSiteIds.push_back(MemProfData.addCallStack(*Loc));
}

return Error::success();
Expand Down Expand Up @@ -769,9 +765,7 @@ void YAMLMemProfReader::parse(StringRef YAMLData) {
IndexedCallStack.reserve(CallStack.size());
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;
return MemProfData.addCallStack(std::move(IndexedCallStack));
};

for (const auto &[GUID, Record] : Doc.HeapProfileRecords) {
Expand Down
6 changes: 2 additions & 4 deletions llvm/unittests/ProfileData/MemProfTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,8 +434,7 @@ TEST(MemProf, BaseMemProfReader) {
MemProfData.addFrame(F2);

llvm::SmallVector<FrameId> CallStack{F1.hash(), F2.hash()};
CallStackId CSId = hashCallStack(CallStack);
MemProfData.CallStacks.try_emplace(CSId, CallStack);
CallStackId CSId = MemProfData.addCallStack(std::move(CallStack));

IndexedMemProfRecord FakeRecord;
MemInfoBlock Block;
Expand Down Expand Up @@ -470,8 +469,7 @@ TEST(MemProf, BaseMemProfReaderWithCSIdMap) {
MemProfData.addFrame(F2);

llvm::SmallVector<FrameId> CallStack = {F1.hash(), F2.hash()};
CallStackId CSId = hashCallStack(CallStack);
MemProfData.CallStacks.insert({CSId, CallStack});
MemProfData.addCallStack(CallStack);

IndexedMemProfRecord FakeRecord;
MemInfoBlock Block;
Expand Down
Loading