diff options
author | Kazu Hirata <kazu@google.com> | 2024-12-07 10:41:42 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-12-07 10:41:42 -0800 |
commit | 4cf0bd89eed3ca08fc00c38a0419ae514075ee7c (patch) | |
tree | 829366d3e49a402d7e496238f1631a4f5ae70165 /llvm/unittests/ProfileData/InstrProfTest.cpp | |
parent | 427172a861f6a1ff1d00771b896d2b2a2ac34494 (diff) | |
download | llvm-4cf0bd89eed3ca08fc00c38a0419ae514075ee7c.zip llvm-4cf0bd89eed3ca08fc00c38a0419ae514075ee7c.tar.gz llvm-4cf0bd89eed3ca08fc00c38a0419ae514075ee7c.tar.bz2 |
[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.
Diffstat (limited to 'llvm/unittests/ProfileData/InstrProfTest.cpp')
-rw-r--r-- | llvm/unittests/ProfileData/InstrProfTest.cpp | 50 |
1 files changed, 19 insertions, 31 deletions
diff --git a/llvm/unittests/ProfileData/InstrProfTest.cpp b/llvm/unittests/ProfileData/InstrProfTest.cpp index 49a186c..6df2ec1 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); |