OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // --- | 5 // --- |
6 // Author: Sainbayar Sukhbaatar | 6 // Author: Sainbayar Sukhbaatar |
7 // Dai Mikurube | 7 // Dai Mikurube |
8 // | 8 // |
9 // This file contains a class DeepHeapProfile and its public function | 9 // This file contains a class DeepHeapProfile and its public function |
10 // DeepHeapProfile::FillOrderedProfile() which works as an alternative of | 10 // DeepHeapProfile::FillOrderedProfile() which works as an alternative of |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 inline static void AddToHashValue(uintptr_t add, uintptr_t* hash_value); | 204 inline static void AddToHashValue(uintptr_t add, uintptr_t* hash_value); |
205 inline static void FinishHashValue(uintptr_t* hash_value); | 205 inline static void FinishHashValue(uintptr_t* hash_value); |
206 | 206 |
207 DeepBucket** table_; | 207 DeepBucket** table_; |
208 size_t table_size_; | 208 size_t table_size_; |
209 HeapProfileTable::Allocator alloc_; | 209 HeapProfileTable::Allocator alloc_; |
210 HeapProfileTable::DeAllocator dealloc_; | 210 HeapProfileTable::DeAllocator dealloc_; |
211 int bucket_id_; | 211 int bucket_id_; |
212 }; | 212 }; |
213 | 213 |
214 struct MMapListEntry { | |
215 uint64 first_address; | |
216 uint64 last_address; | |
217 MapsRegionType type; | |
218 DeepBucket* deep_bucket; | |
219 }; | |
220 | |
221 class RegionStats { | 214 class RegionStats { |
222 public: | 215 public: |
223 RegionStats(): virtual_bytes_(0), committed_bytes_(0) {} | 216 RegionStats(): virtual_bytes_(0), committed_bytes_(0) {} |
224 ~RegionStats() {} | 217 ~RegionStats() {} |
225 | 218 |
226 // Initializes 'virtual_bytes_' and 'committed_bytes_'. | 219 // Initializes 'virtual_bytes_' and 'committed_bytes_'. |
227 void Initialize(); | 220 void Initialize(); |
228 | 221 |
229 // Updates itself to contain the tallies of 'virtual_bytes' and | 222 // Updates itself to contain the tallies of 'virtual_bytes' and |
230 // 'committed_bytes' in the region from |first_adress| to |last_address| | 223 // 'committed_bytes' in the region from |first_adress| to |last_address| |
(...skipping 20 matching lines...) Expand all Loading... |
251 | 244 |
252 private: | 245 private: |
253 size_t virtual_bytes_; | 246 size_t virtual_bytes_; |
254 size_t committed_bytes_; | 247 size_t committed_bytes_; |
255 DISALLOW_COPY_AND_ASSIGN(RegionStats); | 248 DISALLOW_COPY_AND_ASSIGN(RegionStats); |
256 }; | 249 }; |
257 | 250 |
258 class GlobalStats { | 251 class GlobalStats { |
259 public: | 252 public: |
260 // Snapshots and calculates global stats from /proc/<pid>/maps and pagemap. | 253 // Snapshots and calculates global stats from /proc/<pid>/maps and pagemap. |
261 void SnapshotProcMaps( | 254 void SnapshotMaps( |
262 const MemoryResidenceInfoGetterInterface* memory_residence_info_getter, | 255 const MemoryResidenceInfoGetterInterface* memory_residence_info_getter, |
263 MMapListEntry* mmap_list, | 256 DeepHeapProfile* deep_profile, |
264 int mmap_list_length, | |
265 TextBuffer* mmap_dump_buffer); | 257 TextBuffer* mmap_dump_buffer); |
266 | 258 |
267 // Snapshots allocations by malloc and mmap. | 259 // Snapshots allocations by malloc and mmap. |
268 void SnapshotAllocations(DeepHeapProfile* deep_profile); | 260 void SnapshotAllocations(DeepHeapProfile* deep_profile); |
269 | 261 |
270 // Writes global stats into |buffer|. | 262 // Writes global stats into |buffer|. |
271 void Unparse(TextBuffer* buffer); | 263 void Unparse(TextBuffer* buffer); |
272 | 264 |
273 private: | 265 private: |
274 static bool ByFirstAddress(const MMapListEntry& a, | |
275 const MMapListEntry& b); | |
276 | |
277 // Records both virtual and committed byte counts of malloc and mmap regions | 266 // Records both virtual and committed byte counts of malloc and mmap regions |
278 // as callback functions for AllocationMap::Iterate(). | 267 // as callback functions for AllocationMap::Iterate(). |
279 static void RecordAlloc(const void* pointer, | 268 static void RecordAlloc(const void* pointer, |
280 AllocValue* alloc_value, | 269 AllocValue* alloc_value, |
281 DeepHeapProfile* deep_profile); | 270 DeepHeapProfile* deep_profile); |
282 static void RecordMMap(const void* pointer, | |
283 AllocValue* alloc_value, | |
284 DeepHeapProfile* deep_profile); | |
285 | 271 |
286 // All RegionStats members in this class contain the bytes of virtual | 272 // All RegionStats members in this class contain the bytes of virtual |
287 // memory and committed memory. | 273 // memory and committed memory. |
288 // TODO(dmikurube): These regions should be classified more precisely later | 274 // TODO(dmikurube): These regions should be classified more precisely later |
289 // for more detailed analysis. | 275 // for more detailed analysis. |
290 RegionStats all_[NUMBER_OF_MAPS_REGION_TYPES]; | 276 RegionStats all_[NUMBER_OF_MAPS_REGION_TYPES]; |
291 | 277 |
292 RegionStats unhooked_[NUMBER_OF_MAPS_REGION_TYPES]; | 278 RegionStats unhooked_[NUMBER_OF_MAPS_REGION_TYPES]; |
293 | 279 |
294 // Total bytes of malloc'ed regions. | 280 // Total bytes of malloc'ed regions. |
295 RegionStats profiled_malloc_; | 281 RegionStats profiled_malloc_; |
296 | 282 |
297 // Total bytes of mmap'ed regions. | 283 // Total bytes of mmap'ed regions. |
298 RegionStats profiled_mmap_; | 284 RegionStats profiled_mmap_; |
299 }; | 285 }; |
300 | 286 |
301 // Writes reformatted /proc/<pid>/maps into a file "|prefix|.<pid>.maps" | 287 // Writes reformatted /proc/<pid>/maps into a file "|prefix|.<pid>.maps" |
302 // with using |raw_buffer| of |buffer_size|. | 288 // with using |raw_buffer| of |buffer_size|. |
303 static void WriteProcMaps(const char* prefix, | 289 static void WriteProcMaps(const char* prefix, |
304 int buffer_size, | 290 int buffer_size, |
305 char raw_buffer[]); | 291 char raw_buffer[]); |
306 | 292 |
307 // Counts mmap allocations in |deep_profile|->num_mmap_allocations_. | |
308 static void CountMMap(const void* pointer, | |
309 AllocValue* alloc_value, | |
310 DeepHeapProfile* deep_profile); | |
311 | |
312 MemoryResidenceInfoGetterInterface* memory_residence_info_getter_; | 293 MemoryResidenceInfoGetterInterface* memory_residence_info_getter_; |
313 | 294 |
314 // Process ID of the last dump. This can change by fork. | 295 // Process ID of the last dump. This can change by fork. |
315 pid_t most_recent_pid_; | 296 pid_t most_recent_pid_; |
316 | 297 |
317 GlobalStats stats_; // Stats about total memory. | 298 GlobalStats stats_; // Stats about total memory. |
318 int dump_count_; // The number of dumps. | 299 int dump_count_; // The number of dumps. |
319 char* filename_prefix_; // Output file prefix. | 300 char* filename_prefix_; // Output file prefix. |
320 char* profiler_buffer_; // Buffer we use many times. | 301 char* profiler_buffer_; // Buffer we use many times. |
321 | 302 |
322 DeepBucketTable deep_table_; | 303 DeepBucketTable deep_table_; |
323 MMapListEntry* mmap_list_; | |
324 int mmap_list_length_; | |
325 int num_mmap_allocations_; | |
326 #endif // DEEP_HEAP_PROFILE | 304 #endif // DEEP_HEAP_PROFILE |
327 | 305 |
328 HeapProfileTable* heap_profile_; | 306 HeapProfileTable* heap_profile_; |
329 | 307 |
330 DISALLOW_COPY_AND_ASSIGN(DeepHeapProfile); | 308 DISALLOW_COPY_AND_ASSIGN(DeepHeapProfile); |
331 }; | 309 }; |
332 | 310 |
333 #endif // BASE_DEEP_HEAP_PROFILE_H_ | 311 #endif // BASE_DEEP_HEAP_PROFILE_H_ |
OLD | NEW |