[compiler-rt] 857ec0d - Revert "[memprof] Refactor out the MemInfoBlock into a macro based def."
Snehasish Kumar via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 14 11:43:46 PST 2022
Author: Snehasish Kumar
Date: 2022-02-14T11:42:58-08:00
New Revision: 857ec0d01f8021ff0d9540fcbf6ff24e29868ba4
URL: https://github.com/llvm/llvm-project/commit/857ec0d01f8021ff0d9540fcbf6ff24e29868ba4
DIFF: https://github.com/llvm/llvm-project/commit/857ec0d01f8021ff0d9540fcbf6ff24e29868ba4.diff
LOG: Revert "[memprof] Refactor out the MemInfoBlock into a macro based def."
This reverts commit 9def83c6d02944b2931efd50cd2491953a772aab. [4/4]
Added:
Modified:
compiler-rt/include/profile/MemProfData.inc
compiler-rt/lib/memprof/memprof_allocator.cpp
compiler-rt/lib/memprof/tests/rawprofile.cpp
llvm/include/llvm/ProfileData/MemProf.h
llvm/include/llvm/ProfileData/MemProfData.inc
llvm/unittests/ProfileData/MemProfTest.cpp
Removed:
compiler-rt/include/profile/MIBEntryDef.inc
llvm/include/llvm/ProfileData/MIBEntryDef.inc
################################################################################
diff --git a/compiler-rt/include/profile/MIBEntryDef.inc b/compiler-rt/include/profile/MIBEntryDef.inc
deleted file mode 100644
index db4dbf4fd52f8..0000000000000
--- a/compiler-rt/include/profile/MIBEntryDef.inc
+++ /dev/null
@@ -1,51 +0,0 @@
-/*===-- MemEntryDef.inc - MemProf profiling runtime macros -*- C++ -*-======== *\
-|*
-|* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-|* See https://llvm.org/LICENSE.txt for license information.
-|* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-|*
-\*===----------------------------------------------------------------------===*/
-/*
- * This file defines the macros for memprof profiling data structures.
- * Eg. usage to define the memprof meminfoblock struct:
- *
- * struct MemInfoBlock {
- * #define MIBEntryDef(NameTag, Name, Type) Type Name;
- * #include MIBEntryDef.inc
- * #undef MIBEntryDef
- * };
- *
- * This file has two identical copies. The primary copy lives in LLVM and
- * the other one sits in compiler-rt/include/profile directory. To make changes
- * in this file, first modify the primary copy and copy it over to compiler-rt.
- * Testing of any change in this file can start only after the two copies are
- * synced up.
- *
-\*===----------------------------------------------------------------------===*/
-
-#ifndef MIBEntryDef
-#define MIBEntryDef(NameTag, Name, Type)
-#endif
-
-MIBEntryDef(AllocCount = 1, AllocCount, uint32_t)
-MIBEntryDef(TotalAccessCount = 2, TotalAccessCount, uint64_t)
-MIBEntryDef(MinAccessCount = 3, MinAccessCount, uint64_t)
-MIBEntryDef(MaxAccessCount = 4, MaxAccessCount, uint64_t)
-MIBEntryDef(TotalSize = 5, TotalSize, uint64_t)
-MIBEntryDef(MinSize = 6, MinSize, uint32_t)
-MIBEntryDef(MaxSize = 7, MaxSize, uint32_t)
-MIBEntryDef(AllocTimestamp = 8, AllocTimestamp, uint32_t)
-MIBEntryDef(DeallocTimestamp = 9, DeallocTimestamp, uint32_t)
-MIBEntryDef(TotalLifetime = 10, TotalLifetime, uint64_t)
-MIBEntryDef(MinLifetime = 11, MinLifetime, uint32_t)
-MIBEntryDef(MaxLifetime = 12, MaxLifetime, uint32_t)
-MIBEntryDef(AllocCpuId = 13, AllocCpuId, uint32_t)
-MIBEntryDef(DeallocCpuId = 14, DeallocCpuId, uint32_t)
-MIBEntryDef(NumMigratedCpu = 15, NumMigratedCpu, uint32_t)
-MIBEntryDef(NumLifetimeOverlaps = 16, NumLifetimeOverlaps, uint32_t)
-MIBEntryDef(NumSameAllocCpu = 17, NumSameAllocCpu, uint32_t)
-MIBEntryDef(NumSameDeallocCpu = 18, NumSameDeallocCpu, uint32_t)
-MIBEntryDef(DataTypeId = 19, DataTypeId, uint64_t)
-
-
-
diff --git a/compiler-rt/include/profile/MemProfData.inc b/compiler-rt/include/profile/MemProfData.inc
index 38698be9ea0ec..20f8308645c1e 100644
--- a/compiler-rt/include/profile/MemProfData.inc
+++ b/compiler-rt/include/profile/MemProfData.inc
@@ -80,80 +80,71 @@ PACKED(struct SegmentEntry {
}
});
-// Packed struct definition for MSVC. We can't use the PACKED macro defined in
-// 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))
-#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{
-
-#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) \
- IsEqual = (IsEqual && Name == Other.Name);
-#include "MIBEntryDef.inc"
-#undef MIBEntryDef
- return IsEqual;
-}
-
-MemInfoBlock() : AllocCount(0) {}
-
-MemInfoBlock(uint32_t size, uint64_t access_count, uint32_t alloc_timestamp,
- uint32_t dealloc_timestamp, uint32_t alloc_cpu, uint32_t dealloc_cpu)
- : AllocCount(1), TotalAccessCount(access_count),
- MinAccessCount(access_count), MaxAccessCount(access_count),
- TotalSize(size), MinSize(size), MaxSize(size),
- AllocTimestamp(alloc_timestamp), DeallocTimestamp(dealloc_timestamp),
- TotalLifetime(dealloc_timestamp - alloc_timestamp),
- MinLifetime(TotalLifetime), MaxLifetime(TotalLifetime),
- AllocCpuId(alloc_cpu), DeallocCpuId(dealloc_cpu),
- NumLifetimeOverlaps(0), NumSameAllocCpu(0),
- NumSameDeallocCpu(0) {
- 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;
-
- // 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;
-}
+PACKED(struct MemInfoBlock {
+ uint32_t alloc_count;
+ uint64_t total_access_count, min_access_count, max_access_count;
+ uint64_t total_size;
+ uint32_t min_size, max_size;
+ uint32_t alloc_timestamp, dealloc_timestamp;
+ uint64_t total_lifetime;
+ uint32_t min_lifetime, max_lifetime;
+ uint32_t alloc_cpu_id, dealloc_cpu_id;
+ uint32_t num_migrated_cpu;
+
+ // Only compared to prior deallocated object currently.
+ uint32_t num_lifetime_overlaps;
+ uint32_t num_same_alloc_cpu;
+ uint32_t num_same_dealloc_cpu;
+
+ uint64_t data_type_id; // TODO: hash of type name
+
+ MemInfoBlock() : alloc_count(0) {}
+
+ MemInfoBlock(uint32_t size, uint64_t access_count, uint32_t alloc_timestamp,
+ uint32_t dealloc_timestamp, uint32_t alloc_cpu, uint32_t dealloc_cpu)
+ : alloc_count(1), total_access_count(access_count),
+ min_access_count(access_count), max_access_count(access_count),
+ total_size(size), min_size(size), max_size(size),
+ alloc_timestamp(alloc_timestamp), dealloc_timestamp(dealloc_timestamp),
+ total_lifetime(dealloc_timestamp - alloc_timestamp),
+ min_lifetime(total_lifetime), max_lifetime(total_lifetime),
+ alloc_cpu_id(alloc_cpu), dealloc_cpu_id(dealloc_cpu),
+ num_lifetime_overlaps(0), num_same_alloc_cpu(0),
+ num_same_dealloc_cpu(0) {
+ num_migrated_cpu = alloc_cpu_id != dealloc_cpu_id;
+ }
-#ifdef _MSC_VER
-} __pragma(pack(pop));
-#else
-} __attribute__((__packed__));
-#endif
+ void Merge(const MemInfoBlock &newMIB) {
+ alloc_count += newMIB.alloc_count;
+
+ total_access_count += newMIB.total_access_count;
+ min_access_count = newMIB.min_access_count < min_access_count ? newMIB.min_access_count : min_access_count;
+ max_access_count = newMIB.max_access_count < max_access_count ? newMIB.max_access_count : max_access_count;
+
+ total_size += newMIB.total_size;
+ min_size = newMIB.min_size < min_size ? newMIB.min_size : min_size;
+ max_size = newMIB.max_size < max_size ? newMIB.max_size : max_size;
+
+ total_lifetime += newMIB.total_lifetime;
+ min_lifetime = newMIB.min_lifetime < min_lifetime ? newMIB.min_lifetime : min_lifetime;
+ max_lifetime = newMIB.max_lifetime > max_lifetime ? newMIB.max_lifetime : max_lifetime;
+
+ // We know newMIB was deallocated later, so just need to check if it was
+ // allocated before last one deallocated.
+ num_lifetime_overlaps += newMIB.alloc_timestamp < dealloc_timestamp;
+ alloc_timestamp = newMIB.alloc_timestamp;
+ dealloc_timestamp = newMIB.dealloc_timestamp;
+
+ num_same_alloc_cpu += alloc_cpu_id == newMIB.alloc_cpu_id;
+ num_same_dealloc_cpu += dealloc_cpu_id == newMIB.dealloc_cpu_id;
+ alloc_cpu_id = newMIB.alloc_cpu_id;
+ dealloc_cpu_id = newMIB.dealloc_cpu_id;
+ }
+});
} // namespace memprof
} // namespace llvm
diff --git a/compiler-rt/lib/memprof/memprof_allocator.cpp b/compiler-rt/lib/memprof/memprof_allocator.cpp
index 1475e2cf36bd2..14e7bfe53534a 100644
--- a/compiler-rt/lib/memprof/memprof_allocator.cpp
+++ b/compiler-rt/lib/memprof/memprof_allocator.cpp
@@ -43,32 +43,32 @@ void Print(const MemInfoBlock &M, const u64 id, bool print_terse) {
u64 p;
if (print_terse) {
- p = M.TotalSize * 100 / M.AllocCount;
- Printf("MIB:%llu/%u/%llu.%02llu/%u/%u/", id, M.AllocCount, p / 100, p % 100,
- M.MinSize, M.MaxSize);
- p = M.TotalAccessCount * 100 / M.AllocCount;
- Printf("%llu.%02llu/%llu/%llu/", p / 100, p % 100, M.MinAccessCount,
- M.MaxAccessCount);
- p = M.TotalLifetime * 100 / M.AllocCount;
- Printf("%llu.%02llu/%u/%u/", p / 100, p % 100, M.MinLifetime,
- M.MaxLifetime);
- Printf("%u/%u/%u/%u\n", M.NumMigratedCpu, M.NumLifetimeOverlaps,
- M.NumSameAllocCpu, M.NumSameDeallocCpu);
+ p = M.total_size * 100 / M.alloc_count;
+ Printf("MIB:%llu/%u/%llu.%02llu/%u/%u/", id, M.alloc_count, p / 100,
+ p % 100, M.min_size, M.max_size);
+ p = M.total_access_count * 100 / M.alloc_count;
+ Printf("%llu.%02llu/%llu/%llu/", p / 100, p % 100, M.min_access_count,
+ M.max_access_count);
+ p = M.total_lifetime * 100 / M.alloc_count;
+ Printf("%llu.%02llu/%u/%u/", p / 100, p % 100, M.min_lifetime,
+ M.max_lifetime);
+ Printf("%u/%u/%u/%u\n", M.num_migrated_cpu, M.num_lifetime_overlaps,
+ M.num_same_alloc_cpu, M.num_same_dealloc_cpu);
} else {
- p = M.TotalSize * 100 / M.AllocCount;
+ p = M.total_size * 100 / M.alloc_count;
Printf("Memory allocation stack id = %llu\n", id);
Printf("\talloc_count %u, size (ave/min/max) %llu.%02llu / %u / %u\n",
- M.AllocCount, p / 100, p % 100, M.MinSize, M.MaxSize);
- p = M.TotalAccessCount * 100 / M.AllocCount;
+ M.alloc_count, p / 100, p % 100, M.min_size, M.max_size);
+ p = M.total_access_count * 100 / M.alloc_count;
Printf("\taccess_count (ave/min/max): %llu.%02llu / %llu / %llu\n", p / 100,
- p % 100, M.MinAccessCount, M.MaxAccessCount);
- p = M.TotalLifetime * 100 / M.AllocCount;
+ p % 100, M.min_access_count, M.max_access_count);
+ p = M.total_lifetime * 100 / M.alloc_count;
Printf("\tlifetime (ave/min/max): %llu.%02llu / %u / %u\n", p / 100,
- p % 100, M.MinLifetime, M.MaxLifetime);
+ p % 100, M.min_lifetime, M.max_lifetime);
Printf("\tnum migrated: %u, num lifetime overlaps: %u, num same alloc "
"cpu: %u, num same dealloc_cpu: %u\n",
- M.NumMigratedCpu, M.NumLifetimeOverlaps, M.NumSameAllocCpu,
- M.NumSameDeallocCpu);
+ M.num_migrated_cpu, M.num_lifetime_overlaps, M.num_same_alloc_cpu,
+ M.num_same_dealloc_cpu);
}
}
} // namespace
diff --git a/compiler-rt/lib/memprof/tests/rawprofile.cpp b/compiler-rt/lib/memprof/tests/rawprofile.cpp
index 7f6398d1cf86e..6181d80fadf68 100644
--- a/compiler-rt/lib/memprof/tests/rawprofile.cpp
+++ b/compiler-rt/lib/memprof/tests/rawprofile.cpp
@@ -82,8 +82,8 @@ TEST(MemProf, Basic) {
// Since we want to override the constructor set vals to make it easier to
// test.
memset(&FakeMIB, 0, sizeof(MemInfoBlock));
- FakeMIB.AllocCount = 0x1;
- FakeMIB.TotalAccessCount = 0x2;
+ FakeMIB.alloc_count = 0x1;
+ FakeMIB.total_access_count = 0x2;
uint64_t FakeIds[2];
FakeIds[0] = PopulateFakeMap(FakeMIB, /*StackPCBegin=*/2, FakeMap);
diff --git a/llvm/include/llvm/ProfileData/MIBEntryDef.inc b/llvm/include/llvm/ProfileData/MIBEntryDef.inc
deleted file mode 100644
index db4dbf4fd52f8..0000000000000
--- a/llvm/include/llvm/ProfileData/MIBEntryDef.inc
+++ /dev/null
@@ -1,51 +0,0 @@
-/*===-- MemEntryDef.inc - MemProf profiling runtime macros -*- C++ -*-======== *\
-|*
-|* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-|* See https://llvm.org/LICENSE.txt for license information.
-|* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-|*
-\*===----------------------------------------------------------------------===*/
-/*
- * This file defines the macros for memprof profiling data structures.
- * Eg. usage to define the memprof meminfoblock struct:
- *
- * struct MemInfoBlock {
- * #define MIBEntryDef(NameTag, Name, Type) Type Name;
- * #include MIBEntryDef.inc
- * #undef MIBEntryDef
- * };
- *
- * This file has two identical copies. The primary copy lives in LLVM and
- * the other one sits in compiler-rt/include/profile directory. To make changes
- * in this file, first modify the primary copy and copy it over to compiler-rt.
- * Testing of any change in this file can start only after the two copies are
- * synced up.
- *
-\*===----------------------------------------------------------------------===*/
-
-#ifndef MIBEntryDef
-#define MIBEntryDef(NameTag, Name, Type)
-#endif
-
-MIBEntryDef(AllocCount = 1, AllocCount, uint32_t)
-MIBEntryDef(TotalAccessCount = 2, TotalAccessCount, uint64_t)
-MIBEntryDef(MinAccessCount = 3, MinAccessCount, uint64_t)
-MIBEntryDef(MaxAccessCount = 4, MaxAccessCount, uint64_t)
-MIBEntryDef(TotalSize = 5, TotalSize, uint64_t)
-MIBEntryDef(MinSize = 6, MinSize, uint32_t)
-MIBEntryDef(MaxSize = 7, MaxSize, uint32_t)
-MIBEntryDef(AllocTimestamp = 8, AllocTimestamp, uint32_t)
-MIBEntryDef(DeallocTimestamp = 9, DeallocTimestamp, uint32_t)
-MIBEntryDef(TotalLifetime = 10, TotalLifetime, uint64_t)
-MIBEntryDef(MinLifetime = 11, MinLifetime, uint32_t)
-MIBEntryDef(MaxLifetime = 12, MaxLifetime, uint32_t)
-MIBEntryDef(AllocCpuId = 13, AllocCpuId, uint32_t)
-MIBEntryDef(DeallocCpuId = 14, DeallocCpuId, uint32_t)
-MIBEntryDef(NumMigratedCpu = 15, NumMigratedCpu, uint32_t)
-MIBEntryDef(NumLifetimeOverlaps = 16, NumLifetimeOverlaps, uint32_t)
-MIBEntryDef(NumSameAllocCpu = 17, NumSameAllocCpu, uint32_t)
-MIBEntryDef(NumSameDeallocCpu = 18, NumSameDeallocCpu, uint32_t)
-MIBEntryDef(DataTypeId = 19, DataTypeId, uint64_t)
-
-
-
diff --git a/llvm/include/llvm/ProfileData/MemProf.h b/llvm/include/llvm/ProfileData/MemProf.h
index 1c92ec5d8892e..c21903c940061 100644
--- a/llvm/include/llvm/ProfileData/MemProf.h
+++ b/llvm/include/llvm/ProfileData/MemProf.h
@@ -51,41 +51,41 @@ struct MemProfRecord {
// TODO: Replace this once the format is updated to be version agnostic.
OS << " "
- << "AllocCount: " << Info.AllocCount << "\n";
+ << "AllocCount: " << Info.alloc_count << "\n";
OS << " "
- << "TotalAccessCount: " << Info.TotalAccessCount << "\n";
+ << "TotalAccessCount: " << Info.total_access_count << "\n";
OS << " "
- << "MinAccessCount: " << Info.MinAccessCount << "\n";
+ << "MinAccessCount: " << Info.min_access_count << "\n";
OS << " "
- << "MaxAccessCount: " << Info.MaxAccessCount << "\n";
+ << "MaxAccessCount: " << Info.max_access_count << "\n";
OS << " "
- << "TotalSize: " << Info.TotalSize << "\n";
+ << "TotalSize: " << Info.total_size << "\n";
OS << " "
- << "MinSize: " << Info.MinSize << "\n";
+ << "MinSize: " << Info.min_size << "\n";
OS << " "
- << "MaxSize: " << Info.MaxSize << "\n";
+ << "MaxSize: " << Info.max_size << "\n";
OS << " "
- << "AllocTimestamp: " << Info.AllocTimestamp << "\n";
+ << "AllocTimestamp: " << Info.alloc_timestamp << "\n";
OS << " "
- << "DeallocTimestamp: " << Info.DeallocTimestamp << "\n";
+ << "DeallocTimestamp: " << Info.dealloc_timestamp << "\n";
OS << " "
- << "TotalLifetime: " << Info.TotalLifetime << "\n";
+ << "TotalLifetime: " << Info.total_lifetime << "\n";
OS << " "
- << "MinLifetime: " << Info.MinLifetime << "\n";
+ << "MinLifetime: " << Info.min_lifetime << "\n";
OS << " "
- << "MaxLifetime: " << Info.MaxLifetime << "\n";
+ << "MaxLifetime: " << Info.max_lifetime << "\n";
OS << " "
- << "AllocCpuId: " << Info.AllocCpuId << "\n";
+ << "AllocCpuId: " << Info.alloc_cpu_id << "\n";
OS << " "
- << "DeallocCpuId: " << Info.DeallocCpuId << "\n";
+ << "DeallocCpuId: " << Info.dealloc_cpu_id << "\n";
OS << " "
- << "NumMigratedCpu: " << Info.NumMigratedCpu << "\n";
+ << "NumMigratedCpu: " << Info.num_migrated_cpu << "\n";
OS << " "
- << "NumLifetimeOverlaps: " << Info.NumLifetimeOverlaps << "\n";
+ << "NumLifetimeOverlaps: " << Info.num_lifetime_overlaps << "\n";
OS << " "
- << "NumSameAllocCpu: " << Info.NumSameAllocCpu << "\n";
+ << "NumSameAllocCpu: " << Info.num_same_alloc_cpu << "\n";
OS << " "
- << "NumSameDeallocCpu: " << Info.NumSameDeallocCpu << "\n";
+ << "NumSameDeallocCpu: " << Info.num_same_dealloc_cpu << "\n";
}
};
diff --git a/llvm/include/llvm/ProfileData/MemProfData.inc b/llvm/include/llvm/ProfileData/MemProfData.inc
index 8135a664b0466..ff22a697965cb 100644
--- a/llvm/include/llvm/ProfileData/MemProfData.inc
+++ b/llvm/include/llvm/ProfileData/MemProfData.inc
@@ -80,80 +80,71 @@ PACKED(struct SegmentEntry {
}
});
-// Packed struct definition for MSVC. We can't use the PACKED macro defined in
-// 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))
-#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{
-
-#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) \
- IsEqual = (IsEqual && Name == Other.Name);
-#include "MIBEntryDef.inc"
-#undef MIBEntryDef
- return IsEqual;
-}
-
-MemInfoBlock() : AllocCount(0) {}
-
-MemInfoBlock(uint32_t size, uint64_t access_count, uint32_t alloc_timestamp,
- uint32_t dealloc_timestamp, uint32_t alloc_cpu, uint32_t dealloc_cpu)
- : AllocCount(1), TotalAccessCount(access_count),
- MinAccessCount(access_count), MaxAccessCount(access_count),
- TotalSize(size), MinSize(size), MaxSize(size),
- AllocTimestamp(alloc_timestamp), DeallocTimestamp(dealloc_timestamp),
- TotalLifetime(dealloc_timestamp - alloc_timestamp),
- MinLifetime(TotalLifetime), MaxLifetime(TotalLifetime),
- AllocCpuId(alloc_cpu), DeallocCpuId(dealloc_cpu),
- NumLifetimeOverlaps(0), NumSameAllocCpu(0),
- NumSameDeallocCpu(0) {
- 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;
-
- // 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;
-}
+PACKED(struct MemInfoBlock {
+ uint32_t alloc_count;
+ uint64_t total_access_count, min_access_count, max_access_count;
+ uint64_t total_size;
+ uint32_t min_size, max_size;
+ uint32_t alloc_timestamp, dealloc_timestamp;
+ uint64_t total_lifetime;
+ uint32_t min_lifetime, max_lifetime;
+ uint32_t alloc_cpu_id, dealloc_cpu_id;
+ uint32_t num_migrated_cpu;
+
+ // Only compared to prior deallocated object currently.
+ uint32_t num_lifetime_overlaps;
+ uint32_t num_same_alloc_cpu;
+ uint32_t num_same_dealloc_cpu;
+
+ uint64_t data_type_id; // TODO: hash of type name
+
+ MemInfoBlock() : alloc_count(0) {}
+
+ MemInfoBlock(uint32_t size, uint64_t access_count, uint32_t alloc_timestamp,
+ uint32_t dealloc_timestamp, uint32_t alloc_cpu, uint32_t dealloc_cpu)
+ : alloc_count(1), total_access_count(access_count),
+ min_access_count(access_count), max_access_count(access_count),
+ total_size(size), min_size(size), max_size(size),
+ alloc_timestamp(alloc_timestamp), dealloc_timestamp(dealloc_timestamp),
+ total_lifetime(dealloc_timestamp - alloc_timestamp),
+ min_lifetime(total_lifetime), max_lifetime(total_lifetime),
+ alloc_cpu_id(alloc_cpu), dealloc_cpu_id(dealloc_cpu),
+ num_lifetime_overlaps(0), num_same_alloc_cpu(0),
+ num_same_dealloc_cpu(0) {
+ num_migrated_cpu = alloc_cpu_id != dealloc_cpu_id;
+ }
-#ifdef _MSC_VER
-} __pragma(pack(pop));
-#else
-} __attribute__((__packed__));
-#endif
+ void Merge(const MemInfoBlock &newMIB) {
+ alloc_count += newMIB.alloc_count;
+
+ total_access_count += newMIB.total_access_count;
+ min_access_count = newMIB.min_access_count < min_access_count ? newMIB.min_access_count : min_access_count;
+ max_access_count = newMIB.max_access_count < max_access_count ? newMIB.max_access_count : max_access_count;
+
+ total_size += newMIB.total_size;
+ min_size = newMIB.min_size < min_size ? newMIB.min_size : min_size;
+ max_size = newMIB.max_size < max_size ? newMIB.max_size : max_size;
+
+ total_lifetime += newMIB.total_lifetime;
+ min_lifetime = newMIB.min_lifetime < min_lifetime ? newMIB.min_lifetime : min_lifetime;
+ max_lifetime = newMIB.max_lifetime > max_lifetime ? newMIB.max_lifetime : max_lifetime;
+
+ // We know newMIB was deallocated later, so just need to check if it was
+ // allocated before last one deallocated.
+ num_lifetime_overlaps += newMIB.alloc_timestamp < dealloc_timestamp;
+ alloc_timestamp = newMIB.alloc_timestamp;
+ dealloc_timestamp = newMIB.dealloc_timestamp;
+
+ num_same_alloc_cpu += alloc_cpu_id == newMIB.alloc_cpu_id;
+ num_same_dealloc_cpu += dealloc_cpu_id == newMIB.dealloc_cpu_id;
+ alloc_cpu_id = newMIB.alloc_cpu_id;
+ dealloc_cpu_id = newMIB.dealloc_cpu_id;
+ }
+});
} // namespace memprof
} // namespace llvm
diff --git a/llvm/unittests/ProfileData/MemProfTest.cpp b/llvm/unittests/ProfileData/MemProfTest.cpp
index 09ffe8fd634f2..c63d2ecba82b1 100644
--- a/llvm/unittests/ProfileData/MemProfTest.cpp
+++ b/llvm/unittests/ProfileData/MemProfTest.cpp
@@ -123,8 +123,8 @@ TEST(MemProf, FillsValue) {
CSM[0x2] = {0x6000, 0x2000};
llvm::MapVector<uint64_t, MemInfoBlock> Prof;
- Prof[0x1].AllocCount = 1;
- Prof[0x2].AllocCount = 2;
+ Prof[0x1].alloc_count = 1;
+ Prof[0x2].alloc_count = 2;
auto Seg = makeSegments();
@@ -136,8 +136,8 @@ TEST(MemProf, FillsValue) {
}
EXPECT_EQ(Records.size(), 2U);
- EXPECT_EQ(Records[0].Info.AllocCount, 1U);
- EXPECT_EQ(Records[1].Info.AllocCount, 2U);
+ EXPECT_EQ(Records[0].Info.alloc_count, 1U);
+ EXPECT_EQ(Records[1].Info.alloc_count, 2U);
EXPECT_THAT(Records[0].CallStack[0], FrameContains("foo", 5U, 30U, false));
EXPECT_THAT(Records[0].CallStack[1], FrameContains("bar", 51U, 20U, true));
More information about the llvm-commits
mailing list