[llvm] 4cf0bd8 - [memprof] Add getMemProfDataForTest for unit tests (#119061)
via llvm-commits
llvm-commits at lists.llvm.org
Sat Dec 7 10:41:45 PST 2024
Author: Kazu Hirata
Date: 2024-12-07T10:41:42-08:00
New Revision: 4cf0bd89eed3ca08fc00c38a0419ae514075ee7c
URL: https://github.com/llvm/llvm-project/commit/4cf0bd89eed3ca08fc00c38a0419ae514075ee7c
DIFF: https://github.com/llvm/llvm-project/commit/4cf0bd89eed3ca08fc00c38a0419ae514075ee7c.diff
LOG: [memprof] Add getMemProfDataForTest for unit tests (#119061)
We always call getFrameMapping and getCallStackMapping together in
InstrProfTest.cpp. This patch combines the two functions into new
function getMemProfDataForTest.
Added:
Modified:
llvm/unittests/ProfileData/InstrProfTest.cpp
Removed:
################################################################################
diff --git a/llvm/unittests/ProfileData/InstrProfTest.cpp b/llvm/unittests/ProfileData/InstrProfTest.cpp
index 49a186cc98df28..6df2ec1efcd81c 100644
--- a/llvm/unittests/ProfileData/InstrProfTest.cpp
+++ b/llvm/unittests/ProfileData/InstrProfTest.cpp
@@ -349,31 +349,25 @@ TEST_F(InstrProfTest, test_merge_traces_sampled) {
IsSubsetOf({FooTrace, BarTrace, GooTrace, BarTrace, GooTrace, FooTrace}));
}
+using ::llvm::memprof::IndexedMemProfData;
using ::llvm::memprof::IndexedMemProfRecord;
using ::llvm::memprof::MemInfoBlock;
-using FrameIdMapTy =
- llvm::MapVector<::llvm::memprof::FrameId, ::llvm::memprof::Frame>;
-using CallStackIdMapTy =
- llvm::MapVector<::llvm::memprof::CallStackId,
- ::llvm::SmallVector<::llvm::memprof::FrameId>>;
-
-static FrameIdMapTy getFrameMapping() {
- FrameIdMapTy Mapping;
- Mapping.insert({0, {0x123, 1, 2, false}});
- Mapping.insert({1, {0x345, 3, 4, true}});
- Mapping.insert({2, {0x125, 5, 6, false}});
- Mapping.insert({3, {0x567, 7, 8, true}});
- Mapping.insert({4, {0x124, 5, 6, false}});
- Mapping.insert({5, {0x789, 8, 9, true}});
- return Mapping;
-}
-static CallStackIdMapTy getCallStackMapping() {
- CallStackIdMapTy Mapping;
- Mapping.insert({0x111, {0, 1}});
- Mapping.insert({0x222, {2, 3}});
- Mapping.insert({0x333, {4, 5}});
- return Mapping;
+IndexedMemProfData getMemProfDataForTest() {
+ IndexedMemProfData MemProfData;
+
+ MemProfData.Frames.insert({0, {0x123, 1, 2, false}});
+ MemProfData.Frames.insert({1, {0x345, 3, 4, true}});
+ MemProfData.Frames.insert({2, {0x125, 5, 6, false}});
+ MemProfData.Frames.insert({3, {0x567, 7, 8, true}});
+ MemProfData.Frames.insert({4, {0x124, 5, 6, false}});
+ MemProfData.Frames.insert({5, {0x789, 8, 9, true}});
+
+ MemProfData.CallStacks.insert({0x111, {0, 1}});
+ MemProfData.CallStacks.insert({0x222, {2, 3}});
+ MemProfData.CallStacks.insert({0x333, {4, 5}});
+
+ return MemProfData;
}
// Populate all of the fields of MIB.
@@ -452,9 +446,7 @@ TEST_F(InstrProfTest, test_memprof_v2_full_schema) {
const IndexedMemProfRecord IndexedMR = makeRecordV2(
/*AllocFrames=*/{0x111, 0x222},
/*CallSiteFrames=*/{0x333}, MIB, memprof::getFullSchema());
- memprof::IndexedMemProfData MemProfData;
- MemProfData.Frames = getFrameMapping();
- MemProfData.CallStacks = getCallStackMapping();
+ IndexedMemProfData MemProfData = getMemProfDataForTest();
MemProfData.Records.try_emplace(0x9999, IndexedMR);
Writer.addMemProfData(MemProfData, Err);
@@ -491,9 +483,7 @@ TEST_F(InstrProfTest, test_memprof_v2_partial_schema) {
const IndexedMemProfRecord IndexedMR = makeRecordV2(
/*AllocFrames=*/{0x111, 0x222},
/*CallSiteFrames=*/{0x333}, MIB, memprof::getHotColdSchema());
- memprof::IndexedMemProfData MemProfData;
- MemProfData.Frames = getFrameMapping();
- MemProfData.CallStacks = getCallStackMapping();
+ IndexedMemProfData MemProfData = getMemProfDataForTest();
MemProfData.Records.try_emplace(0x9999, IndexedMR);
Writer.addMemProfData(MemProfData, Err);
@@ -602,9 +592,7 @@ TEST_F(InstrProfTest, test_memprof_merge) {
/*AllocFrames=*/{0x111, 0x222},
/*CallSiteFrames=*/{}, makePartialMIB(), memprof::getHotColdSchema());
- memprof::IndexedMemProfData MemProfData;
- MemProfData.Frames = getFrameMapping();
- MemProfData.CallStacks = getCallStackMapping();
+ IndexedMemProfData MemProfData = getMemProfDataForTest();
MemProfData.Records.try_emplace(0x9999, IndexedMR);
Writer2.addMemProfData(MemProfData, Err);
More information about the llvm-commits
mailing list