[llvm] [memprof] Add YAML-based deserialization for MemProf profile (PR #117829)
Snehasish Kumar via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 26 17:54:13 PST 2024
================
@@ -742,4 +742,81 @@ TEST(MemProf, RadixTreeBuilderSuccessiveJumps) {
EXPECT_THAT(Mappings, testing::Contains(testing::Pair(
llvm::memprof::hashCallStack(CS4), 10U)));
}
+
+// Verify that we can parse YAML and retrieve IndexedMemProfData as expected.
+TEST(MemProf, YAMLParser) {
+ StringRef YAMLData = R"YAML(
+---
+HeapProfileRecords:
+- GUID: 0xdeadbeef12345678
+ AllocSites:
+ - Callstack:
+ - {Function: 0x100, LineOffset: 11, Column: 10, Inline: true}
+ - {Function: 0x200, LineOffset: 22, Column: 20, Inline: false}
+ MemInfoBlock:
+ AllocCount: 777
+ TotalSize: 888
+ - Callstack:
+ - {Function: 0x300, LineOffset: 33, Column: 30, Inline: false}
+ - {Function: 0x400, LineOffset: 44, Column: 40, Inline: true}
+ MemInfoBlock:
+ AllocCount: 666
+ TotalSize: 555
+ CallSites:
+ - - {Function: 0x500, LineOffset: 55, Column: 50, Inline: true}
+ - {Function: 0x600, LineOffset: 66, Column: 60, Inline: false}
+ - - {Function: 0x700, LineOffset: 77, Column: 70, Inline: true}
+ - {Function: 0x800, LineOffset: 88, Column: 80, Inline: false}
+)YAML";
+
+ llvm::memprof::YAMLMemProfReader YAMLReader;
+ YAMLReader.parse(YAMLData);
+ llvm::memprof::IndexedMemProfData MemProfData = YAMLReader.takeMemProfData();
+
+ Frame F1(0x100, 11, 10, true);
+ Frame F2(0x200, 22, 20, false);
+ Frame F3(0x300, 33, 30, false);
+ Frame F4(0x400, 44, 40, true);
+ Frame F5(0x500, 55, 50, true);
+ Frame F6(0x600, 66, 60, false);
+ Frame F7(0x700, 77, 70, true);
+ Frame F8(0x800, 88, 80, false);
+
+ llvm::SmallVector<FrameId> CS1 = {F1.hash(), F2.hash()};
+ llvm::SmallVector<FrameId> CS2 = {F3.hash(), F4.hash()};
+ llvm::SmallVector<FrameId> CS3 = {F5.hash(), F6.hash()};
+ llvm::SmallVector<FrameId> CS4 = {F7.hash(), F8.hash()};
+
+ // Verify the entire contents of MemProfData.Frames.
+ EXPECT_THAT(
+ MemProfData.Frames,
+ ::testing::UnorderedElementsAre(
+ ::testing::Pair(F1.hash(), F1), ::testing::Pair(F2.hash(), F2),
----------------
snehasish wrote:
Some using decls would reduce the boilerplate here.
Also for other names such as llvm::memprof::hashCallstack etc below.
https://github.com/llvm/llvm-project/pull/117829
More information about the llvm-commits
mailing list