Skip to content

Commit fd9f3be

Browse files
[memprof] Upgrade a unit test to Version 3 (#116516)
I'm planning to remove MemProf Version 1, which is a maintenance burden because it uses a different set of struct fields in IndexedAllocationInfo and IndexedMemProfRecord compared to Version 2 and 3. (FWIW, Version 2 and 3 are much closer to each other.) Before we remove the old version, we need to upgrade test_memprof_merge to Version 3. Here are some remarks: - Without this patch, we call Writer.addMemProfFrame, which I don't think is correct. This way, we are adding IndexedMemProfRecord to Writer2 without any frame. I'm changing that to Writer2.addMemProfFrame. - This patch adds a call to getCallStackMapping. Version 2 and 3 require a map from call stack IDs to call stacks. - I'm calling makeRecordV2 instead of makeRecord to populate the struct fields used by Version 2 and 3. - Version 1 uses MemProfRecord::MemProfRecord (that is, a constructor) to convert IndexedMemProfRecord to MemProfRecord. Version 2 and 3 use MemProfRecord::toMemProfRecord, a member function, to do the same task.
1 parent 8c7c8ea commit fd9f3be

File tree

1 file changed

+16
-20
lines changed

1 file changed

+16
-20
lines changed

llvm/unittests/ProfileData/InstrProfTest.cpp

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -677,29 +677,29 @@ TEST_F(InstrProfTest, test_memprof_merge) {
677677
Writer.addRecord({"func1", 0x1234, {42}}, Err);
678678

679679
InstrProfWriter Writer2;
680+
Writer2.setMemProfVersionRequested(memprof::Version3);
680681
ASSERT_THAT_ERROR(Writer2.mergeProfileKind(InstrProfKind::MemProf),
681682
Succeeded());
682683

683-
const IndexedMemProfRecord IndexedMR = makeRecord(
684-
/*AllocFrames=*/
685-
{
686-
{0, 1},
687-
{2, 3},
688-
},
689-
/*CallSiteFrames=*/{
690-
{4, 5},
691-
});
692-
693684
const FrameIdMapTy IdToFrameMap = getFrameMapping();
694685
for (const auto &I : IdToFrameMap) {
695-
Writer.addMemProfFrame(I.first, I.getSecond(), Err);
686+
Writer2.addMemProfFrame(I.first, I.getSecond(), Err);
696687
}
688+
689+
const auto CSIdToCallStackMap = getCallStackMapping();
690+
for (const auto &[CSId, CallStack] : CSIdToCallStackMap)
691+
Writer2.addMemProfCallStack(CSId, CallStack, Err);
692+
693+
const IndexedMemProfRecord IndexedMR = makeRecordV2(
694+
/*AllocFrames=*/{0x111, 0x222},
695+
/*CallSiteFrames=*/{}, makePartialMIB(), memprof::getHotColdSchema());
697696
Writer2.addMemProfRecord(/*Id=*/0x9999, IndexedMR);
698697

699698
ASSERT_THAT_ERROR(Writer.mergeProfileKind(Writer2.getProfileKind()),
700699
Succeeded());
701700
Writer.mergeRecordsFromWriter(std::move(Writer2), Err);
702701

702+
Writer.setMemProfVersionRequested(memprof::Version3);
703703
auto Profile = Writer.writeBuffer();
704704
readProfile(std::move(Profile));
705705

@@ -714,16 +714,12 @@ TEST_F(InstrProfTest, test_memprof_merge) {
714714

715715
std::optional<memprof::FrameId> LastUnmappedFrameId;
716716

717-
auto IdToFrameCallback = [&](const memprof::FrameId Id) {
718-
auto Iter = IdToFrameMap.find(Id);
719-
if (Iter == IdToFrameMap.end()) {
720-
LastUnmappedFrameId = Id;
721-
return memprof::Frame(0, 0, 0, false);
722-
}
723-
return Iter->second;
724-
};
717+
memprof::FrameIdConverter<decltype(IdToFrameMap)> FrameIdConv(IdToFrameMap);
718+
memprof::CallStackIdConverter<decltype(CSIdToCallStackMap)> CSIdConv(
719+
CSIdToCallStackMap, FrameIdConv);
725720

726-
const memprof::MemProfRecord WantRecord(IndexedMR, IdToFrameCallback);
721+
const ::llvm::memprof::MemProfRecord WantRecord =
722+
IndexedMR.toMemProfRecord(CSIdConv);
727723
ASSERT_EQ(LastUnmappedFrameId, std::nullopt)
728724
<< "could not map frame id: " << *LastUnmappedFrameId;
729725
EXPECT_THAT(WantRecord, EqualsRecord(Record));

0 commit comments

Comments
 (0)