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 <malloc.h> | 7 #include <malloc.h> |
8 | 8 |
9 #include "base/trace_event/process_memory_dump.h" | 9 #include "base/trace_event/process_memory_dump.h" |
10 | 10 |
11 namespace base { | 11 namespace base { |
12 namespace trace_event { | 12 namespace trace_event { |
13 | 13 |
14 namespace { | |
15 | |
16 const char kDumperFriendlyName[] = "Malloc"; | |
17 | |
18 } // namespace | |
19 | |
20 // static | 14 // static |
21 MallocDumpProvider* MallocDumpProvider::GetInstance() { | 15 MallocDumpProvider* MallocDumpProvider::GetInstance() { |
22 return Singleton<MallocDumpProvider, | 16 return Singleton<MallocDumpProvider, |
23 LeakySingletonTraits<MallocDumpProvider>>::get(); | 17 LeakySingletonTraits<MallocDumpProvider>>::get(); |
24 } | 18 } |
25 | 19 |
26 MallocDumpProvider::MallocDumpProvider() { | 20 MallocDumpProvider::MallocDumpProvider() { |
27 } | 21 } |
28 | 22 |
29 MallocDumpProvider::~MallocDumpProvider() { | 23 MallocDumpProvider::~MallocDumpProvider() { |
30 } | 24 } |
31 | 25 |
32 // Called at trace dump point time. Creates a snapshot the memory counters for | 26 // Called at trace dump point time. Creates a snapshot the memory counters for |
33 // the current process. | 27 // the current process. |
34 bool MallocDumpProvider::DumpInto(ProcessMemoryDump* pmd) { | 28 bool MallocDumpProvider::OnMemoryDump(ProcessMemoryDump* pmd) { |
35 struct mallinfo info = mallinfo(); | 29 struct mallinfo info = mallinfo(); |
36 DCHECK_GE(info.arena + info.hblkhd, info.uordblks); | 30 DCHECK_GE(info.arena + info.hblkhd, info.uordblks); |
37 | 31 |
38 MemoryAllocatorDump* dump = | 32 MemoryAllocatorDump* dump = pmd->CreateAllocatorDump("malloc"); |
39 pmd->CreateAllocatorDump("malloc", MemoryAllocatorDump::kRootHeap); | |
40 if (!dump) | 33 if (!dump) |
41 return false; | 34 return false; |
42 | 35 |
43 // When the system allocator is implemented by tcmalloc, the total physical | 36 // When the system allocator is implemented by tcmalloc, the total physical |
44 // size is given by |arena| and |hblkhd| is 0. In case of Android's jemalloc | 37 // size is given by |arena| and |hblkhd| is 0. In case of Android's jemalloc |
45 // |arena| is 0 and the outer pages size is reported by |hblkhd|. In case of | 38 // |arena| is 0 and the outer pages size is reported by |hblkhd|. In case of |
46 // dlmalloc the total is given by |arena| + |hblkhd|. | 39 // dlmalloc the total is given by |arena| + |hblkhd|. |
47 // For more details see link: http://goo.gl/fMR8lF. | 40 // For more details see link: http://goo.gl/fMR8lF. |
48 dump->set_physical_size_in_bytes(info.arena + info.hblkhd); | 41 dump->AddScalar(MemoryAllocatorDump::kNameOuterSize, |
49 | 42 MemoryAllocatorDump::kUnitsBytes, info.arena + info.hblkhd); |
50 // mallinfo doesn't support any allocated object count. | |
51 dump->set_allocated_objects_count(0); | |
52 | 43 |
53 // Total allocated space is given by |uordblks|. | 44 // Total allocated space is given by |uordblks|. |
54 dump->set_allocated_objects_size_in_bytes(info.uordblks); | 45 dump->AddScalar(MemoryAllocatorDump::kNameInnerSize, |
| 46 MemoryAllocatorDump::kUnitsBytes, info.uordblks); |
55 | 47 |
56 return true; | 48 return true; |
57 } | 49 } |
58 | 50 |
59 const char* MallocDumpProvider::GetFriendlyName() const { | |
60 return kDumperFriendlyName; | |
61 } | |
62 | |
63 } // namespace trace_event | 51 } // namespace trace_event |
64 } // namespace base | 52 } // namespace base |
OLD | NEW |