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

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

Issue 1410353005: Add generic.total_physical_bytes property to MallocExtension (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@web_cache2
Patch Set: Add in readme. 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 | « no previous file | third_party/tcmalloc/README.chromium » ('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/allocator/allocator_extension_thunks.h"
10 #include "base/trace_event/process_memory_dump.h" 10 #include "base/trace_event/process_memory_dump.h"
(...skipping 22 matching lines...) Expand all
33 ProcessMemoryDump* pmd) { 33 ProcessMemoryDump* pmd) {
34 size_t total_virtual_size = 0; 34 size_t total_virtual_size = 0;
35 size_t resident_size = 0; 35 size_t resident_size = 0;
36 size_t allocated_objects_size = 0; 36 size_t allocated_objects_size = 0;
37 37
38 allocator::thunks::GetNumericPropertyFunction get_property_function = 38 allocator::thunks::GetNumericPropertyFunction get_property_function =
39 allocator::thunks::GetGetNumericPropertyFunction(); 39 allocator::thunks::GetGetNumericPropertyFunction();
40 if (get_property_function) { 40 if (get_property_function) {
41 // If the function is not null then tcmalloc is used. See 41 // If the function is not null then tcmalloc is used. See
42 // MallocExtension::getNumericProperty. 42 // MallocExtension::getNumericProperty.
43 size_t pageheap_unmapped_bytes = 0;
44 bool res = get_property_function("generic.heap_size", &total_virtual_size); 43 bool res = get_property_function("generic.heap_size", &total_virtual_size);
45 DCHECK(res); 44 DCHECK(res);
46 res = get_property_function("tcmalloc.pageheap_unmapped_bytes", 45 res = get_property_function("generic.total_physical_bytes", &resident_size);
47 &pageheap_unmapped_bytes);
48 DCHECK(res); 46 DCHECK(res);
49 res = get_property_function("generic.current_allocated_bytes", 47 res = get_property_function("generic.current_allocated_bytes",
50 &allocated_objects_size); 48 &allocated_objects_size);
51 DCHECK(res); 49 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 { 50 } else {
61 struct mallinfo info = mallinfo(); 51 struct mallinfo info = mallinfo();
62 DCHECK_GE(info.arena + info.hblkhd, info.uordblks); 52 DCHECK_GE(info.arena + info.hblkhd, info.uordblks);
63 53
64 // In case of Android's jemalloc |arena| is 0 and the outer pages size is 54 // 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 55 // reported by |hblkhd|. In case of dlmalloc the total is given by
66 // |arena| + |hblkhd|. For more details see link: http://goo.gl/fMR8lF. 56 // |arena| + |hblkhd|. For more details see link: http://goo.gl/fMR8lF.
67 total_virtual_size = info.arena + info.hblkhd; 57 total_virtual_size = info.arena + info.hblkhd;
68 resident_size = info.uordblks; 58 resident_size = info.uordblks;
69 allocated_objects_size = info.uordblks; 59 allocated_objects_size = info.uordblks;
70 } 60 }
71 61
72 MemoryAllocatorDump* outer_dump = pmd->CreateAllocatorDump("malloc"); 62 MemoryAllocatorDump* outer_dump = pmd->CreateAllocatorDump("malloc");
73 outer_dump->AddScalar("virtual_size", MemoryAllocatorDump::kUnitsBytes, 63 outer_dump->AddScalar("virtual_size", MemoryAllocatorDump::kUnitsBytes,
74 total_virtual_size); 64 total_virtual_size);
75 outer_dump->AddScalar(MemoryAllocatorDump::kNameSize, 65 outer_dump->AddScalar(MemoryAllocatorDump::kNameSize,
76 MemoryAllocatorDump::kUnitsBytes, resident_size); 66 MemoryAllocatorDump::kUnitsBytes, resident_size);
77 67
78 // Total allocated space is given by |uordblks|. 68 // Total allocated space is given by |uordblks|.
79 MemoryAllocatorDump* inner_dump = pmd->CreateAllocatorDump(kAllocatedObjects); 69 MemoryAllocatorDump* inner_dump = pmd->CreateAllocatorDump(kAllocatedObjects);
80 inner_dump->AddScalar(MemoryAllocatorDump::kNameSize, 70 inner_dump->AddScalar(MemoryAllocatorDump::kNameSize,
81 MemoryAllocatorDump::kUnitsBytes, 71 MemoryAllocatorDump::kUnitsBytes,
82 allocated_objects_size); 72 allocated_objects_size);
83 73
84 return true; 74 return true;
85 } 75 }
86 76
87 } // namespace trace_event 77 } // namespace trace_event
88 } // namespace base 78 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | third_party/tcmalloc/README.chromium » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698