Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2005, Google Inc. | 1 // Copyright (c) 2005, 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 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 183 enum AddOrRemove { ADD, REMOVE }; | 183 enum AddOrRemove { ADD, REMOVE }; |
| 184 | 184 |
| 185 // Add or remove all MMap-allocated regions to/from *heap_profile. | 185 // Add or remove all MMap-allocated regions to/from *heap_profile. |
| 186 // Assumes heap_lock is held. | 186 // Assumes heap_lock is held. |
| 187 static void AddRemoveMMapDataLocked(AddOrRemove mode) { | 187 static void AddRemoveMMapDataLocked(AddOrRemove mode) { |
| 188 RAW_DCHECK(heap_lock.IsHeld(), ""); | 188 RAW_DCHECK(heap_lock.IsHeld(), ""); |
| 189 if (!FLAGS_mmap_profile || !is_on) return; | 189 if (!FLAGS_mmap_profile || !is_on) return; |
| 190 // MemoryRegionMap maintained all the data we need for all | 190 // MemoryRegionMap maintained all the data we need for all |
| 191 // mmap-like allocations, so we just use it here: | 191 // mmap-like allocations, so we just use it here: |
| 192 MemoryRegionMap::LockHolder l; | 192 MemoryRegionMap::LockHolder l; |
| 193 heap_profile->MMapRecordBegin(); | |
| 193 for (MemoryRegionMap::RegionIterator r = MemoryRegionMap::BeginRegionLocked(); | 194 for (MemoryRegionMap::RegionIterator r = MemoryRegionMap::BeginRegionLocked(); |
| 194 r != MemoryRegionMap::EndRegionLocked(); ++r) { | 195 r != MemoryRegionMap::EndRegionLocked(); ++r) { |
| 195 if (mode == ADD) { | 196 if (mode == ADD) { |
| 196 heap_profile->RecordAllocWithStack( | 197 heap_profile->RecordAllocWithStack( |
| 197 reinterpret_cast<const void*>(r->start_addr), | 198 reinterpret_cast<const void*>(r->start_addr), |
| 198 r->end_addr - r->start_addr, | 199 r->end_addr - r->start_addr, |
| 199 r->call_stack_depth, r->call_stack); | 200 r->call_stack_depth, r->call_stack); |
| 200 } else { | 201 } else { |
| 201 heap_profile->RecordFree(reinterpret_cast<void*>(r->start_addr)); | 202 heap_profile->RecordFree(reinterpret_cast<void*>(r->start_addr)); |
| 202 } | 203 } |
| 203 } | 204 } |
| 205 heap_profile->MMapRecordEnd(); | |
| 204 } | 206 } |
| 205 | 207 |
| 206 // Input must be a buffer of size at least 1MB. | 208 // Input must be a buffer of size at least 1MB. |
| 207 static char* DoGetHeapProfileLocked(char* buf, int buflen) { | 209 static char* DoGetHeapProfileLocked(char* buf, int buflen) { |
| 208 // We used to be smarter about estimating the required memory and | 210 // We used to be smarter about estimating the required memory and |
| 209 // then capping it to 1MB and generating the profile into that. | 211 // then capping it to 1MB and generating the profile into that. |
| 210 if (buf == NULL || buflen < 1) | 212 if (buf == NULL || buflen < 1) |
| 211 return NULL; | 213 return NULL; |
| 212 | 214 |
| 213 RAW_DCHECK(heap_lock.IsHeld(), ""); | 215 RAW_DCHECK(heap_lock.IsHeld(), ""); |
| 214 int bytes_written = 0; | 216 int bytes_written = 0; |
| 215 if (is_on) { | 217 if (is_on) { |
| 216 HeapProfileTable::Stats const stats = heap_profile->total(); | 218 HeapProfileTable::Stats const stats = heap_profile->total(); |
| 217 (void)stats; // avoid an unused-variable warning in non-debug mode. | 219 (void)stats; // avoid an unused-variable warning in non-debug mode. |
| 218 AddRemoveMMapDataLocked(ADD); | 220 AddRemoveMMapDataLocked(ADD); |
|
Dai Mikurube (NOT FULLTIME)
2011/12/01 07:56:42
mmap() log is merged into malloc() log here.
| |
| 219 bytes_written = heap_profile->FillOrderedProfile(buf, buflen - 1); | 221 bytes_written = heap_profile->FillOrderedProfile(buf, buflen - 1); |
| 220 // FillOrderedProfile should not reduce the set of active mmap-ed regions, | 222 // FillOrderedProfile should not reduce the set of active mmap-ed regions, |
| 221 // hence MemoryRegionMap will let us remove everything we've added above: | 223 // hence MemoryRegionMap will let us remove everything we've added above: |
| 222 AddRemoveMMapDataLocked(REMOVE); | 224 AddRemoveMMapDataLocked(REMOVE); |
|
Dai Mikurube (NOT FULLTIME)
2011/12/01 07:56:42
mmap() log is removed from malloc() log here.
| |
| 223 RAW_DCHECK(stats.Equivalent(heap_profile->total()), ""); | 225 RAW_DCHECK(stats.Equivalent(heap_profile->total()), ""); |
| 224 // if this fails, we somehow removed by AddRemoveMMapDataLocked | 226 // if this fails, we somehow removed by AddRemoveMMapDataLocked |
| 225 // more than we have added. | 227 // more than we have added. |
| 226 } | 228 } |
| 227 buf[bytes_written] = '\0'; | 229 buf[bytes_written] = '\0'; |
| 228 RAW_DCHECK(bytes_written == strlen(buf), ""); | 230 RAW_DCHECK(bytes_written == strlen(buf), ""); |
| 229 | 231 |
| 230 return buf; | 232 return buf; |
| 231 } | 233 } |
| 232 | 234 |
| (...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 581 | 583 |
| 582 // class used for finalization -- dumps the heap-profile at program exit | 584 // class used for finalization -- dumps the heap-profile at program exit |
| 583 struct HeapProfileEndWriter { | 585 struct HeapProfileEndWriter { |
| 584 ~HeapProfileEndWriter() { HeapProfilerDump("Exiting"); } | 586 ~HeapProfileEndWriter() { HeapProfilerDump("Exiting"); } |
| 585 }; | 587 }; |
| 586 | 588 |
| 587 // We want to make sure tcmalloc is up and running before starting the profiler | 589 // We want to make sure tcmalloc is up and running before starting the profiler |
| 588 static const TCMallocGuard tcmalloc_initializer; | 590 static const TCMallocGuard tcmalloc_initializer; |
| 589 REGISTER_MODULE_INITIALIZER(heapprofiler, HeapProfilerInit()); | 591 REGISTER_MODULE_INITIALIZER(heapprofiler, HeapProfilerInit()); |
| 590 static HeapProfileEndWriter heap_profile_end_writer; | 592 static HeapProfileEndWriter heap_profile_end_writer; |
| OLD | NEW |