Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(652)

Side by Side Diff: base/trace_event/malloc_dump_provider.cc

Issue 1408403004: [tracing] Fix resident size of malloc dump provider when tcmalloc is used (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Nit. Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/allocator/allocator_extension_thunks.cc ('k') | content/app/content_main_runner.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/allocator/allocator_extension_thunks.h"
9 #include "base/trace_event/process_memory_dump.h" 10 #include "base/trace_event/process_memory_dump.h"
10 11
11 namespace base { 12 namespace base {
12 namespace trace_event { 13 namespace trace_event {
13 14
14 // static 15 // static
15 const char MallocDumpProvider::kAllocatedObjects[] = "malloc/allocated_objects"; 16 const char MallocDumpProvider::kAllocatedObjects[] = "malloc/allocated_objects";
16 17
17 // static 18 // static
18 MallocDumpProvider* MallocDumpProvider::GetInstance() { 19 MallocDumpProvider* MallocDumpProvider::GetInstance() {
19 return Singleton<MallocDumpProvider, 20 return Singleton<MallocDumpProvider,
20 LeakySingletonTraits<MallocDumpProvider>>::get(); 21 LeakySingletonTraits<MallocDumpProvider>>::get();
21 } 22 }
22 23
23 MallocDumpProvider::MallocDumpProvider() { 24 MallocDumpProvider::MallocDumpProvider() {
24 } 25 }
25 26
26 MallocDumpProvider::~MallocDumpProvider() { 27 MallocDumpProvider::~MallocDumpProvider() {
27 } 28 }
28 29
29 // Called at trace dump point time. Creates a snapshot the memory counters for 30 // Called at trace dump point time. Creates a snapshot the memory counters for
30 // the current process. 31 // the current process.
31 bool MallocDumpProvider::OnMemoryDump(const MemoryDumpArgs& args, 32 bool MallocDumpProvider::OnMemoryDump(const MemoryDumpArgs& args,
32 ProcessMemoryDump* pmd) { 33 ProcessMemoryDump* pmd) {
33 struct mallinfo info = mallinfo(); 34 size_t total_virtual_size = 0;
34 DCHECK_GE(info.arena + info.hblkhd, info.uordblks); 35 size_t resident_size = 0;
36 size_t allocated_objects_size = 0;
35 37
36 // When the system allocator is implemented by tcmalloc, the total heap 38 allocator::thunks::GetNumericPropertyFunction get_property_function =
37 // size is given by |arena| and |hblkhd| is 0. In case of Android's jemalloc 39 allocator::thunks::GetGetNumericPropertyFunction();
38 // |arena| is 0 and the outer pages size is reported by |hblkhd|. In case of 40 if (get_property_function) {
39 // dlmalloc the total is given by |arena| + |hblkhd|. 41 // If the function is not null then tcmalloc is used. See
40 // For more details see link: http://goo.gl/fMR8lF. 42 // MallocExtension::getNumericProperty.
43 size_t pageheap_unmapped_bytes = 0;
44 bool res = get_property_function("generic.heap_size", &total_virtual_size);
45 DCHECK(res);
46 res = get_property_function("tcmalloc.pageheap_unmapped_bytes",
47 &pageheap_unmapped_bytes);
48 DCHECK(res);
49 res = get_property_function("generic.current_allocated_bytes",
50 &allocated_objects_size);
51 DCHECK(res);
52
53 // Please see TCMallocImplementation::GetStats implementation for
54 // explanation
55 // about this math.
56 // TODO(ssid): Usage of metadata is not included in page heap bytes
57 // (crbug.com/546491). MallocExtension::GetNumericProperty will be extended
58 // to get this value.
59 resident_size = total_virtual_size - pageheap_unmapped_bytes;
60 } else {
61 struct mallinfo info = mallinfo();
62 DCHECK_GE(info.arena + info.hblkhd, info.uordblks);
63
64 // In case of Android's jemalloc |arena| is 0 and the outer pages size is
65 // reported by |hblkhd|. In case of dlmalloc the total is given by
66 // |arena| + |hblkhd|. For more details see link: http://goo.gl/fMR8lF.
67 total_virtual_size = info.arena + info.hblkhd;
68 resident_size = info.uordblks;
69 allocated_objects_size = info.uordblks;
70 }
71
41 MemoryAllocatorDump* outer_dump = pmd->CreateAllocatorDump("malloc"); 72 MemoryAllocatorDump* outer_dump = pmd->CreateAllocatorDump("malloc");
42 outer_dump->AddScalar("virtual_size", 73 outer_dump->AddScalar("virtual_size", MemoryAllocatorDump::kUnitsBytes,
43 MemoryAllocatorDump::kUnitsBytes, 74 total_virtual_size);
44 info.arena + info.hblkhd); 75 outer_dump->AddScalar(MemoryAllocatorDump::kNameSize,
76 MemoryAllocatorDump::kUnitsBytes, resident_size);
45 77
46 // Total allocated space is given by |uordblks|. 78 // Total allocated space is given by |uordblks|.
47 MemoryAllocatorDump* inner_dump = pmd->CreateAllocatorDump(kAllocatedObjects); 79 MemoryAllocatorDump* inner_dump = pmd->CreateAllocatorDump(kAllocatedObjects);
48 inner_dump->AddScalar(MemoryAllocatorDump::kNameSize, 80 inner_dump->AddScalar(MemoryAllocatorDump::kNameSize,
49 MemoryAllocatorDump::kUnitsBytes, info.uordblks); 81 MemoryAllocatorDump::kUnitsBytes,
82 allocated_objects_size);
50 83
51 return true; 84 return true;
52 } 85 }
53 86
54 } // namespace trace_event 87 } // namespace trace_event
55 } // namespace base 88 } // namespace base
OLDNEW
« no previous file with comments | « base/allocator/allocator_extension_thunks.cc ('k') | content/app/content_main_runner.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698