[compiler-rt] [llvm] [Memprof] Adds the option to collect AccessCountHistograms for memprof. (PR #94264)
Teresa Johnson via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 3 11:20:24 PDT 2024
================
@@ -90,111 +93,139 @@ PACKED(struct SegmentEntry {
// MemProfData.inc since it would mean we are embedding a directive (the
// #include for MIBEntryDef) into the macros which is undefined behaviour.
#ifdef _MSC_VER
-__pragma(pack(push,1))
+__pragma(pack(push, 1))
#endif
-// A struct representing the heap allocation characteristics of a particular
-// runtime context. This struct is shared between the compiler-rt runtime and
-// the raw profile reader. The indexed format uses a separate, self-describing
-// backwards compatible format.
-struct MemInfoBlock{
+ // A struct representing the heap allocation characteristics of a particular
+ // runtime context. This struct is shared between the compiler-rt runtime
+ // and the raw profile reader. The indexed format uses a separate,
+ // self-describing backwards compatible format.
+ struct MemInfoBlock {
#define MIBEntryDef(NameTag, Name, Type) Type Name;
#include "MIBEntryDef.inc"
#undef MIBEntryDef
-bool operator==(const MemInfoBlock& Other) const {
- bool IsEqual = true;
-#define MIBEntryDef(NameTag, Name, Type) \
+ bool operator==(const MemInfoBlock &Other) const {
+ bool IsEqual = true;
+#define MIBEntryDef(NameTag, Name, Type) \
IsEqual = (IsEqual && Name == Other.Name);
#include "MIBEntryDef.inc"
#undef MIBEntryDef
- return IsEqual;
-}
+ return IsEqual;
+ }
-MemInfoBlock() {
+ MemInfoBlock() {
#define MIBEntryDef(NameTag, Name, Type) Name = Type();
#include "MIBEntryDef.inc"
#undef MIBEntryDef
-}
-
-MemInfoBlock(uint32_t Size, uint64_t AccessCount, uint32_t AllocTs,
- uint32_t DeallocTs, uint32_t AllocCpu, uint32_t DeallocCpu)
- : MemInfoBlock() {
- AllocCount = 1U;
- TotalAccessCount = AccessCount;
- MinAccessCount = AccessCount;
- MaxAccessCount = AccessCount;
- TotalSize = Size;
- MinSize = Size;
- MaxSize = Size;
- AllocTimestamp = AllocTs;
- DeallocTimestamp = DeallocTs;
- TotalLifetime = DeallocTimestamp - AllocTimestamp;
- MinLifetime = TotalLifetime;
- MaxLifetime = TotalLifetime;
- // Access density is accesses per byte. Multiply by 100 to include the
- // fractional part.
- TotalAccessDensity = AccessCount * 100 / Size;
- MinAccessDensity = TotalAccessDensity;
- MaxAccessDensity = TotalAccessDensity;
- // Lifetime access density is the access density per second of lifetime.
- // Multiply by 1000 to convert denominator lifetime to seconds (using a
- // minimum lifetime of 1ms to avoid divide by 0. Do the multiplication first
- // to reduce truncations to 0.
- TotalLifetimeAccessDensity =
- TotalAccessDensity * 1000 / (TotalLifetime ? TotalLifetime : 1);
- MinLifetimeAccessDensity = TotalLifetimeAccessDensity;
- MaxLifetimeAccessDensity = TotalLifetimeAccessDensity;
- AllocCpuId = AllocCpu;
- DeallocCpuId = DeallocCpu;
- NumMigratedCpu = AllocCpuId != DeallocCpuId;
-}
-
-void Merge(const MemInfoBlock &newMIB) {
- AllocCount += newMIB.AllocCount;
-
- TotalAccessCount += newMIB.TotalAccessCount;
- MinAccessCount = newMIB.MinAccessCount < MinAccessCount ? newMIB.MinAccessCount : MinAccessCount;
- MaxAccessCount = newMIB.MaxAccessCount > MaxAccessCount ? newMIB.MaxAccessCount : MaxAccessCount;
-
- TotalSize += newMIB.TotalSize;
- MinSize = newMIB.MinSize < MinSize ? newMIB.MinSize : MinSize;
- MaxSize = newMIB.MaxSize > MaxSize ? newMIB.MaxSize : MaxSize;
-
- TotalLifetime += newMIB.TotalLifetime;
- MinLifetime = newMIB.MinLifetime < MinLifetime ? newMIB.MinLifetime : MinLifetime;
- MaxLifetime = newMIB.MaxLifetime > MaxLifetime ? newMIB.MaxLifetime : MaxLifetime;
-
- TotalAccessDensity += newMIB.TotalAccessDensity;
- MinAccessDensity = newMIB.MinAccessDensity < MinAccessDensity
- ? newMIB.MinAccessDensity
- : MinAccessDensity;
- MaxAccessDensity = newMIB.MaxAccessDensity > MaxAccessDensity
- ? newMIB.MaxAccessDensity
- : MaxAccessDensity;
-
- TotalLifetimeAccessDensity += newMIB.TotalLifetimeAccessDensity;
- MinLifetimeAccessDensity =
- newMIB.MinLifetimeAccessDensity < MinLifetimeAccessDensity
- ? newMIB.MinLifetimeAccessDensity
- : MinLifetimeAccessDensity;
- MaxLifetimeAccessDensity =
- newMIB.MaxLifetimeAccessDensity > MaxLifetimeAccessDensity
- ? newMIB.MaxLifetimeAccessDensity
- : MaxLifetimeAccessDensity;
-
- // We know newMIB was deallocated later, so just need to check if it was
- // allocated before last one deallocated.
- NumLifetimeOverlaps += newMIB.AllocTimestamp < DeallocTimestamp;
- AllocTimestamp = newMIB.AllocTimestamp;
- DeallocTimestamp = newMIB.DeallocTimestamp;
-
- NumSameAllocCpu += AllocCpuId == newMIB.AllocCpuId;
- NumSameDeallocCpu += DeallocCpuId == newMIB.DeallocCpuId;
- AllocCpuId = newMIB.AllocCpuId;
- DeallocCpuId = newMIB.DeallocCpuId;
-}
+ }
+
+ MemInfoBlock(uint32_t Size, uint64_t AccessCount, uint32_t AllocTs,
----------------
teresajohnson wrote:
I don't think that would be a hard failure. Not sure why it wasn't clang formatted before, but better to stick with the format of the surrounding code. Generally it won't reformat the whole file, though, only your changed lines. How did you invoke it?
https://github.com/llvm/llvm-project/pull/94264
More information about the llvm-commits
mailing list