Skip to content

Commit 77de11e

Browse files
[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.
1 parent d76650b commit 77de11e

File tree

1 file changed

+19
-31
lines changed

1 file changed

+19
-31
lines changed

llvm/unittests/ProfileData/InstrProfTest.cpp

Lines changed: 19 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -349,31 +349,25 @@ TEST_F(InstrProfTest, test_merge_traces_sampled) {
349349
IsSubsetOf({FooTrace, BarTrace, GooTrace, BarTrace, GooTrace, FooTrace}));
350350
}
351351

352+
using ::llvm::memprof::IndexedMemProfData;
352353
using ::llvm::memprof::IndexedMemProfRecord;
353354
using ::llvm::memprof::MemInfoBlock;
354-
using FrameIdMapTy =
355-
llvm::MapVector<::llvm::memprof::FrameId, ::llvm::memprof::Frame>;
356-
using CallStackIdMapTy =
357-
llvm::MapVector<::llvm::memprof::CallStackId,
358-
::llvm::SmallVector<::llvm::memprof::FrameId>>;
359-
360-
static FrameIdMapTy getFrameMapping() {
361-
FrameIdMapTy Mapping;
362-
Mapping.insert({0, {0x123, 1, 2, false}});
363-
Mapping.insert({1, {0x345, 3, 4, true}});
364-
Mapping.insert({2, {0x125, 5, 6, false}});
365-
Mapping.insert({3, {0x567, 7, 8, true}});
366-
Mapping.insert({4, {0x124, 5, 6, false}});
367-
Mapping.insert({5, {0x789, 8, 9, true}});
368-
return Mapping;
369-
}
370355

371-
static CallStackIdMapTy getCallStackMapping() {
372-
CallStackIdMapTy Mapping;
373-
Mapping.insert({0x111, {0, 1}});
374-
Mapping.insert({0x222, {2, 3}});
375-
Mapping.insert({0x333, {4, 5}});
376-
return Mapping;
356+
IndexedMemProfData getMemProfDataForTest() {
357+
IndexedMemProfData MemProfData;
358+
359+
MemProfData.Frames.insert({0, {0x123, 1, 2, false}});
360+
MemProfData.Frames.insert({1, {0x345, 3, 4, true}});
361+
MemProfData.Frames.insert({2, {0x125, 5, 6, false}});
362+
MemProfData.Frames.insert({3, {0x567, 7, 8, true}});
363+
MemProfData.Frames.insert({4, {0x124, 5, 6, false}});
364+
MemProfData.Frames.insert({5, {0x789, 8, 9, true}});
365+
366+
MemProfData.CallStacks.insert({0x111, {0, 1}});
367+
MemProfData.CallStacks.insert({0x222, {2, 3}});
368+
MemProfData.CallStacks.insert({0x333, {4, 5}});
369+
370+
return MemProfData;
377371
}
378372

379373
// Populate all of the fields of MIB.
@@ -454,9 +448,7 @@ TEST_F(InstrProfTest, test_memprof_v2_full_schema) {
454448
const IndexedMemProfRecord IndexedMR = makeRecordV2(
455449
/*AllocFrames=*/{0x111, 0x222},
456450
/*CallSiteFrames=*/{0x333}, MIB, memprof::getFullSchema());
457-
memprof::IndexedMemProfData MemProfData;
458-
MemProfData.Frames = getFrameMapping();
459-
MemProfData.CallStacks = getCallStackMapping();
451+
IndexedMemProfData MemProfData = getMemProfDataForTest();
460452
MemProfData.Records.try_emplace(0x9999, IndexedMR);
461453
Writer.addMemProfData(MemProfData, Err);
462454

@@ -493,9 +485,7 @@ TEST_F(InstrProfTest, test_memprof_v2_partial_schema) {
493485
const IndexedMemProfRecord IndexedMR = makeRecordV2(
494486
/*AllocFrames=*/{0x111, 0x222},
495487
/*CallSiteFrames=*/{0x333}, MIB, memprof::getHotColdSchema());
496-
memprof::IndexedMemProfData MemProfData;
497-
MemProfData.Frames = getFrameMapping();
498-
MemProfData.CallStacks = getCallStackMapping();
488+
IndexedMemProfData MemProfData = getMemProfDataForTest();
499489
MemProfData.Records.try_emplace(0x9999, IndexedMR);
500490
Writer.addMemProfData(MemProfData, Err);
501491

@@ -604,9 +594,7 @@ TEST_F(InstrProfTest, test_memprof_merge) {
604594
/*AllocFrames=*/{0x111, 0x222},
605595
/*CallSiteFrames=*/{}, makePartialMIB(), memprof::getHotColdSchema());
606596

607-
memprof::IndexedMemProfData MemProfData;
608-
MemProfData.Frames = getFrameMapping();
609-
MemProfData.CallStacks = getCallStackMapping();
597+
IndexedMemProfData MemProfData = getMemProfDataForTest();
610598
MemProfData.Records.try_emplace(0x9999, IndexedMR);
611599
Writer2.addMemProfData(MemProfData, Err);
612600

0 commit comments

Comments
 (0)