| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "base/trace_event/malloc_dump_provider.h" | |
| 6 | |
| 7 #include <malloc.h> | |
| 8 | |
| 9 #include "base/trace_event/process_memory_dump.h" | |
| 10 | |
| 11 namespace base { | |
| 12 namespace trace_event { | |
| 13 | |
| 14 // static | |
| 15 const char MallocDumpProvider::kAllocatedObjects[] = "malloc/allocated_objects"; | |
| 16 | |
| 17 // static | |
| 18 MallocDumpProvider* MallocDumpProvider::GetInstance() { | |
| 19 return Singleton<MallocDumpProvider, | |
| 20 LeakySingletonTraits<MallocDumpProvider>>::get(); | |
| 21 } | |
| 22 | |
| 23 MallocDumpProvider::MallocDumpProvider() { | |
| 24 } | |
| 25 | |
| 26 MallocDumpProvider::~MallocDumpProvider() { | |
| 27 } | |
| 28 | |
| 29 // Called at trace dump point time. Creates a snapshot the memory counters for | |
| 30 // the current process. | |
| 31 bool MallocDumpProvider::OnMemoryDump(ProcessMemoryDump* pmd) { | |
| 32 struct mallinfo info = mallinfo(); | |
| 33 DCHECK_GE(info.arena + info.hblkhd, info.uordblks); | |
| 34 | |
| 35 // When the system allocator is implemented by tcmalloc, the total heap | |
| 36 // size is given by |arena| and |hblkhd| is 0. In case of Android's jemalloc | |
| 37 // |arena| is 0 and the outer pages size is reported by |hblkhd|. In case of | |
| 38 // dlmalloc the total is given by |arena| + |hblkhd|. | |
| 39 // For more details see link: http://goo.gl/fMR8lF. | |
| 40 MemoryAllocatorDump* outer_dump = pmd->CreateAllocatorDump("malloc"); | |
| 41 outer_dump->AddScalar("heap_virtual_size", MemoryAllocatorDump::kUnitsBytes, | |
| 42 info.arena + info.hblkhd); | |
| 43 | |
| 44 // Total allocated space is given by |uordblks|. | |
| 45 MemoryAllocatorDump* inner_dump = pmd->CreateAllocatorDump(kAllocatedObjects); | |
| 46 inner_dump->AddScalar(MemoryAllocatorDump::kNameSize, | |
| 47 MemoryAllocatorDump::kUnitsBytes, info.uordblks); | |
| 48 | |
| 49 return true; | |
| 50 } | |
| 51 | |
| 52 } // namespace trace_event | |
| 53 } // namespace base | |
| OLD | NEW |