Chromium Code Reviews| 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..dd05b637f4f8904373e8c6af40bac2f64cb63758 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"; |
| +#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, |
| + 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. |
| + 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) { |
| + char buf[1024]; |
| + int len; |
| + const char* mangled_type_name = reinterpret_cast<const char*>(ptr); |
| + if (mangled_type_name == NULL) { |
| + len = snprintf(buf, 1023, "%6d: %8"PRId64" @ (no_typeinfo)\n", |
|
Alexander Potapenko
2012/08/17 11:44:51
Please use sizeof(buf) instead of an int literal.
Dai Mikurube (NOT FULLTIME)
2012/08/20 10:23:43
Done. 1023 may be typo...
|
| + count->objects, count->bytes); |
| + } else { |
| + len = snprintf(buf, 1023, "%6d: %8"PRId64" @ %s\n", |
| + count->objects, count->bytes, mangled_type_name); |
| + } |
| + RawWrite(args.fd, buf, len); |
| +} |
| +#endif // PROFILING_ALLOCATED_TYPE |
| + |
| inline |
| void HeapProfileTable::DumpNonLiveIterator(const void* ptr, AllocValue* v, |
| const DumpArgs& args) { |