bool operator!=(const Frame &Other) const { return !operator==(Other); }
// Write the contents of the frame to the ostream \p OS.
- void write(raw_ostream & OS) const {
+ void serialize(raw_ostream & OS) const {
using namespace support;
endian::Writer LE(OS, little);
LE.write<uint32_t>(Column);
LE.write<bool>(IsInlineFrame);
}
+
+ // Read a frame from char data which has been serialized as little endian.
+ static Frame deserialize(const unsigned char *Ptr) {
+ using namespace support;
+ return Frame(
+ /*Function=*/endian::readNext<uint64_t, little, unaligned>(Ptr),
+ /*LineOffset=*/endian::readNext<uint32_t, little, unaligned>(Ptr),
+ /*Column=*/endian::readNext<uint32_t, little, unaligned>(Ptr),
+ /*IsInlineFrame=*/endian::readNext<bool, little, unaligned>(Ptr));
+ }
+
+ // Returns the size of the frame information.
+ static constexpr size_t serializedSize() {
+ return sizeof(Frame::Function) + sizeof(Frame::LineOffset) +
+ sizeof(Frame::Column) + sizeof(Frame::IsInlineFrame);
+ }
});
// The dynamic calling context for the allocation.
for (const MemProfRecord &MR : Records) {
LE.write<uint64_t>(MR.CallStack.size());
for (const MemProfRecord::Frame &F : MR.CallStack) {
- F.write(OS);
+ F.serialize(OS);
}
MR.Info.serialize(Schema, OS);
}
const uint64_t NumFrames =
endian::readNext<uint64_t, little, unaligned>(Ptr);
for (uint64_t J = 0; J < NumFrames; J++) {
- const auto F = *reinterpret_cast<const MemProfRecord::Frame *>(Ptr);
- Ptr += sizeof(MemProfRecord::Frame);
+ const auto F = MemProfRecord::Frame::deserialize(Ptr);
+ Ptr += MemProfRecord::Frame::serializedSize();
MR.CallStack.push_back(F);
}
MR.Info.deserialize(Schema, Ptr);