1#ifndef MEMPROF_DATA_INC
2#define MEMPROF_DATA_INC
25#define PACKED(...) __pragma(pack(push,1)) __VA_ARGS__ __pragma(pack(pop))
27#define PACKED(...) __VA_ARGS__ __attribute__((__packed__))
31#define MEMPROF_RAW_MAGIC_64 \
32 ((uint64_t)255 << 56 | (uint64_t)'m' << 48 | (uint64_t)'p' << 40 | (uint64_t)'r' << 32 | \
33 (uint64_t)'o' << 24 | (uint64_t)'f' << 16 | (uint64_t)'r' << 8 | (uint64_t)129)
36#define MEMPROF_RAW_VERSION 5ULL
39#define MEMPROF_RAW_SUPPORTED_VERSIONS {3ULL, 4ULL, 5ULL}
41#define MEMPROF_V3_MIB_SIZE 132ULL;
43#define MEMPROF_BUILDID_MAX_SIZE 32ULL
59PACKED(
struct SegmentEntry {
64 uint8_t BuildId[MEMPROF_BUILDID_MAX_SIZE] = {0};
70 SegmentEntry(
const SegmentEntry& S) {
74 BuildIdSize = S.BuildIdSize;
75 memcpy(BuildId, S.BuildId, S.BuildIdSize);
78 SegmentEntry& operator=(
const SegmentEntry& S) {
82 BuildIdSize = S.BuildIdSize;
83 memcpy(BuildId, S.BuildId, S.BuildIdSize);
89 BuildIdSize == S.BuildIdSize &&
90 memcmp(BuildId, S.BuildId, S.BuildIdSize) == 0;
107#define MIBEntryDef(NameTag, Name, Type) Type Name;
113#define MIBEntryDef(NameTag, Name, Type) \
114 IsEqual = (IsEqual && Name == Other.Name);
121#define MIBEntryDef(NameTag, Name, Type) Name = Type();
128 uintptr_t Histogram,
uint32_t HistogramSize)
131 TotalAccessCount = AccessCount;
132 MinAccessCount = AccessCount;
133 MaxAccessCount = AccessCount;
137 AllocTimestamp = AllocTs;
138 DeallocTimestamp = DeallocTs;
139 TotalLifetime = DeallocTimestamp - AllocTimestamp;
140 MinLifetime = TotalLifetime;
141 MaxLifetime = TotalLifetime;
144 TotalAccessDensity = AccessCount * 100 /
Size;
145 MinAccessDensity = TotalAccessDensity;
146 MaxAccessDensity = TotalAccessDensity;
151 TotalLifetimeAccessDensity =
152 TotalAccessDensity * 1000 / (TotalLifetime ? TotalLifetime : 1);
153 MinLifetimeAccessDensity = TotalLifetimeAccessDensity;
154 MaxLifetimeAccessDensity = TotalLifetimeAccessDensity;
155 AllocCpuId = AllocCpu;
156 DeallocCpuId = DeallocCpu;
157 NumMigratedCpu = AllocCpuId != DeallocCpuId;
158 AccessHistogramSize = HistogramSize;
159 AccessHistogram = Histogram;
162void Merge(
const MemInfoBlock &newMIB) {
163 AllocCount += newMIB.AllocCount;
165 TotalAccessCount += newMIB.TotalAccessCount;
166 MinAccessCount = newMIB.MinAccessCount < MinAccessCount ? newMIB.MinAccessCount : MinAccessCount;
167 MaxAccessCount = newMIB.MaxAccessCount > MaxAccessCount ? newMIB.MaxAccessCount : MaxAccessCount;
169 TotalSize += newMIB.TotalSize;
170 MinSize = newMIB.MinSize < MinSize ? newMIB.MinSize : MinSize;
171 MaxSize = newMIB.MaxSize > MaxSize ? newMIB.MaxSize : MaxSize;
173 TotalLifetime += newMIB.TotalLifetime;
174 MinLifetime = newMIB.MinLifetime < MinLifetime ? newMIB.MinLifetime : MinLifetime;
175 MaxLifetime = newMIB.MaxLifetime > MaxLifetime ? newMIB.MaxLifetime : MaxLifetime;
177 TotalAccessDensity += newMIB.TotalAccessDensity;
178 MinAccessDensity = newMIB.MinAccessDensity < MinAccessDensity
179 ? newMIB.MinAccessDensity
181 MaxAccessDensity = newMIB.MaxAccessDensity > MaxAccessDensity
182 ? newMIB.MaxAccessDensity
185 TotalLifetimeAccessDensity += newMIB.TotalLifetimeAccessDensity;
186 MinLifetimeAccessDensity =
187 newMIB.MinLifetimeAccessDensity < MinLifetimeAccessDensity
188 ? newMIB.MinLifetimeAccessDensity
189 : MinLifetimeAccessDensity;
190 MaxLifetimeAccessDensity =
191 newMIB.MaxLifetimeAccessDensity > MaxLifetimeAccessDensity
192 ? newMIB.MaxLifetimeAccessDensity
193 : MaxLifetimeAccessDensity;
197 NumLifetimeOverlaps += newMIB.AllocTimestamp < DeallocTimestamp;
198 AllocTimestamp = newMIB.AllocTimestamp;
199 DeallocTimestamp = newMIB.DeallocTimestamp;
201 NumSameAllocCpu += AllocCpuId == newMIB.AllocCpuId;
202 NumSameDeallocCpu += DeallocCpuId == newMIB.DeallocCpuId;
203 AllocCpuId = newMIB.AllocCpuId;
204 DeallocCpuId = newMIB.DeallocCpuId;
208 uintptr_t ShorterHistogram;
210 if (newMIB.AccessHistogramSize > AccessHistogramSize) {
211 ShorterHistogram = AccessHistogram;
212 ShorterHistogramSize = AccessHistogramSize;
214 AccessHistogram = newMIB.AccessHistogram;
215 AccessHistogramSize = newMIB.AccessHistogramSize;
217 ShorterHistogram = newMIB.AccessHistogram;
218 ShorterHistogramSize = newMIB.AccessHistogramSize;
220 for (
size_t i = 0; i < ShorterHistogramSize; ++i) {
226} __pragma(pack(pop));
228} __attribute__((__packed__));
231constexpr int MantissaBits = 12;
232constexpr int ExponentBits = 4;
233constexpr uint16_t MaxMantissa = (1
U << MantissaBits) - 1;
234constexpr uint16_t MaxExponent = (1
U << ExponentBits) - 1;
235constexpr uint64_t MaxRepresentableValue =
static_cast<uint64_t>(MaxMantissa)
243 if (Count > MaxRepresentableValue)
244 Count = MaxRepresentableValue;
246 if (Count <= MaxMantissa)
251 while (M > MaxMantissa) {
255 return (
E << MantissaBits) |
static_cast<uint16_t>(
M);
261 const uint16_t E = EncodedValue >> MantissaBits;
262 const uint16_t M = EncodedValue & MaxMantissa;
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
std::optional< std::vector< StOtherPiece > > Other
Merge contiguous icmps into a memcmp
static Constant * SegmentOffset(IRBuilderBase &IRB, int Offset, unsigned AddressSpace)
This is an optimization pass for GlobalISel generic memory operations.
bool operator==(const AddressRangeValuePair &LHS, const AddressRangeValuePair &RHS)