OLD | NEW |
1 // Copyright (c) 2006, Google Inc. | 1 // Copyright (c) 2006, Google Inc. |
2 // All rights reserved. | 2 // All rights reserved. |
3 // | 3 // |
4 // Redistribution and use in source and binary forms, with or without | 4 // Redistribution and use in source and binary forms, with or without |
5 // modification, are permitted provided that the following conditions are | 5 // modification, are permitted provided that the following conditions are |
6 // met: | 6 // met: |
7 // | 7 // |
8 // * Redistributions of source code must retain the above copyright | 8 // * Redistributions of source code must retain the above copyright |
9 // notice, this list of conditions and the following disclaimer. | 9 // notice, this list of conditions and the following disclaimer. |
10 // * Redistributions in binary form must reproduce the above | 10 // * Redistributions in binary form must reproduce the above |
(...skipping 22 matching lines...) Loading... |
33 // | 33 // |
34 | 34 |
35 #ifndef BASE_HEAP_PROFILE_TABLE_H_ | 35 #ifndef BASE_HEAP_PROFILE_TABLE_H_ |
36 #define BASE_HEAP_PROFILE_TABLE_H_ | 36 #define BASE_HEAP_PROFILE_TABLE_H_ |
37 | 37 |
38 #include "addressmap-inl.h" | 38 #include "addressmap-inl.h" |
39 #include "base/basictypes.h" | 39 #include "base/basictypes.h" |
40 #include "base/logging.h" // for RawFD | 40 #include "base/logging.h" // for RawFD |
41 #include "heap-profile-stats.h" | 41 #include "heap-profile-stats.h" |
42 | 42 |
43 #if defined(TYPE_PROFILING) | |
44 #include <gperftools/type_profiler_map.h> | |
45 #endif // defined(TYPE_PROFILING) | |
46 | |
47 // Table to maintain a heap profile data inside, | 43 // Table to maintain a heap profile data inside, |
48 // i.e. the set of currently active heap memory allocations. | 44 // i.e. the set of currently active heap memory allocations. |
49 // thread-unsafe and non-reentrant code: | 45 // thread-unsafe and non-reentrant code: |
50 // each instance object must be used by one thread | 46 // each instance object must be used by one thread |
51 // at a time w/o self-recursion. | 47 // at a time w/o self-recursion. |
52 // | 48 // |
53 // TODO(maxim): add a unittest for this class. | 49 // TODO(maxim): add a unittest for this class. |
54 class HeapProfileTable { | 50 class HeapProfileTable { |
55 public: | 51 public: |
56 | 52 |
(...skipping 159 matching lines...) Loading... |
216 // 4. Perform whatever action is supposed to free the memory again. New | 212 // 4. Perform whatever action is supposed to free the memory again. New |
217 // allocations are not marked. So all allocations that are marked as | 213 // allocations are not marked. So all allocations that are marked as |
218 // "live" where created during step 2. | 214 // "live" where created during step 2. |
219 // 5. Invoke DumpMarkedObjects(MARK_TWO) to get the list of allocations that | 215 // 5. Invoke DumpMarkedObjects(MARK_TWO) to get the list of allocations that |
220 // were created during step 2, but survived step 4. | 216 // were created during step 2, but survived step 4. |
221 // | 217 // |
222 // Note that this functionality cannot be used if the HeapProfileTable is | 218 // Note that this functionality cannot be used if the HeapProfileTable is |
223 // used for leak checking (using HeapLeakChecker). | 219 // used for leak checking (using HeapLeakChecker). |
224 void DumpMarkedObjects(AllocationMark mark, const char* file_name); | 220 void DumpMarkedObjects(AllocationMark mark, const char* file_name); |
225 | 221 |
226 #if defined(TYPE_PROFILING) | |
227 void DumpTypeStatistics(const char* file_name) const; | |
228 #endif // defined(TYPE_PROFILING) | |
229 | |
230 private: | 222 private: |
231 friend class DeepHeapProfile; | |
232 | |
233 // data types ---------------------------- | 223 // data types ---------------------------- |
234 | 224 |
235 // Hash table bucket to hold (de)allocation stats | 225 // Hash table bucket to hold (de)allocation stats |
236 // for a given allocation call stack trace. | 226 // for a given allocation call stack trace. |
237 typedef HeapProfileBucket Bucket; | 227 typedef HeapProfileBucket Bucket; |
238 | 228 |
239 // Info stored in the address map | 229 // Info stored in the address map |
240 struct AllocValue { | 230 struct AllocValue { |
241 // Access to the stack-trace bucket | 231 // Access to the stack-trace bucket |
242 Bucket* bucket() const { | 232 Bucket* bucket() const { |
(...skipping 78 matching lines...) Loading... |
321 MarkArgs(AllocationMark mark_arg, bool mark_all_arg) | 311 MarkArgs(AllocationMark mark_arg, bool mark_all_arg) |
322 : mark(mark_arg), | 312 : mark(mark_arg), |
323 mark_all(mark_all_arg) { | 313 mark_all(mark_all_arg) { |
324 } | 314 } |
325 | 315 |
326 AllocationMark mark; // The mark to put on allocations. | 316 AllocationMark mark; // The mark to put on allocations. |
327 bool mark_all; // True if all allocations should be marked. Otherwise just | 317 bool mark_all; // True if all allocations should be marked. Otherwise just |
328 // mark unmarked allocations. | 318 // mark unmarked allocations. |
329 }; | 319 }; |
330 | 320 |
331 #if defined(TYPE_PROFILING) | |
332 struct TypeCount { | |
333 TypeCount(size_t bytes_arg, unsigned int objects_arg) | |
334 : bytes(bytes_arg), | |
335 objects(objects_arg) { | |
336 } | |
337 | |
338 size_t bytes; | |
339 unsigned int objects; | |
340 }; | |
341 #endif // defined(TYPE_PROFILING) | |
342 | |
343 struct AllocationAddressIteratorArgs { | 321 struct AllocationAddressIteratorArgs { |
344 AllocationAddressIteratorArgs(AddressIterator callback_arg, void* data_arg) | 322 AllocationAddressIteratorArgs(AddressIterator callback_arg, void* data_arg) |
345 : callback(callback_arg), | 323 : callback(callback_arg), |
346 data(data_arg) { | 324 data(data_arg) { |
347 } | 325 } |
348 | 326 |
349 AddressIterator callback; | 327 AddressIterator callback; |
350 void* data; | 328 void* data; |
351 }; | 329 }; |
352 | 330 |
(...skipping 49 matching lines...) Loading... |
402 // Helper for DumpNonLiveProfile to do object-granularity | 380 // Helper for DumpNonLiveProfile to do object-granularity |
403 // heap profile dumping. It gets passed to AllocationMap::Iterate. | 381 // heap profile dumping. It gets passed to AllocationMap::Iterate. |
404 inline static void DumpNonLiveIterator(const void* ptr, AllocValue* v, | 382 inline static void DumpNonLiveIterator(const void* ptr, AllocValue* v, |
405 const DumpArgs& args); | 383 const DumpArgs& args); |
406 | 384 |
407 // Helper for DumpMarkedObjects to dump all allocations with a given mark. It | 385 // Helper for DumpMarkedObjects to dump all allocations with a given mark. It |
408 // gets passed to AllocationMap::Iterate. | 386 // gets passed to AllocationMap::Iterate. |
409 inline static void DumpMarkedIterator(const void* ptr, AllocValue* v, | 387 inline static void DumpMarkedIterator(const void* ptr, AllocValue* v, |
410 const DumpMarkedArgs& args); | 388 const DumpMarkedArgs& args); |
411 | 389 |
412 #if defined(TYPE_PROFILING) | |
413 inline static void TallyTypesItererator(const void* ptr, | |
414 AllocValue* value, | |
415 AddressMap<TypeCount>* type_size_map); | |
416 | |
417 inline static void DumpTypesIterator(const void* ptr, | |
418 TypeCount* size, | |
419 const DumpArgs& args); | |
420 #endif // defined(TYPE_PROFILING) | |
421 | |
422 // Helper for IterateOrderedAllocContexts and FillOrderedProfile. | 390 // Helper for IterateOrderedAllocContexts and FillOrderedProfile. |
423 // Creates a sorted list of Buckets whose length is num_buckets_. | 391 // Creates a sorted list of Buckets whose length is num_buckets_. |
424 // The caller is responsible for deallocating the returned list. | 392 // The caller is responsible for deallocating the returned list. |
425 Bucket** MakeSortedBucketList() const; | 393 Bucket** MakeSortedBucketList() const; |
426 | 394 |
427 // Helper for TakeSnapshot. Saves object to snapshot. | 395 // Helper for TakeSnapshot. Saves object to snapshot. |
428 static void AddToSnapshot(const void* ptr, AllocValue* v, Snapshot* s); | 396 static void AddToSnapshot(const void* ptr, AllocValue* v, Snapshot* s); |
429 | 397 |
430 // Arguments passed to AddIfNonLive | 398 // Arguments passed to AddIfNonLive |
431 struct AddNonLiveArgs { | 399 struct AddNonLiveArgs { |
(...skipping 84 matching lines...) Loading... |
516 // Helpers for sorting and generating leak reports | 484 // Helpers for sorting and generating leak reports |
517 struct Entry; | 485 struct Entry; |
518 struct ReportState; | 486 struct ReportState; |
519 static void ReportCallback(const void* ptr, AllocValue* v, ReportState*); | 487 static void ReportCallback(const void* ptr, AllocValue* v, ReportState*); |
520 static void ReportObject(const void* ptr, AllocValue* v, char*); | 488 static void ReportObject(const void* ptr, AllocValue* v, char*); |
521 | 489 |
522 DISALLOW_COPY_AND_ASSIGN(Snapshot); | 490 DISALLOW_COPY_AND_ASSIGN(Snapshot); |
523 }; | 491 }; |
524 | 492 |
525 #endif // BASE_HEAP_PROFILE_TABLE_H_ | 493 #endif // BASE_HEAP_PROFILE_TABLE_H_ |
OLD | NEW |