aboutsummaryrefslogtreecommitdiff
path: root/llvm/unittests/ProfileData/MemProfTest.cpp
diff options
context:
space:
mode:
authorKazu Hirata <kazu@google.com>2024-12-05 13:19:19 -0800
committerKazu Hirata <kazu@google.com>2024-12-05 13:19:19 -0800
commitdbd920b290697b06b4fa1f5c1b37a0d6b91e1559 (patch)
tree86264f0d92227c176af6d24b816f71d98157c387 /llvm/unittests/ProfileData/MemProfTest.cpp
parent3a7d1b5c1643881704d3f6bdc6b9b3c7e16b09a8 (diff)
downloadllvm-dbd920b290697b06b4fa1f5c1b37a0d6b91e1559.zip
llvm-dbd920b290697b06b4fa1f5c1b37a0d6b91e1559.tar.gz
llvm-dbd920b290697b06b4fa1f5c1b37a0d6b91e1559.tar.bz2
Reapply [memprof] Update YAML traits for writer purposes (#118720)
For Frames, we prefer the inline notation for the brevity. For PortableMemInfoBlock, we go through all member fields and print out those that are populated. This iteration works around the unavailability of ScalarTraits<uintptr_t> on macOS.
Diffstat (limited to 'llvm/unittests/ProfileData/MemProfTest.cpp')
-rw-r--r--llvm/unittests/ProfileData/MemProfTest.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/llvm/unittests/ProfileData/MemProfTest.cpp b/llvm/unittests/ProfileData/MemProfTest.cpp
index 3ac64dc..99f95dd 100644
--- a/llvm/unittests/ProfileData/MemProfTest.cpp
+++ b/llvm/unittests/ProfileData/MemProfTest.cpp
@@ -807,4 +807,40 @@ HeapProfileRecords:
EXPECT_THAT(Record.CallSiteIds,
ElementsAre(hashCallStack(CS3), hashCallStack(CS4)));
}
+
+template <typename T> std::string serializeInYAML(T &Val) {
+ std::string Out;
+ llvm::raw_string_ostream OS(Out);
+ llvm::yaml::Output Yout(OS);
+ Yout << Val;
+ return Out;
+}
+
+TEST(MemProf, YAMLWriterFrame) {
+ Frame F(11, 22, 33, true);
+
+ std::string Out = serializeInYAML(F);
+ EXPECT_EQ(Out, R"YAML(---
+{ Function: 11, LineOffset: 22, Column: 33, Inline: true }
+...
+)YAML");
+}
+
+TEST(MemProf, YAMLWriterMIB) {
+ MemInfoBlock MIB;
+ MIB.AllocCount = 111;
+ MIB.TotalSize = 222;
+ MIB.TotalLifetime = 333;
+ MIB.TotalLifetimeAccessDensity = 444;
+ PortableMemInfoBlock PMIB(MIB, llvm::memprof::getHotColdSchema());
+
+ std::string Out = serializeInYAML(PMIB);
+ EXPECT_EQ(Out, R"YAML(---
+AllocCount: 111
+TotalSize: 222
+TotalLifetime: 333
+TotalLifetimeAccessDensity: 444
+...
+)YAML");
+}
} // namespace