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

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

Issue 1531463004: [tracing]Fix resident size of malloc for mac and ios. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix comment. Created 5 years 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 | no next file » | 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 #if defined(OS_MACOSX) 7 #if defined(OS_MACOSX)
8 #include <malloc/malloc.h> 8 #include <malloc/malloc.h>
9 #else 9 #else
10 #include <malloc.h> 10 #include <malloc.h>
(...skipping 18 matching lines...) Expand all
29 29
30 MallocDumpProvider::~MallocDumpProvider() {} 30 MallocDumpProvider::~MallocDumpProvider() {}
31 31
32 // Called at trace dump point time. Creates a snapshot the memory counters for 32 // Called at trace dump point time. Creates a snapshot the memory counters for
33 // the current process. 33 // the current process.
34 bool MallocDumpProvider::OnMemoryDump(const MemoryDumpArgs& args, 34 bool MallocDumpProvider::OnMemoryDump(const MemoryDumpArgs& args,
35 ProcessMemoryDump* pmd) { 35 ProcessMemoryDump* pmd) {
36 size_t total_virtual_size = 0; 36 size_t total_virtual_size = 0;
37 size_t resident_size = 0; 37 size_t resident_size = 0;
38 size_t allocated_objects_size = 0; 38 size_t allocated_objects_size = 0;
39 #if defined(OS_MACOSX) || defined(OS_IOS) 39 #if defined(USE_TCMALLOC)
40 malloc_statistics_t stats = {0};
41 malloc_zone_statistics(nullptr, &stats);
42 total_virtual_size = stats.size_allocated;
43 resident_size = stats.size_in_use;
44 allocated_objects_size = stats.size_in_use;
45 #elif defined(USE_TCMALLOC)
46 bool res = 40 bool res =
47 allocator::GetNumericProperty("generic.heap_size", &total_virtual_size); 41 allocator::GetNumericProperty("generic.heap_size", &total_virtual_size);
48 DCHECK(res); 42 DCHECK(res);
49 res = allocator::GetNumericProperty("generic.total_physical_bytes", 43 res = allocator::GetNumericProperty("generic.total_physical_bytes",
50 &resident_size); 44 &resident_size);
51 DCHECK(res); 45 DCHECK(res);
52 res = allocator::GetNumericProperty("generic.current_allocated_bytes", 46 res = allocator::GetNumericProperty("generic.current_allocated_bytes",
53 &allocated_objects_size); 47 &allocated_objects_size);
54 DCHECK(res); 48 DCHECK(res);
49 #elif defined(OS_MACOSX) || defined(OS_IOS)
50 malloc_statistics_t stats = {0};
51 malloc_zone_statistics(nullptr, &stats);
52 total_virtual_size = stats.size_allocated;
53 allocated_objects_size = stats.size_in_use;
54
55 // The resident size is approximated to the max size in use, which would count
56 // the total size of all regions other than the free bytes at the end of each
57 // region. In each allocation region the allocations are rounded off to a
58 // fixed quantum, so the excess region will not be resident.
59 // See crrev.com/1531463004 for detailed explanation.
60 resident_size = stats.max_size_in_use;
55 #else 61 #else
56 struct mallinfo info = mallinfo(); 62 struct mallinfo info = mallinfo();
57 DCHECK_GE(info.arena + info.hblkhd, info.uordblks); 63 DCHECK_GE(info.arena + info.hblkhd, info.uordblks);
58 64
59 // In case of Android's jemalloc |arena| is 0 and the outer pages size is 65 // In case of Android's jemalloc |arena| is 0 and the outer pages size is
60 // reported by |hblkhd|. In case of dlmalloc the total is given by 66 // reported by |hblkhd|. In case of dlmalloc the total is given by
61 // |arena| + |hblkhd|. For more details see link: http://goo.gl/fMR8lF. 67 // |arena| + |hblkhd|. For more details see link: http://goo.gl/fMR8lF.
62 total_virtual_size = info.arena + info.hblkhd; 68 total_virtual_size = info.arena + info.hblkhd;
63 resident_size = info.uordblks; 69 resident_size = info.uordblks;
64 allocated_objects_size = info.uordblks; 70 allocated_objects_size = info.uordblks;
65 #endif 71 #endif
66 72
67 MemoryAllocatorDump* outer_dump = pmd->CreateAllocatorDump("malloc"); 73 MemoryAllocatorDump* outer_dump = pmd->CreateAllocatorDump("malloc");
68 outer_dump->AddScalar("virtual_size", MemoryAllocatorDump::kUnitsBytes, 74 outer_dump->AddScalar("virtual_size", MemoryAllocatorDump::kUnitsBytes,
69 total_virtual_size); 75 total_virtual_size);
70 outer_dump->AddScalar(MemoryAllocatorDump::kNameSize, 76 outer_dump->AddScalar(MemoryAllocatorDump::kNameSize,
71 MemoryAllocatorDump::kUnitsBytes, resident_size); 77 MemoryAllocatorDump::kUnitsBytes, resident_size);
72 78
73 // Total allocated space is given by |uordblks|. 79 // Total allocated space is given by |uordblks|.
74 MemoryAllocatorDump* inner_dump = pmd->CreateAllocatorDump(kAllocatedObjects); 80 MemoryAllocatorDump* inner_dump = pmd->CreateAllocatorDump(kAllocatedObjects);
75 inner_dump->AddScalar(MemoryAllocatorDump::kNameSize, 81 inner_dump->AddScalar(MemoryAllocatorDump::kNameSize,
76 MemoryAllocatorDump::kUnitsBytes, 82 MemoryAllocatorDump::kUnitsBytes,
77 allocated_objects_size); 83 allocated_objects_size);
78 84
85 if (resident_size - allocated_objects_size > 0) {
86 // Explicitly specify why is extra memory resident. In tcmalloc it accounts
87 // for free lists and caches. In mac and ios it accounts for the
88 // fragmentation and metadata.
89 MemoryAllocatorDump* other_dump =
90 pmd->CreateAllocatorDump("malloc/metadata_fragmentation_caches");
91 other_dump->AddScalar(MemoryAllocatorDump::kNameSize,
92 MemoryAllocatorDump::kUnitsBytes,
93 resident_size - allocated_objects_size);
94 }
95
79 return true; 96 return true;
80 } 97 }
81 98
82 } // namespace trace_event 99 } // namespace trace_event
83 } // namespace base 100 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698