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" |
Primiano Tucci (use gerrit)
2015/10/26 14:25:35
please add an include "build/build_config.h", othe
ssid
2015/10/26 17:10:40
Done.
| |
10 | 10 |
11 #if defined(USE_TCMALLOC) | |
12 #include "third_party/tcmalloc/chromium/src/gperftools/malloc_extension.h" | |
13 #endif | |
14 | |
11 namespace base { | 15 namespace base { |
12 namespace trace_event { | 16 namespace trace_event { |
13 | 17 |
14 // static | 18 // static |
15 const char MallocDumpProvider::kAllocatedObjects[] = "malloc/allocated_objects"; | 19 const char MallocDumpProvider::kAllocatedObjects[] = "malloc/allocated_objects"; |
16 | 20 |
17 // static | 21 // static |
18 MallocDumpProvider* MallocDumpProvider::GetInstance() { | 22 MallocDumpProvider* MallocDumpProvider::GetInstance() { |
19 return Singleton<MallocDumpProvider, | 23 return Singleton<MallocDumpProvider, |
20 LeakySingletonTraits<MallocDumpProvider>>::get(); | 24 LeakySingletonTraits<MallocDumpProvider>>::get(); |
21 } | 25 } |
22 | 26 |
23 MallocDumpProvider::MallocDumpProvider() { | 27 MallocDumpProvider::MallocDumpProvider() { |
24 } | 28 } |
25 | 29 |
26 MallocDumpProvider::~MallocDumpProvider() { | 30 MallocDumpProvider::~MallocDumpProvider() { |
27 } | 31 } |
28 | 32 |
29 // Called at trace dump point time. Creates a snapshot the memory counters for | 33 // Called at trace dump point time. Creates a snapshot the memory counters for |
30 // the current process. | 34 // the current process. |
31 bool MallocDumpProvider::OnMemoryDump(const MemoryDumpArgs& args, | 35 bool MallocDumpProvider::OnMemoryDump(const MemoryDumpArgs& args, |
32 ProcessMemoryDump* pmd) { | 36 ProcessMemoryDump* pmd) { |
37 size_t total_virtual_size = 0; | |
38 size_t resident_size = 0; | |
39 size_t allocated_objects_size = 0; | |
40 | |
41 #if defined(USE_TCMALLOC) | |
42 size_t pageheap_unmapped_bytes = 0; | |
43 bool res = MallocExtension::instance()->GetNumericProperty( | |
44 "generic.heap_size", &total_virtual_size); | |
45 DCHECK(res); | |
46 res = MallocExtension::instance()->GetNumericProperty( | |
47 "tcmalloc.pageheap_unmapped_bytes", &pageheap_unmapped_bytes); | |
48 DCHECK(res); | |
49 res = MallocExtension::instance()->GetNumericProperty( | |
50 "generic.current_allocated_bytes", &allocated_objects_size); | |
51 DCHECK(res); | |
52 | |
53 // TODO(ssid): Usage of metadata is not included in page heap bytes | |
54 // (crbug.com/546491). MallocExtension::GetNumericProperty will be extended | |
55 // to get this value. | |
56 resident_size = total_virtual_size - pageheap_unmapped_bytes; | |
Primiano Tucci (use gerrit)
2015/10/26 14:25:35
Maybe add a comment with a pointer to the tcmalloc
ssid
2015/10/26 17:10:40
Done.
| |
57 #else // defined(USE_TCMALLOC) | |
58 | |
33 struct mallinfo info = mallinfo(); | 59 struct mallinfo info = mallinfo(); |
34 DCHECK_GE(info.arena + info.hblkhd, info.uordblks); | 60 DCHECK_GE(info.arena + info.hblkhd, info.uordblks); |
35 | 61 |
36 // When the system allocator is implemented by tcmalloc, the total heap | 62 // In case of Android's jemalloc |arena| is 0 and the outer pages size is |
37 // size is given by |arena| and |hblkhd| is 0. In case of Android's jemalloc | 63 // reported by |hblkhd|. In case of dlmalloc the total is given by |
38 // |arena| is 0 and the outer pages size is reported by |hblkhd|. In case of | 64 // |arena| + |hblkhd|. For more details see link: http://goo.gl/fMR8lF. |
39 // dlmalloc the total is given by |arena| + |hblkhd|. | 65 total_virtual_size = info.arena + info.hblkhd; |
40 // For more details see link: http://goo.gl/fMR8lF. | 66 resident_size = info.uordblks; |
67 allocated_objects_size = info.uordblks; | |
68 #endif // defined(USE_TCMALLOC) | |
69 | |
41 MemoryAllocatorDump* outer_dump = pmd->CreateAllocatorDump("malloc"); | 70 MemoryAllocatorDump* outer_dump = pmd->CreateAllocatorDump("malloc"); |
42 outer_dump->AddScalar("virtual_size", | 71 outer_dump->AddScalar("virtual_size", MemoryAllocatorDump::kUnitsBytes, |
43 MemoryAllocatorDump::kUnitsBytes, | 72 total_virtual_size); |
44 info.arena + info.hblkhd); | 73 outer_dump->AddScalar(MemoryAllocatorDump::kNameSize, |
74 MemoryAllocatorDump::kUnitsBytes, resident_size); | |
45 | 75 |
46 // Total allocated space is given by |uordblks|. | 76 // Total allocated space is given by |uordblks|. |
47 MemoryAllocatorDump* inner_dump = pmd->CreateAllocatorDump(kAllocatedObjects); | 77 MemoryAllocatorDump* inner_dump = pmd->CreateAllocatorDump(kAllocatedObjects); |
48 inner_dump->AddScalar(MemoryAllocatorDump::kNameSize, | 78 inner_dump->AddScalar(MemoryAllocatorDump::kNameSize, |
49 MemoryAllocatorDump::kUnitsBytes, info.uordblks); | 79 MemoryAllocatorDump::kUnitsBytes, |
80 allocated_objects_size); | |
50 | 81 |
51 return true; | 82 return true; |
52 } | 83 } |
53 | 84 |
54 } // namespace trace_event | 85 } // namespace trace_event |
55 } // namespace base | 86 } // namespace base |
OLD | NEW |