Index: third_party/tcmalloc/chromium/src/heap-profile-table.cc |
diff --git a/third_party/tcmalloc/chromium/src/heap-profile-table.cc b/third_party/tcmalloc/chromium/src/heap-profile-table.cc |
index dc7fc9c167fd289bbdf0cdc2c66d0565d48e0401..36a90b02ec22c5ddd5b60076c5baf0f61110d76a 100644 |
--- a/third_party/tcmalloc/chromium/src/heap-profile-table.cc |
+++ b/third_party/tcmalloc/chromium/src/heap-profile-table.cc |
@@ -92,6 +92,9 @@ DEFINE_int32(heap_check_max_leaks, |
// header of the dumped heap profile |
static const char kProfileHeader[] = "heap profile: "; |
static const char kProcSelfMapsHeader[] = "\nMAPPED_LIBRARIES:\n"; |
+#if defined(PROFILING_ALLOCATED_TYPE) |
+static const char kAllocatedTypeStatsHeader[] = "allocated type statistics:\n"; |
jar (doing other things)
2012/08/20 21:59:09
nit: globals are prefixed by g_
Dai Mikurube (NOT FULLTIME)
2012/08/21 04:45:44
It follows the other "static const" variables in t
|
+#endif // PROFILING_ALLOCATED_TYPE |
//---------------------------------------------------------------------- |
@@ -418,6 +421,30 @@ void HeapProfileTable::DumpMarkedObjects(AllocationMark mark, |
RawClose(fd); |
} |
+#if defined(PROFILING_ALLOCATED_TYPE) |
+void HeapProfileTable::DumpAllocatedTypeStatistics( |
+ const char* file_name) const { |
+ AddressMap<AllocatedTypeCount>* type_size_map; |
+ type_size_map = new(alloc_(sizeof(AddressMap<AllocatedTypeCount>))) |
+ AddressMap<AllocatedTypeCount>(alloc_, dealloc_); |
+ |
+ alloc_address_map_->Iterate(CountUpAllocatedTypeIterator, type_size_map); |
+ |
+ RawFD fd = RawOpenForWriting(file_name); |
+ if (fd == kIllegalRawFD) { |
+ RAW_LOG(ERROR, "Failed dumping allocated type statistics to %s", file_name); |
+ return; |
+ } |
+ RawWrite(fd, kAllocatedTypeStatsHeader, strlen(kAllocatedTypeStatsHeader)); |
+ const DumpArgs args(fd, NULL); |
+ type_size_map->Iterate<const DumpArgs&>(DumpAllocatedTypeIterator, args); |
+ RawClose(fd); |
+ |
+ type_size_map->~AddressMap<AllocatedTypeCount>(); |
+ dealloc_(type_size_map); |
+} |
+#endif // PROFILING_ALLOCATED_TYPE |
+ |
void HeapProfileTable::IterateOrderedAllocContexts( |
AllocContextIterator callback) const { |
Bucket** list = MakeSortedBucketList(); |
@@ -475,6 +502,47 @@ int HeapProfileTable::FillOrderedProfile(char buf[], int size) const { |
return bucket_length + map_length; |
} |
+#if defined(PROFILING_ALLOCATED_TYPE) |
+// static |
+void HeapProfileTable::CountUpAllocatedTypeIterator( |
+ const void* ptr, AllocValue* v, |
jar (doing other things)
2012/08/20 21:59:09
nit: one param per line.
Don't use single letter
Dai Mikurube (NOT FULLTIME)
2012/08/21 04:45:44
Renamed it to value, but I still prefer v for cons
|
+ AddressMap<AllocatedTypeCount>* type_size_map) { |
+ const std::type_info* type = ::LookupAllocatedType(ptr); |
+ |
+ const void* key; |
+ if (type) { |
+ // In new abi, type_info's NTBS is unique. |
jar (doing other things)
2012/08/20 21:59:09
Use words rather than abbreviations in comments.
Dai Mikurube (NOT FULLTIME)
2012/08/21 04:45:44
Done.
|
+ key = type->name(); |
+ } else { |
+ key = NULL; |
+ } |
+ |
+ AllocatedTypeCount* count = type_size_map->FindMutable(key); |
+ if (count) { |
+ count->bytes += v->bytes; |
+ ++count->objects; |
+ } else { |
+ type_size_map->Insert(key, AllocatedTypeCount(v->bytes, 1)); |
+ } |
+} |
+ |
+// static |
+void HeapProfileTable::DumpAllocatedTypeIterator( |
+ const void* ptr, AllocatedTypeCount* count, const DumpArgs& args) { |
jar (doing other things)
2012/08/20 21:59:09
nit: one arg per line, wrap at paren
Dai Mikurube (NOT FULLTIME)
2012/08/21 04:45:44
Done.
|
+ char buf[1024]; |
+ int len; |
+ const char* mangled_type_name = reinterpret_cast<const char*>(ptr); |
jar (doing other things)
2012/08/20 21:59:09
nit: prefer static_cast
Dai Mikurube (NOT FULLTIME)
2012/08/21 04:45:44
Thanks for the good catch. I mistook.
|
+ if (mangled_type_name == NULL) { |
+ len = snprintf(buf, sizeof(buf), "%6d: %8"PRId64" @ (no_typeinfo)\n", |
+ count->objects, count->bytes); |
+ } else { |
+ len = snprintf(buf, sizeof(buf), "%6d: %8"PRId64" @ %s\n", |
+ count->objects, count->bytes, mangled_type_name); |
jar (doing other things)
2012/08/20 21:59:09
Use a ternary expression, and you won't have to re
Dai Mikurube (NOT FULLTIME)
2012/08/21 04:45:44
Done.
|
+ } |
+ RawWrite(args.fd, buf, len); |
+} |
+#endif // PROFILING_ALLOCATED_TYPE |
+ |
inline |
void HeapProfileTable::DumpNonLiveIterator(const void* ptr, AllocValue* v, |
const DumpArgs& args) { |