Skip to content

Commit 46aedce

Browse files
Address comments.
1 parent 1ee8dff commit 46aedce

File tree

2 files changed

+30
-16
lines changed

2 files changed

+30
-16
lines changed

llvm/lib/ProfileData/MemProfReader.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,20 @@ template <> struct MappingTraits<memprof::Frame> {
4949
Io.mapRequired("LineOffset", F.LineOffset);
5050
Io.mapRequired("Column", F.Column);
5151
Io.mapRequired("Inline", F.IsInlineFrame);
52+
53+
// Assert that the definition of Frame matches what we expect. The
54+
// structured bindings below detect changes to the number of fields.
55+
// static_assert checks the type of each field.
56+
const auto &[Function, SymbolName, LineOffset, Column, IsInlineFrame] = F;
57+
static_assert(
58+
std::is_same_v<remove_cvref_t<decltype(Function)>, GlobalValue::GUID>);
59+
static_assert(std::is_same_v<remove_cvref_t<decltype(SymbolName)>,
60+
std::unique_ptr<std::string>>);
61+
static_assert(
62+
std::is_same_v<remove_cvref_t<decltype(LineOffset)>, uint32_t>);
63+
static_assert(std::is_same_v<remove_cvref_t<decltype(Column)>, uint32_t>);
64+
static_assert(
65+
std::is_same_v<remove_cvref_t<decltype(IsInlineFrame)>, bool>);
5266
}
5367
};
5468

llvm/unittests/ProfileData/MemProfTest.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ using ::llvm::memprof::CallStackId;
3434
using ::llvm::memprof::CallStackMap;
3535
using ::llvm::memprof::Frame;
3636
using ::llvm::memprof::FrameId;
37+
using ::llvm::memprof::hashCallStack;
3738
using ::llvm::memprof::IndexedAllocationInfo;
3839
using ::llvm::memprof::IndexedMemProfRecord;
3940
using ::llvm::memprof::MemInfoBlock;
@@ -46,8 +47,11 @@ using ::llvm::memprof::RawMemProfReader;
4647
using ::llvm::memprof::SegmentEntry;
4748
using ::llvm::object::SectionedAddress;
4849
using ::llvm::symbolize::SymbolizableModule;
50+
using ::testing::ElementsAre;
51+
using ::testing::Pair;
4952
using ::testing::Return;
5053
using ::testing::SizeIs;
54+
using ::testing::UnorderedElementsAre;
5155

5256
class MockSymbolizer : public SymbolizableModule {
5357
public:
@@ -788,35 +792,31 @@ TEST(MemProf, YAMLParser) {
788792
llvm::SmallVector<FrameId> CS4 = {F7.hash(), F8.hash()};
789793

790794
// Verify the entire contents of MemProfData.Frames.
791-
EXPECT_THAT(
792-
MemProfData.Frames,
793-
::testing::UnorderedElementsAre(
794-
::testing::Pair(F1.hash(), F1), ::testing::Pair(F2.hash(), F2),
795-
::testing::Pair(F3.hash(), F3), ::testing::Pair(F4.hash(), F4),
796-
::testing::Pair(F5.hash(), F5), ::testing::Pair(F6.hash(), F6),
797-
::testing::Pair(F7.hash(), F7), ::testing::Pair(F8.hash(), F8)));
795+
EXPECT_THAT(MemProfData.Frames,
796+
UnorderedElementsAre(Pair(F1.hash(), F1), Pair(F2.hash(), F2),
797+
Pair(F3.hash(), F3), Pair(F4.hash(), F4),
798+
Pair(F5.hash(), F5), Pair(F6.hash(), F6),
799+
Pair(F7.hash(), F7), Pair(F8.hash(), F8)));
798800

799801
// Verify the entire contents of MemProfData.Frames.
800802
EXPECT_THAT(MemProfData.CallStacks,
801-
::testing::UnorderedElementsAre(
802-
::testing::Pair(llvm::memprof::hashCallStack(CS1), CS1),
803-
::testing::Pair(llvm::memprof::hashCallStack(CS2), CS2),
804-
::testing::Pair(llvm::memprof::hashCallStack(CS3), CS3),
805-
::testing::Pair(llvm::memprof::hashCallStack(CS4), CS4)));
803+
UnorderedElementsAre(Pair(hashCallStack(CS1), CS1),
804+
Pair(hashCallStack(CS2), CS2),
805+
Pair(hashCallStack(CS3), CS3),
806+
Pair(hashCallStack(CS4), CS4)));
806807

807808
// Verify the entire contents of MemProfData.Records.
808809
ASSERT_THAT(MemProfData.Records, SizeIs(1));
809810
const auto &[GUID, Record] = *MemProfData.Records.begin();
810811
EXPECT_EQ(GUID, 0xdeadbeef12345678ULL);
811812
ASSERT_THAT(Record.AllocSites, SizeIs(2));
812-
EXPECT_EQ(Record.AllocSites[0].CSId, llvm::memprof::hashCallStack(CS1));
813+
EXPECT_EQ(Record.AllocSites[0].CSId, hashCallStack(CS1));
813814
EXPECT_EQ(Record.AllocSites[0].Info.getAllocCount(), 777U);
814815
EXPECT_EQ(Record.AllocSites[0].Info.getTotalSize(), 888U);
815-
EXPECT_EQ(Record.AllocSites[1].CSId, llvm::memprof::hashCallStack(CS2));
816+
EXPECT_EQ(Record.AllocSites[1].CSId, hashCallStack(CS2));
816817
EXPECT_EQ(Record.AllocSites[1].Info.getAllocCount(), 666U);
817818
EXPECT_EQ(Record.AllocSites[1].Info.getTotalSize(), 555U);
818819
EXPECT_THAT(Record.CallSiteIds,
819-
::testing::ElementsAre(llvm::memprof::hashCallStack(CS3),
820-
llvm::memprof::hashCallStack(CS4)));
820+
ElementsAre(hashCallStack(CS3), hashCallStack(CS4)));
821821
}
822822
} // namespace

0 commit comments

Comments
 (0)