@@ -80,80 +80,71 @@ PACKED(struct SegmentEntry {
80
80
}
81
81
});
82
82
83
- // Packed struct definition for MSVC. We can't use the PACKED macro defined in
84
- // MemProfData.inc since it would mean we are embedding a directive (the
85
- // #include for MIBEntryDef) into the macros which is undefined behaviour.
86
- #ifdef _MSC_VER
87
- __pragma (pack(push,1 ))
88
- #endif
89
-
90
83
// A struct representing the heap allocation characteristics of a particular
91
84
// runtime context. This struct is shared between the compiler-rt runtime and
92
85
// the raw profile reader. The indexed format uses a separate, self-describing
93
86
// backwards compatible format.
94
- struct MemInfoBlock {
95
-
96
- #define MIBEntryDef (NameTag, Name, Type ) Type Name;
97
- #include " MIBEntryDef.inc"
98
- #undef MIBEntryDef
99
-
100
- bool operator ==(const MemInfoBlock& Other) const {
101
- bool IsEqual = true ;
102
- #define MIBEntryDef (NameTag, Name, Type ) \
103
- IsEqual = (IsEqual && Name == Other.Name );
104
- #include " MIBEntryDef.inc"
105
- #undef MIBEntryDef
106
- return IsEqual;
107
- }
108
-
109
- MemInfoBlock () : AllocCount(0 ) {}
110
-
111
- MemInfoBlock (uint32_t size, uint64_t access_count, uint32_t alloc_timestamp,
112
- uint32_t dealloc_timestamp, uint32_t alloc_cpu, uint32_t dealloc_cpu)
113
- : AllocCount(1 ), TotalAccessCount(access_count),
114
- MinAccessCount (access_count), MaxAccessCount(access_count),
115
- TotalSize(size), MinSize(size), MaxSize(size),
116
- AllocTimestamp(alloc_timestamp), DeallocTimestamp(dealloc_timestamp),
117
- TotalLifetime(dealloc_timestamp - alloc_timestamp),
118
- MinLifetime(TotalLifetime), MaxLifetime(TotalLifetime),
119
- AllocCpuId(alloc_cpu), DeallocCpuId(dealloc_cpu),
120
- NumLifetimeOverlaps(0 ), NumSameAllocCpu(0 ),
121
- NumSameDeallocCpu(0 ) {
122
- NumMigratedCpu = AllocCpuId != DeallocCpuId;
123
- }
124
-
125
- void Merge (const MemInfoBlock &newMIB) {
126
- AllocCount += newMIB.AllocCount ;
127
-
128
- TotalAccessCount += newMIB.TotalAccessCount ;
129
- MinAccessCount = newMIB.MinAccessCount < MinAccessCount ? newMIB.MinAccessCount : MinAccessCount;
130
- MaxAccessCount = newMIB.MaxAccessCount < MaxAccessCount ? newMIB.MaxAccessCount : MaxAccessCount;
131
-
132
- TotalSize += newMIB.TotalSize ;
133
- MinSize = newMIB.MinSize < MinSize ? newMIB.MinSize : MinSize;
134
- MaxSize = newMIB.MaxSize < MaxSize ? newMIB.MaxSize : MaxSize;
135
-
136
- TotalLifetime += newMIB.TotalLifetime ;
137
- MinLifetime = newMIB.MinLifetime < MinLifetime ? newMIB.MinLifetime : MinLifetime;
138
- MaxLifetime = newMIB.MaxLifetime > MaxLifetime ? newMIB.MaxLifetime : MaxLifetime;
139
-
140
- // We know newMIB was deallocated later, so just need to check if it was
141
- // allocated before last one deallocated.
142
- NumLifetimeOverlaps += newMIB.AllocTimestamp < DeallocTimestamp;
143
- AllocTimestamp = newMIB.AllocTimestamp ;
144
- DeallocTimestamp = newMIB.DeallocTimestamp ;
145
-
146
- NumSameAllocCpu += AllocCpuId == newMIB.AllocCpuId ;
147
- NumSameDeallocCpu += DeallocCpuId == newMIB.DeallocCpuId ;
148
- AllocCpuId = newMIB.AllocCpuId ;
149
- DeallocCpuId = newMIB.DeallocCpuId ;
150
- }
87
+ PACKED (struct MemInfoBlock {
88
+ uint32_t alloc_count;
89
+ uint64_t total_access_count, min_access_count, max_access_count;
90
+ uint64_t total_size;
91
+ uint32_t min_size, max_size;
92
+ uint32_t alloc_timestamp, dealloc_timestamp;
93
+ uint64_t total_lifetime;
94
+ uint32_t min_lifetime, max_lifetime;
95
+ uint32_t alloc_cpu_id, dealloc_cpu_id;
96
+ uint32_t num_migrated_cpu;
97
+
98
+ // Only compared to prior deallocated object currently.
99
+ uint32_t num_lifetime_overlaps;
100
+ uint32_t num_same_alloc_cpu;
101
+ uint32_t num_same_dealloc_cpu;
102
+
103
+ uint64_t data_type_id; // TODO: hash of type name
104
+
105
+ MemInfoBlock () : alloc_count(0 ) {}
106
+
107
+ MemInfoBlock (uint32_t size, uint64_t access_count, uint32_t alloc_timestamp,
108
+ uint32_t dealloc_timestamp, uint32_t alloc_cpu, uint32_t dealloc_cpu)
109
+ : alloc_count(1 ), total_access_count(access_count),
110
+ min_access_count (access_count), max_access_count(access_count),
111
+ total_size(size), min_size(size), max_size(size),
112
+ alloc_timestamp(alloc_timestamp), dealloc_timestamp(dealloc_timestamp),
113
+ total_lifetime(dealloc_timestamp - alloc_timestamp),
114
+ min_lifetime(total_lifetime), max_lifetime(total_lifetime),
115
+ alloc_cpu_id(alloc_cpu), dealloc_cpu_id(dealloc_cpu),
116
+ num_lifetime_overlaps(0 ), num_same_alloc_cpu(0 ),
117
+ num_same_dealloc_cpu(0 ) {
118
+ num_migrated_cpu = alloc_cpu_id != dealloc_cpu_id;
119
+ }
151
120
152
- #ifdef _MSC_VER
153
- } __pragma(pack(pop));
154
- #else
155
- } __attribute__((__packed__));
156
- #endif
121
+ void Merge (const MemInfoBlock &newMIB) {
122
+ alloc_count += newMIB.alloc_count ;
123
+
124
+ total_access_count += newMIB.total_access_count ;
125
+ min_access_count = newMIB.min_access_count < min_access_count ? newMIB.min_access_count : min_access_count;
126
+ max_access_count = newMIB.max_access_count < max_access_count ? newMIB.max_access_count : max_access_count;
127
+
128
+ total_size += newMIB.total_size ;
129
+ min_size = newMIB.min_size < min_size ? newMIB.min_size : min_size;
130
+ max_size = newMIB.max_size < max_size ? newMIB.max_size : max_size;
131
+
132
+ total_lifetime += newMIB.total_lifetime ;
133
+ min_lifetime = newMIB.min_lifetime < min_lifetime ? newMIB.min_lifetime : min_lifetime;
134
+ max_lifetime = newMIB.max_lifetime > max_lifetime ? newMIB.max_lifetime : max_lifetime;
135
+
136
+ // We know newMIB was deallocated later, so just need to check if it was
137
+ // allocated before last one deallocated.
138
+ num_lifetime_overlaps += newMIB.alloc_timestamp < dealloc_timestamp;
139
+ alloc_timestamp = newMIB.alloc_timestamp ;
140
+ dealloc_timestamp = newMIB.dealloc_timestamp ;
141
+
142
+ num_same_alloc_cpu += alloc_cpu_id == newMIB.alloc_cpu_id ;
143
+ num_same_dealloc_cpu += dealloc_cpu_id == newMIB.dealloc_cpu_id ;
144
+ alloc_cpu_id = newMIB.alloc_cpu_id ;
145
+ dealloc_cpu_id = newMIB.dealloc_cpu_id ;
146
+ }
147
+ });
157
148
158
149
} // namespace memprof
159
150
} // namespace llvm
0 commit comments