[llvm] [memprof] Add getMemProfDataForTest for unit tests (PR #119061)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Sat Dec 7 00:26:51 PST 2024
https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/119061
We always call getFrameMapping and getCallStackMapping together in
InstrProfTest.cpp. This patch combines the two functions into new
function getMemProfDataForTest.
>From 77de11e8c6bfe82c21658ffcf6b623afd327db61 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Sat, 7 Dec 2024 00:02:49 -0800
Subject: [PATCH] [memprof] Add getMemProfDataForTest for unit tests
We always call getFrameMapping and getCallStackMapping together in
InstrProfTest.cpp. This patch combines the two functions into new
function getMemProfDataForTest.
---
llvm/unittests/ProfileData/InstrProfTest.cpp | 50 ++++++++------------
1 file changed, 19 insertions(+), 31 deletions(-)
diff --git a/llvm/unittests/ProfileData/InstrProfTest.cpp b/llvm/unittests/ProfileData/InstrProfTest.cpp
index 273b89ca26aa98..b64abdc76356ae 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.
@@ -454,9 +448,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);
@@ -493,9 +485,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);
@@ -604,9 +594,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