Skip to content

Commit d403516

Browse files
[memprof] Update YAML traits for writer purposes
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.
1 parent 32b821c commit d403516

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed

llvm/include/llvm/ProfileData/MemProf.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,6 +1177,11 @@ template <> struct MappingTraits<memprof::Frame> {
11771177
(void)Column;
11781178
(void)IsInlineFrame;
11791179
}
1180+
1181+
// Request the inline notation for brevity:
1182+
//
1183+
// { Function: 123, LineOffset: 11, Column: 10; IsInlineFrame: true }
1184+
static const bool flow = true;
11801185
};
11811186

11821187
template <> struct CustomMappingTraits<memprof::PortableMemInfoBlock> {
@@ -1201,8 +1206,13 @@ template <> struct CustomMappingTraits<memprof::PortableMemInfoBlock> {
12011206
Io.setError("Key is not a valid validation event");
12021207
}
12031208

1204-
static void output(IO &Io, memprof::PortableMemInfoBlock &VI) {
1205-
llvm_unreachable("To be implemented");
1209+
static void output(IO &Io, memprof::PortableMemInfoBlock &MIB) {
1210+
auto Schema = MIB.getSchema();
1211+
#define MIBEntryDef(NameTag, Name, Type) \
1212+
if (Schema.test(llvm::to_underlying(memprof::Meta::Name))) \
1213+
Io.mapRequired(#Name, MIB.Name);
1214+
#include "llvm/ProfileData/MIBEntryDef.inc"
1215+
#undef MIBEntryDef
12061216
}
12071217
};
12081218

llvm/unittests/ProfileData/MemProfTest.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -807,4 +807,38 @@ TEST(MemProf, YAMLParser) {
807807
EXPECT_THAT(Record.CallSiteIds,
808808
ElementsAre(hashCallStack(CS3), hashCallStack(CS4)));
809809
}
810+
811+
TEST(MemProf, YAMLWriterFrame) {
812+
Frame F(12, 34, 56, true);
813+
814+
std::string Out;
815+
llvm::raw_string_ostream OS(Out);
816+
llvm::yaml::Output Yout(OS);
817+
Yout << F;
818+
EXPECT_EQ(Out, R"YAML(---
819+
{ Function: 12, LineOffset: 34, Column: 56, Inline: true }
820+
...
821+
)YAML");
822+
}
823+
824+
TEST(MemProf, YAMLWriterMIB) {
825+
MemInfoBlock MIB;
826+
MIB.AllocCount = 111;
827+
MIB.TotalSize = 222;
828+
MIB.TotalLifetime = 333;
829+
MIB.TotalLifetimeAccessDensity = 444;
830+
PortableMemInfoBlock PMIB(MIB, llvm::memprof::getHotColdSchema());
831+
832+
std::string Out;
833+
llvm::raw_string_ostream OS(Out);
834+
llvm::yaml::Output Yout(OS);
835+
Yout << PMIB;
836+
EXPECT_EQ(Out, R"YAML(---
837+
AllocCount: 111
838+
TotalSize: 222
839+
TotalLifetime: 333
840+
TotalLifetimeAccessDensity: 444
841+
...
842+
)YAML");
843+
}
810844
} // namespace

0 commit comments

Comments
 (0)