| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/trace_event/malloc_dump_provider.h" | 5 #include "base/trace_event/malloc_dump_provider.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <unordered_map> | 9 #include <unordered_map> |
| 10 | 10 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 #include <malloc.h> | 25 #include <malloc.h> |
| 26 #endif | 26 #endif |
| 27 #if defined(OS_WIN) | 27 #if defined(OS_WIN) |
| 28 #include <windows.h> | 28 #include <windows.h> |
| 29 #endif | 29 #endif |
| 30 | 30 |
| 31 namespace base { | 31 namespace base { |
| 32 namespace trace_event { | 32 namespace trace_event { |
| 33 | 33 |
| 34 namespace { | 34 namespace { |
| 35 #if BUILDFLAG(USE_EXPERIMENTAL_ALLOCATOR_SHIM) | 35 #if BUILDFLAG(USE_ALLOCATOR_SHIM) |
| 36 | 36 |
| 37 using allocator::AllocatorDispatch; | 37 using allocator::AllocatorDispatch; |
| 38 | 38 |
| 39 void* HookAlloc(const AllocatorDispatch* self, size_t size, void* context) { | 39 void* HookAlloc(const AllocatorDispatch* self, size_t size, void* context) { |
| 40 const AllocatorDispatch* const next = self->next; | 40 const AllocatorDispatch* const next = self->next; |
| 41 void* ptr = next->alloc_function(next, size, context); | 41 void* ptr = next->alloc_function(next, size, context); |
| 42 if (ptr) | 42 if (ptr) |
| 43 MallocDumpProvider::GetInstance()->InsertAllocation(ptr, size); | 43 MallocDumpProvider::GetInstance()->InsertAllocation(ptr, size); |
| 44 return ptr; | 44 return ptr; |
| 45 } | 45 } |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 &HookZeroInitAlloc, /* alloc_zero_initialized_function */ | 132 &HookZeroInitAlloc, /* alloc_zero_initialized_function */ |
| 133 &HookAllocAligned, /* alloc_aligned_function */ | 133 &HookAllocAligned, /* alloc_aligned_function */ |
| 134 &HookRealloc, /* realloc_function */ | 134 &HookRealloc, /* realloc_function */ |
| 135 &HookFree, /* free_function */ | 135 &HookFree, /* free_function */ |
| 136 &HookGetSizeEstimate, /* get_size_estimate_function */ | 136 &HookGetSizeEstimate, /* get_size_estimate_function */ |
| 137 &HookBatchMalloc, /* batch_malloc_function */ | 137 &HookBatchMalloc, /* batch_malloc_function */ |
| 138 &HookBatchFree, /* batch_free_function */ | 138 &HookBatchFree, /* batch_free_function */ |
| 139 &HookFreeDefiniteSize, /* free_definite_size_function */ | 139 &HookFreeDefiniteSize, /* free_definite_size_function */ |
| 140 nullptr, /* next */ | 140 nullptr, /* next */ |
| 141 }; | 141 }; |
| 142 #endif // BUILDFLAG(USE_EXPERIMENTAL_ALLOCATOR_SHIM) | 142 #endif // BUILDFLAG(USE_ALLOCATOR_SHIM) |
| 143 | 143 |
| 144 #if defined(OS_WIN) | 144 #if defined(OS_WIN) |
| 145 // A structure containing some information about a given heap. | 145 // A structure containing some information about a given heap. |
| 146 struct WinHeapInfo { | 146 struct WinHeapInfo { |
| 147 size_t committed_size; | 147 size_t committed_size; |
| 148 size_t uncommitted_size; | 148 size_t uncommitted_size; |
| 149 size_t allocated_size; | 149 size_t allocated_size; |
| 150 size_t block_count; | 150 size_t block_count; |
| 151 }; | 151 }; |
| 152 | 152 |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 MemoryAllocatorDump::kUnitsObjects, | 319 MemoryAllocatorDump::kUnitsObjects, |
| 320 shim_allocated_objects_count); | 320 shim_allocated_objects_count); |
| 321 pmd->DumpHeapUsage(metrics_by_context, overhead, "malloc"); | 321 pmd->DumpHeapUsage(metrics_by_context, overhead, "malloc"); |
| 322 } | 322 } |
| 323 tid_dumping_heap_ = kInvalidThreadId; | 323 tid_dumping_heap_ = kInvalidThreadId; |
| 324 | 324 |
| 325 return true; | 325 return true; |
| 326 } | 326 } |
| 327 | 327 |
| 328 void MallocDumpProvider::OnHeapProfilingEnabled(bool enabled) { | 328 void MallocDumpProvider::OnHeapProfilingEnabled(bool enabled) { |
| 329 #if BUILDFLAG(USE_EXPERIMENTAL_ALLOCATOR_SHIM) | 329 #if BUILDFLAG(USE_ALLOCATOR_SHIM) |
| 330 if (enabled) { | 330 if (enabled) { |
| 331 allocation_register_.SetEnabled(); | 331 allocation_register_.SetEnabled(); |
| 332 allocator::InsertAllocatorDispatch(&g_allocator_hooks); | 332 allocator::InsertAllocatorDispatch(&g_allocator_hooks); |
| 333 } else { | 333 } else { |
| 334 allocation_register_.SetDisabled(); | 334 allocation_register_.SetDisabled(); |
| 335 } | 335 } |
| 336 #endif | 336 #endif |
| 337 } | 337 } |
| 338 | 338 |
| 339 void MallocDumpProvider::InsertAllocation(void* address, size_t size) { | 339 void MallocDumpProvider::InsertAllocation(void* address, size_t size) { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 367 if (tid_dumping_heap_ != kInvalidThreadId && | 367 if (tid_dumping_heap_ != kInvalidThreadId && |
| 368 tid_dumping_heap_ == PlatformThread::CurrentId()) | 368 tid_dumping_heap_ == PlatformThread::CurrentId()) |
| 369 return; | 369 return; |
| 370 if (!allocation_register_.is_enabled()) | 370 if (!allocation_register_.is_enabled()) |
| 371 return; | 371 return; |
| 372 allocation_register_.Remove(address); | 372 allocation_register_.Remove(address); |
| 373 } | 373 } |
| 374 | 374 |
| 375 } // namespace trace_event | 375 } // namespace trace_event |
| 376 } // namespace base | 376 } // namespace base |
| OLD | NEW |