Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 29 additions & 4 deletions llvm/include/llvm/ProfileData/MemProfYAML.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,36 @@ template <> struct ScalarTraits<memprof::GUIDHex64> {
};

template <> struct MappingTraits<memprof::Frame> {
// Essentially the same as memprof::Frame except that Function is of type
// memprof::GUIDHex64 instead of GlobalValue::GUID. This class helps in two
// ways. During serialization, we print Function as a 16-digit hexadecimal
// number. During deserialization, we accept a function name as an
// alternative to the usual GUID expressed as a hexadecimal number.
class FrameWithHex64 {
public:
FrameWithHex64(IO &) {}
FrameWithHex64(IO &, const memprof::Frame &F)
: Function(F.Function), LineOffset(F.LineOffset), Column(F.Column),
IsInlineFrame(F.IsInlineFrame) {}
memprof::Frame denormalize(IO &) {
return memprof::Frame(Function, LineOffset, Column, IsInlineFrame);
}

memprof::GUIDHex64 Function = 0;
static_assert(std::is_same_v<decltype(Function.value),
decltype(memprof::Frame::Function)>);
decltype(memprof::Frame::LineOffset) LineOffset = 0;
decltype(memprof::Frame::Column) Column = 0;
decltype(memprof::Frame::IsInlineFrame) IsInlineFrame = false;
};

static void mapping(IO &Io, memprof::Frame &F) {
Io.mapRequired("Function", F.Function);
Io.mapRequired("LineOffset", F.LineOffset);
Io.mapRequired("Column", F.Column);
Io.mapRequired("IsInlineFrame", F.IsInlineFrame);
MappingNormalization<FrameWithHex64, memprof::Frame> Keys(Io, F);

Io.mapRequired("Function", Keys->Function);
Io.mapRequired("LineOffset", Keys->LineOffset);
Io.mapRequired("Column", Keys->Column);
Io.mapRequired("IsInlineFrame", Keys->IsInlineFrame);

// Assert that the definition of Frame matches what we expect. The
// structured bindings below detect changes to the number of fields.
Expand Down
16 changes: 8 additions & 8 deletions llvm/test/tools/llvm-profdata/memprof-yaml.test
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,24 @@ HeapProfileRecords:
- GUID: 0xdeadbeef12345678
AllocSites:
- Callstack:
- { Function: 100, LineOffset: 11, Column: 10, IsInlineFrame: true }
- { Function: 200, LineOffset: 22, Column: 20, IsInlineFrame: false }
- { Function: 0x1111111111111111, LineOffset: 11, Column: 10, IsInlineFrame: true }
- { Function: 0x2222222222222222, LineOffset: 22, Column: 20, IsInlineFrame: false }
MemInfoBlock:
AllocCount: 111
TotalSize: 222
TotalLifetime: 333
TotalLifetimeAccessDensity: 444
- Callstack:
- { Function: 300, LineOffset: 33, Column: 30, IsInlineFrame: false }
- { Function: 400, LineOffset: 44, Column: 40, IsInlineFrame: true }
- { Function: 0x3333333333333333, LineOffset: 33, Column: 30, IsInlineFrame: false }
- { Function: 0x4444444444444444, LineOffset: 44, Column: 40, IsInlineFrame: true }
MemInfoBlock:
AllocCount: 555
TotalSize: 666
TotalLifetime: 777
TotalLifetimeAccessDensity: 888
CallSites:
- - { Function: 500, LineOffset: 55, Column: 50, IsInlineFrame: true }
- { Function: 600, LineOffset: 66, Column: 60, IsInlineFrame: false }
- - { Function: 700, LineOffset: 77, Column: 70, IsInlineFrame: true }
- { Function: 800, LineOffset: 88, Column: 80, IsInlineFrame: false }
- - { Function: 0x5555555555555555, LineOffset: 55, Column: 50, IsInlineFrame: true }
- { Function: 0x6666666666666666, LineOffset: 66, Column: 60, IsInlineFrame: false }
- - { Function: 0x7777777777777777, LineOffset: 77, Column: 70, IsInlineFrame: true }
- { Function: 0x8888888888888888, LineOffset: 88, Column: 80, IsInlineFrame: false }
...
4 changes: 3 additions & 1 deletion llvm/tools/llvm-profdata/llvm-profdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3307,7 +3307,9 @@ static int showMemProfProfile(ShowFormat SFormat, raw_fd_ostream &OS) {

auto Reader = std::move(ReaderOrErr.get());
memprof::AllMemProfData Data = Reader->getAllMemProfData();
yaml::Output Yout(OS);
// Construct yaml::Output with the maximum column width of 80 so that each
// Frame fits in one line.
yaml::Output Yout(OS, nullptr, 80);
Yout << Data;

return 0;
Expand Down
4 changes: 2 additions & 2 deletions llvm/unittests/ProfileData/MemProfTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -804,11 +804,11 @@ template <typename T> std::string serializeInYAML(T &Val) {
}

TEST(MemProf, YAMLWriterFrame) {
Frame F(11, 22, 33, true);
Frame F(0x0123456789abcdefULL, 22, 33, true);

std::string Out = serializeInYAML(F);
EXPECT_EQ(Out, R"YAML(---
{ Function: 11, LineOffset: 22, Column: 33, IsInlineFrame: true }
{ Function: 0x0123456789abcdef, LineOffset: 22, Column: 33, IsInlineFrame: true }
...
)YAML");
}
Expand Down
Loading