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

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

Issue 1095003002: [tracing] Simplify design of MemoryAllocatorDump (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@matr_2_sess
Patch Set: Rebase Created 5 years, 8 months 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/trace_event/BUILD.gn ('k') | base/trace_event/memory_allocator_attributes.h » ('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/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 { 14 namespace {
15 15
16 const char kDumperFriendlyName[] = "Malloc"; 16 const char kDumperFriendlyName[] = "Malloc";
17 const char kDumperName[] = "malloc";
18 17
19 } // namespace 18 } // namespace
20 19
21 // static 20 // static
22 MallocDumpProvider* MallocDumpProvider::GetInstance() { 21 MallocDumpProvider* MallocDumpProvider::GetInstance() {
23 return Singleton<MallocDumpProvider, 22 return Singleton<MallocDumpProvider,
24 LeakySingletonTraits<MallocDumpProvider>>::get(); 23 LeakySingletonTraits<MallocDumpProvider>>::get();
25 } 24 }
26 25
27 MallocDumpProvider::MallocDumpProvider() { 26 MallocDumpProvider::MallocDumpProvider() {
28 } 27 }
29 28
30 MallocDumpProvider::~MallocDumpProvider() { 29 MallocDumpProvider::~MallocDumpProvider() {
31 } 30 }
32 31
33 // 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
34 // the current process. 33 // the current process.
35 bool MallocDumpProvider::DumpInto(ProcessMemoryDump* pmd) { 34 bool MallocDumpProvider::DumpInto(ProcessMemoryDump* pmd) {
36 struct mallinfo info = mallinfo(); 35 struct mallinfo info = mallinfo();
37 DCHECK(info.uordblks > 0); 36 DCHECK(info.uordblks > 0);
38 DCHECK_GE(info.arena + info.hblkhd, info.uordblks); 37 DCHECK_GE(info.arena + info.hblkhd, info.uordblks);
39 38
40 MemoryAllocatorDump* dump = pmd->CreateAllocatorDump(kDumperName); 39 MemoryAllocatorDump* dump =
40 pmd->CreateAllocatorDump("malloc", MemoryAllocatorDump::kRootHeap);
41 if (!dump) 41 if (!dump)
42 return false; 42 return false;
43 43
44 // When the system allocator is implemented by tcmalloc, the total physical 44 // When the system allocator is implemented by tcmalloc, the total physical
45 // size is given by |arena| and |hblkhd| is 0. In case of Android's jemalloc 45 // size is given by |arena| and |hblkhd| is 0. In case of Android's jemalloc
46 // |arena| is 0 and the outer pages size is reported by |hblkhd|. In case of 46 // |arena| is 0 and the outer pages size is reported by |hblkhd|. In case of
47 // dlmalloc the total is given by |arena| + |hblkhd|. 47 // dlmalloc the total is given by |arena| + |hblkhd|.
48 // For more details see link: http://goo.gl/fMR8lF. 48 // For more details see link: http://goo.gl/fMR8lF.
49 dump->set_physical_size_in_bytes(info.arena + info.hblkhd); 49 dump->set_physical_size_in_bytes(info.arena + info.hblkhd);
50 50
51 // mallinfo doesn't support any allocated object count. 51 // mallinfo doesn't support any allocated object count.
52 dump->set_allocated_objects_count(0); 52 dump->set_allocated_objects_count(0);
53 53
54 // Total allocated space is given by |uordblks|. 54 // Total allocated space is given by |uordblks|.
55 dump->set_allocated_objects_size_in_bytes(info.uordblks); 55 dump->set_allocated_objects_size_in_bytes(info.uordblks);
56 56
57 return true; 57 return true;
58 } 58 }
59 59
60 const char* MallocDumpProvider::GetFriendlyName() const { 60 const char* MallocDumpProvider::GetFriendlyName() const {
61 return kDumperFriendlyName; 61 return kDumperFriendlyName;
62 } 62 }
63 63
64 } // namespace trace_event 64 } // namespace trace_event
65 } // namespace base 65 } // namespace base
OLDNEW
« no previous file with comments | « base/trace_event/BUILD.gn ('k') | base/trace_event/memory_allocator_attributes.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698