aboutsummaryrefslogtreecommitdiff
path: root/llvm/unittests
diff options
context:
space:
mode:
authorKazu Hirata <kazu@google.com>2024-12-19 12:20:25 -0800
committerGitHub <noreply@github.com>2024-12-19 12:20:25 -0800
commit10d054e95413f0e98e4aeed9dbd4605f6f03b3fa (patch)
tree6115c42ce199608e7f9a7afdfd822e3f0669592b /llvm/unittests
parente3b571e632855386908c5cea310f5056d31d6df8 (diff)
downloadllvm-10d054e95413f0e98e4aeed9dbd4605f6f03b3fa.zip
llvm-10d054e95413f0e98e4aeed9dbd4605f6f03b3fa.tar.gz
llvm-10d054e95413f0e98e4aeed9dbd4605f6f03b3fa.tar.bz2
[memprof] Introduce IndexedCallstackIdConveter (NFC) (#120540)
This patch introduces IndexedCallstackIdConveter as a convenience wrapper around FrameIdConverter and CallStackIdConverter just for tests. With the new wrapper, we get to replace idioms like: FrameIdConverter<decltype(MemProfData.Frames)> FrameIdConv( MemProfData.Frames); CallStackIdConverter<decltype(MemProfData.CallStacks)> CSIdConv( MemProfData.CallStacks, FrameIdConv); with: IndexedCallstackIdConveter CSIdConv(MemProfData); Unfortunately, this exact pattern occurs in tests only; the combinations of the frame ID converter and call stack ID converter are diverse in production code.
Diffstat (limited to 'llvm/unittests')
-rw-r--r--llvm/unittests/ProfileData/InstrProfTest.cpp31
-rw-r--r--llvm/unittests/ProfileData/MemProfTest.cpp41
2 files changed, 24 insertions, 48 deletions
diff --git a/llvm/unittests/ProfileData/InstrProfTest.cpp b/llvm/unittests/ProfileData/InstrProfTest.cpp
index ac872d8..adcd4d2 100644
--- a/llvm/unittests/ProfileData/InstrProfTest.cpp
+++ b/llvm/unittests/ProfileData/InstrProfTest.cpp
@@ -457,17 +457,14 @@ TEST_F(InstrProfTest, test_memprof_v2_full_schema) {
ASSERT_THAT_ERROR(RecordOr.takeError(), Succeeded());
const memprof::MemProfRecord &Record = RecordOr.get();
- memprof::FrameIdConverter<decltype(MemProfData.Frames)> FrameIdConv(
- MemProfData.Frames);
- memprof::CallStackIdConverter<decltype(MemProfData.CallStacks)> CSIdConv(
- MemProfData.CallStacks, FrameIdConv);
+ memprof::IndexedCallstackIdConveter CSIdConv(MemProfData);
const ::llvm::memprof::MemProfRecord WantRecord =
IndexedMR.toMemProfRecord(CSIdConv);
- ASSERT_EQ(FrameIdConv.LastUnmappedId, std::nullopt)
- << "could not map frame id: " << *FrameIdConv.LastUnmappedId;
- ASSERT_EQ(CSIdConv.LastUnmappedId, std::nullopt)
- << "could not map call stack id: " << *CSIdConv.LastUnmappedId;
+ ASSERT_EQ(CSIdConv.FrameIdConv.LastUnmappedId, std::nullopt)
+ << "could not map frame id: " << *CSIdConv.FrameIdConv.LastUnmappedId;
+ ASSERT_EQ(CSIdConv.CSIdConv.LastUnmappedId, std::nullopt)
+ << "could not map call stack id: " << *CSIdConv.CSIdConv.LastUnmappedId;
EXPECT_THAT(WantRecord, EqualsRecord(Record));
}
@@ -494,17 +491,14 @@ TEST_F(InstrProfTest, test_memprof_v2_partial_schema) {
ASSERT_THAT_ERROR(RecordOr.takeError(), Succeeded());
const memprof::MemProfRecord &Record = RecordOr.get();
- memprof::FrameIdConverter<decltype(MemProfData.Frames)> FrameIdConv(
- MemProfData.Frames);
- memprof::CallStackIdConverter<decltype(MemProfData.CallStacks)> CSIdConv(
- MemProfData.CallStacks, FrameIdConv);
+ memprof::IndexedCallstackIdConveter CSIdConv(MemProfData);
const ::llvm::memprof::MemProfRecord WantRecord =
IndexedMR.toMemProfRecord(CSIdConv);
- ASSERT_EQ(FrameIdConv.LastUnmappedId, std::nullopt)
- << "could not map frame id: " << *FrameIdConv.LastUnmappedId;
- ASSERT_EQ(CSIdConv.LastUnmappedId, std::nullopt)
- << "could not map call stack id: " << *CSIdConv.LastUnmappedId;
+ ASSERT_EQ(CSIdConv.FrameIdConv.LastUnmappedId, std::nullopt)
+ << "could not map frame id: " << *CSIdConv.FrameIdConv.LastUnmappedId;
+ ASSERT_EQ(CSIdConv.CSIdConv.LastUnmappedId, std::nullopt)
+ << "could not map call stack id: " << *CSIdConv.CSIdConv.LastUnmappedId;
EXPECT_THAT(WantRecord, EqualsRecord(Record));
}
@@ -615,10 +609,7 @@ TEST_F(InstrProfTest, test_memprof_merge) {
std::optional<memprof::FrameId> LastUnmappedFrameId;
- memprof::FrameIdConverter<decltype(MemProfData.Frames)> FrameIdConv(
- MemProfData.Frames);
- memprof::CallStackIdConverter<decltype(MemProfData.CallStacks)> CSIdConv(
- MemProfData.CallStacks, FrameIdConv);
+ memprof::IndexedCallstackIdConveter CSIdConv(MemProfData);
const ::llvm::memprof::MemProfRecord WantRecord =
IndexedMR.toMemProfRecord(CSIdConv);
diff --git a/llvm/unittests/ProfileData/MemProfTest.cpp b/llvm/unittests/ProfileData/MemProfTest.cpp
index 2eb85d5..1fe9af5 100644
--- a/llvm/unittests/ProfileData/MemProfTest.cpp
+++ b/llvm/unittests/ProfileData/MemProfTest.cpp
@@ -501,16 +501,13 @@ TEST(MemProf, IndexedMemProfRecordToMemProfRecord) {
IndexedRecord.CallSiteIds.push_back(CS3Id);
IndexedRecord.CallSiteIds.push_back(CS4Id);
- FrameIdConverter<decltype(MemProfData.Frames)> FrameIdConv(
- MemProfData.Frames);
- CallStackIdConverter<decltype(MemProfData.CallStacks)> CSIdConv(
- MemProfData.CallStacks, FrameIdConv);
+ IndexedCallstackIdConveter CSIdConv(MemProfData);
MemProfRecord Record = IndexedRecord.toMemProfRecord(CSIdConv);
// Make sure that all lookups are successful.
- ASSERT_EQ(FrameIdConv.LastUnmappedId, std::nullopt);
- ASSERT_EQ(CSIdConv.LastUnmappedId, std::nullopt);
+ ASSERT_EQ(CSIdConv.FrameIdConv.LastUnmappedId, std::nullopt);
+ ASSERT_EQ(CSIdConv.CSIdConv.LastUnmappedId, std::nullopt);
// Verify the contents of Record.
ASSERT_THAT(Record.AllocSites, SizeIs(2));
@@ -540,17 +537,14 @@ TEST(MemProf, MissingCallStackId) {
// Create empty maps.
IndexedMemProfData MemProfData;
- FrameIdConverter<decltype(MemProfData.Frames)> FrameIdConv(
- MemProfData.Frames);
- CallStackIdConverter<decltype(MemProfData.CallStacks)> CSIdConv(
- MemProfData.CallStacks, FrameIdConv);
+ IndexedCallstackIdConveter CSIdConv(MemProfData);
// We are only interested in errors, not the return value.
(void)IndexedMR.toMemProfRecord(CSIdConv);
- ASSERT_TRUE(CSIdConv.LastUnmappedId.has_value());
- EXPECT_EQ(*CSIdConv.LastUnmappedId, 0xdeadbeefU);
- EXPECT_EQ(FrameIdConv.LastUnmappedId, std::nullopt);
+ ASSERT_TRUE(CSIdConv.CSIdConv.LastUnmappedId.has_value());
+ EXPECT_EQ(*CSIdConv.CSIdConv.LastUnmappedId, 0xdeadbeefU);
+ EXPECT_EQ(CSIdConv.FrameIdConv.LastUnmappedId, std::nullopt);
}
TEST(MemProf, MissingFrameId) {
@@ -561,17 +555,14 @@ TEST(MemProf, MissingFrameId) {
IndexedMemProfRecord IndexedMR;
IndexedMR.AllocSites.emplace_back(CSId, makePartialMIB(), getHotColdSchema());
- FrameIdConverter<decltype(MemProfData.Frames)> FrameIdConv(
- MemProfData.Frames);
- CallStackIdConverter<decltype(MemProfData.CallStacks)> CSIdConv(
- MemProfData.CallStacks, FrameIdConv);
+ IndexedCallstackIdConveter CSIdConv(MemProfData);
// We are only interested in errors, not the return value.
(void)IndexedMR.toMemProfRecord(CSIdConv);
- EXPECT_EQ(CSIdConv.LastUnmappedId, std::nullopt);
- ASSERT_TRUE(FrameIdConv.LastUnmappedId.has_value());
- EXPECT_EQ(*FrameIdConv.LastUnmappedId, 3U);
+ EXPECT_EQ(CSIdConv.CSIdConv.LastUnmappedId, std::nullopt);
+ ASSERT_TRUE(CSIdConv.FrameIdConv.LastUnmappedId.has_value());
+ EXPECT_EQ(*CSIdConv.FrameIdConv.LastUnmappedId, 3U);
}
// Verify CallStackRadixTreeBuilder can handle empty inputs.
@@ -714,10 +705,7 @@ HeapProfileRecords:
const auto &[GUID, IndexedRecord] = MemProfData.Records.front();
EXPECT_EQ(GUID, 0xdeadbeef12345678ULL);
- FrameIdConverter<decltype(MemProfData.Frames)> FrameIdConv(
- MemProfData.Frames);
- CallStackIdConverter<decltype(MemProfData.CallStacks)> CSIdConv(
- MemProfData.CallStacks, FrameIdConv);
+ IndexedCallstackIdConveter CSIdConv(MemProfData);
MemProfRecord Record = IndexedRecord.toMemProfRecord(CSIdConv);
ASSERT_THAT(Record.AllocSites, SizeIs(2));
@@ -760,10 +748,7 @@ HeapProfileRecords:
const auto &[GUID, IndexedRecord] = MemProfData.Records.front();
EXPECT_EQ(GUID, IndexedMemProfRecord::getGUID("_Z3fooi"));
- FrameIdConverter<decltype(MemProfData.Frames)> FrameIdConv(
- MemProfData.Frames);
- CallStackIdConverter<decltype(MemProfData.CallStacks)> CSIdConv(
- MemProfData.CallStacks, FrameIdConv);
+ IndexedCallstackIdConveter CSIdConv(MemProfData);
MemProfRecord Record = IndexedRecord.toMemProfRecord(CSIdConv);
ASSERT_THAT(Record.AllocSites, SizeIs(1));