1 #ifndef MEMPROF_DATA_INC
2 #define MEMPROF_DATA_INC
24 #define PACKED(...) __pragma(pack(push,1)) __VA_ARGS__ __pragma(pack(pop))
26 #define PACKED(...) __VA_ARGS__ __attribute__((__packed__))
30 #define MEMPROF_RAW_MAGIC_64 \
31 ((uint64_t)255 << 56 | (uint64_t)'m' << 48 | (uint64_t)'p' << 40 | (uint64_t)'r' << 32 | \
32 (uint64_t)'o' << 24 | (uint64_t)'f' << 16 | (uint64_t)'r' << 8 | (uint64_t)129)
35 #define MEMPROF_RAW_VERSION 1ULL
40 PACKED(
struct Header {
52 PACKED(
struct SegmentEntry {
58 uint8_t BuildId[32] = {0};
63 SegmentEntry(
const SegmentEntry&
S) {
69 SegmentEntry& operator=(
const SegmentEntry&
S) {
77 return Start ==
S.Start &&
87 __pragma(pack(
push,1))
96 #define MIBEntryDef(NameTag, Name, Type) Type Name;
100 bool operator==(
const MemInfoBlock& Other)
const {
102 #define MIBEntryDef(NameTag, Name, Type) \
103 IsEqual = (IsEqual && Name == Other.Name);
110 #define MIBEntryDef(NameTag, Name, Type) Name = Type();
119 TotalAccessCount = AccessCount;
120 MinAccessCount = AccessCount;
121 MaxAccessCount = AccessCount;
125 AllocTimestamp = AllocTs;
126 DeallocTimestamp = DeallocTs;
127 TotalLifetime = DeallocTimestamp - AllocTimestamp;
128 MinLifetime = TotalLifetime;
129 MaxLifetime = TotalLifetime;
130 AllocCpuId = AllocCpu;
131 DeallocCpuId = DeallocCpu;
132 NumMigratedCpu = AllocCpuId != DeallocCpuId;
135 void Merge(
const MemInfoBlock &newMIB) {
136 AllocCount += newMIB.AllocCount;
138 TotalAccessCount += newMIB.TotalAccessCount;
139 MinAccessCount = newMIB.MinAccessCount < MinAccessCount ? newMIB.MinAccessCount : MinAccessCount;
140 MaxAccessCount = newMIB.MaxAccessCount < MaxAccessCount ? newMIB.MaxAccessCount : MaxAccessCount;
142 TotalSize += newMIB.TotalSize;
143 MinSize = newMIB.MinSize < MinSize ? newMIB.MinSize : MinSize;
144 MaxSize = newMIB.MaxSize < MaxSize ? newMIB.MaxSize : MaxSize;
146 TotalLifetime += newMIB.TotalLifetime;
147 MinLifetime = newMIB.MinLifetime < MinLifetime ? newMIB.MinLifetime : MinLifetime;
148 MaxLifetime = newMIB.MaxLifetime > MaxLifetime ? newMIB.MaxLifetime : MaxLifetime;
152 NumLifetimeOverlaps += newMIB.AllocTimestamp < DeallocTimestamp;
153 AllocTimestamp = newMIB.AllocTimestamp;
154 DeallocTimestamp = newMIB.DeallocTimestamp;
156 NumSameAllocCpu += AllocCpuId == newMIB.AllocCpuId;
157 NumSameDeallocCpu += DeallocCpuId == newMIB.DeallocCpuId;
158 AllocCpuId = newMIB.AllocCpuId;
159 DeallocCpuId = newMIB.DeallocCpuId;
163 } __pragma(pack(pop));
165 } __attribute__((__packed__));