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..a854d62b8de9761f23a4c594f8315cf6d770eaff 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(TYPE_PROFILING) |
+static const char kTypeProfileStatsHeader[] = "type statistics:\n"; |
+#endif // defined(TYPE_PROFILING) |
//---------------------------------------------------------------------- |
@@ -418,6 +421,30 @@ void HeapProfileTable::DumpMarkedObjects(AllocationMark mark, |
RawClose(fd); |
} |
+#if defined(TYPE_PROFILING) |
+void HeapProfileTable::DumpTypeStatistics( |
+ const char* file_name) const { |
jar (doing other things)
2012/10/01 21:59:44
nit: does this need to wrap here?
Dai Mikurube (NOT FULLTIME)
2012/10/02 06:35:12
Ah, not. Removed the newline.
|
+ AddressMap<TypeCount>* type_size_map; |
+ type_size_map = new(alloc_(sizeof(AddressMap<TypeCount>))) |
+ AddressMap<TypeCount>(alloc_, dealloc_); |
+ |
+ alloc_address_map_->Iterate(CountUpTypeIterator, type_size_map); |
+ |
+ RawFD fd = RawOpenForWriting(file_name); |
+ if (fd == kIllegalRawFD) { |
+ RAW_LOG(ERROR, "Failed dumping type statistics to %s", file_name); |
+ return; |
jar (doing other things)
2012/10/01 21:59:44
probably want to destructor and dealloc_(type_size
Dai Mikurube (NOT FULLTIME)
2012/10/02 06:35:12
Chose your suggestion. Thanks.
|
+ } |
+ RawWrite(fd, kTypeProfileStatsHeader, strlen(kTypeProfileStatsHeader)); |
+ const DumpArgs args(fd, NULL); |
+ type_size_map->Iterate<const DumpArgs&>(DumpTypeIterator, args); |
+ RawClose(fd); |
+ |
+ type_size_map->~AddressMap<TypeCount>(); |
+ dealloc_(type_size_map); |
+} |
+#endif // defined(TYPE_PROFILING) |
+ |
void HeapProfileTable::IterateOrderedAllocContexts( |
AllocContextIterator callback) const { |
Bucket** list = MakeSortedBucketList(); |
@@ -475,6 +502,46 @@ int HeapProfileTable::FillOrderedProfile(char buf[], int size) const { |
return bucket_length + map_length; |
} |
+#if defined(TYPE_PROFILING) |
+// static |
+void HeapProfileTable::CountUpTypeIterator( |
+ const void* ptr, |
+ AllocValue* value, |
+ AddressMap<TypeCount>* type_size_map) { |
+ const std::type_info* type = LookupType(ptr); |
+ |
+ const void* key; |
jar (doing other things)
2012/10/01 21:59:44
nit: initialize key to NULL here... then you don't
Dai Mikurube (NOT FULLTIME)
2012/10/02 06:35:12
Done.
|
+ if (type) { |
+ // In new Application Binary Interface (ABI), |
+ // type_info's Null-Terminated Byte String (NTBS) is unique. |
jar (doing other things)
2012/10/01 21:59:44
I don't understand the significance of this commen
Dai Mikurube (NOT FULLTIME)
2012/10/02 06:35:12
Done.
|
+ key = type->name(); |
+ } else { |
+ key = NULL; |
+ } |
+ |
+ TypeCount* count = type_size_map->FindMutable(key); |
+ if (count) { |
+ count->bytes += value->bytes; |
+ ++count->objects; |
+ } else { |
+ type_size_map->Insert(key, TypeCount(value->bytes, 1)); |
+ } |
+} |
+ |
+// static |
+void HeapProfileTable::DumpTypeIterator(const void* ptr, |
+ TypeCount* count, |
+ const DumpArgs& args) { |
+ char buf[1024]; |
+ int len; |
+ const char* mangled_type_name = static_cast<const char*>(ptr); |
+ len = snprintf(buf, sizeof(buf), "%6d: %8"PRId64" @ %s\n", |
+ count->objects, count->bytes, |
+ mangled_type_name ? mangled_type_name : "(no_typeinfo)"); |
+ RawWrite(args.fd, buf, len); |
+} |
+#endif // defined(TYPE_PROFILING) |
+ |
inline |
void HeapProfileTable::DumpNonLiveIterator(const void* ptr, AllocValue* v, |
const DumpArgs& args) { |