diff options
author | Kazu Hirata <kazu@google.com> | 2024-12-10 21:29:57 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-12-10 21:29:57 -0800 |
commit | 76b493128cb171455a1890f7bd2b54f32b7ec2a7 (patch) | |
tree | 8a31426698937d62d1496b97cf0a7f47f0a2ed5a /llvm/unittests/ProfileData/MemProfTest.cpp | |
parent | 3146d57b646c869564669c3e074d6d4fc1ca7500 (diff) | |
download | llvm-76b493128cb171455a1890f7bd2b54f32b7ec2a7.zip llvm-76b493128cb171455a1890f7bd2b54f32b7ec2a7.tar.gz llvm-76b493128cb171455a1890f7bd2b54f32b7ec2a7.tar.bz2 |
[memprof] Accept a function name in YAML (#119453)
This patch does two things:
- During deserialization, we accept a function name as an alternative
to the usual GUID represented as a hexadecimal number.
- During serialization, we print a GUID as a 16-digit hexadecimal
number prefixed with 0x in the usual way. (Without this patch, we
print a decimal number, which is not customary.)
In YAML, the MemProf profile is a vector of pairs of GUID and
MemProfRecord. This patch accepts a function name for the GUID, but
it does not accept a function name for the GUID used in Frames yet.
That will be addressed in a subsequent patch.
Diffstat (limited to 'llvm/unittests/ProfileData/MemProfTest.cpp')
-rw-r--r-- | llvm/unittests/ProfileData/MemProfTest.cpp | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/llvm/unittests/ProfileData/MemProfTest.cpp b/llvm/unittests/ProfileData/MemProfTest.cpp index 093b3a2..5886d3e 100644 --- a/llvm/unittests/ProfileData/MemProfTest.cpp +++ b/llvm/unittests/ProfileData/MemProfTest.cpp @@ -35,6 +35,7 @@ using ::llvm::StringRef; using ::llvm::object::SectionedAddress; using ::llvm::symbolize::SymbolizableModule; using ::testing::ElementsAre; +using ::testing::IsEmpty; using ::testing::Pair; using ::testing::Return; using ::testing::SizeIs; @@ -760,6 +761,43 @@ HeapProfileRecords: ElementsAre(hashCallStack(CS3), hashCallStack(CS4))); } +// Verify that the YAML parser accepts a GUID expressed as a function name. +TEST(MemProf, YAMLParserGUID) { + StringRef YAMLData = R"YAML( +--- +HeapProfileRecords: +- GUID: _Z3fooi + AllocSites: + - Callstack: + - {Function: 0x100, LineOffset: 11, Column: 10, IsInlineFrame: true} + MemInfoBlock: {} + CallSites: [] +)YAML"; + + YAMLMemProfReader YAMLReader; + YAMLReader.parse(YAMLData); + IndexedMemProfData MemProfData = YAMLReader.takeMemProfData(); + + Frame F1(0x100, 11, 10, true); + + llvm::SmallVector<FrameId> CS1 = {F1.hash()}; + + // Verify the entire contents of MemProfData.Frames. + EXPECT_THAT(MemProfData.Frames, UnorderedElementsAre(Pair(F1.hash(), F1))); + + // Verify the entire contents of MemProfData.Frames. + EXPECT_THAT(MemProfData.CallStacks, + UnorderedElementsAre(Pair(hashCallStack(CS1), CS1))); + + // Verify the entire contents of MemProfData.Records. + ASSERT_THAT(MemProfData.Records, SizeIs(1)); + const auto &[GUID, Record] = MemProfData.Records.front(); + EXPECT_EQ(GUID, IndexedMemProfRecord::getGUID("_Z3fooi")); + ASSERT_THAT(Record.AllocSites, SizeIs(1)); + EXPECT_EQ(Record.AllocSites[0].CSId, hashCallStack(CS1)); + EXPECT_THAT(Record.CallSiteIds, IsEmpty()); +} + template <typename T> std::string serializeInYAML(T &Val) { std::string Out; llvm::raw_string_ostream OS(Out); |