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

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

Issue 1180693002: Update from https://crrev.com/333737 (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: rebased Created 5 years, 6 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/malloc_dump_provider.h ('k') | base/trace_event/memory_allocator_dump.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 // static 14 // static
15 const char MallocDumpProvider::kAllocatedObjects[] = "malloc/allocated_objects";
16
17 // static
15 MallocDumpProvider* MallocDumpProvider::GetInstance() { 18 MallocDumpProvider* MallocDumpProvider::GetInstance() {
16 return Singleton<MallocDumpProvider, 19 return Singleton<MallocDumpProvider,
17 LeakySingletonTraits<MallocDumpProvider>>::get(); 20 LeakySingletonTraits<MallocDumpProvider>>::get();
18 } 21 }
19 22
20 MallocDumpProvider::MallocDumpProvider() { 23 MallocDumpProvider::MallocDumpProvider() {
21 } 24 }
22 25
23 MallocDumpProvider::~MallocDumpProvider() { 26 MallocDumpProvider::~MallocDumpProvider() {
24 } 27 }
25 28
26 // Called at trace dump point time. Creates a snapshot the memory counters for 29 // Called at trace dump point time. Creates a snapshot the memory counters for
27 // the current process. 30 // the current process.
28 bool MallocDumpProvider::OnMemoryDump(ProcessMemoryDump* pmd) { 31 bool MallocDumpProvider::OnMemoryDump(ProcessMemoryDump* pmd) {
29 struct mallinfo info = mallinfo(); 32 struct mallinfo info = mallinfo();
30 DCHECK_GE(info.arena + info.hblkhd, info.uordblks); 33 DCHECK_GE(info.arena + info.hblkhd, info.uordblks);
31 34
32 MemoryAllocatorDump* dump = pmd->CreateAllocatorDump("malloc");
33 if (!dump)
34 return false;
35
36 // When the system allocator is implemented by tcmalloc, the total physical 35 // When the system allocator is implemented by tcmalloc, the total physical
37 // size is given by |arena| and |hblkhd| is 0. In case of Android's jemalloc 36 // size is given by |arena| and |hblkhd| is 0. In case of Android's jemalloc
38 // |arena| is 0 and the outer pages size is reported by |hblkhd|. In case of 37 // |arena| is 0 and the outer pages size is reported by |hblkhd|. In case of
39 // dlmalloc the total is given by |arena| + |hblkhd|. 38 // dlmalloc the total is given by |arena| + |hblkhd|.
40 // For more details see link: http://goo.gl/fMR8lF. 39 // For more details see link: http://goo.gl/fMR8lF.
41 dump->AddScalar(MemoryAllocatorDump::kNameOuterSize, 40 MemoryAllocatorDump* outer_dump = pmd->CreateAllocatorDump("malloc");
42 MemoryAllocatorDump::kUnitsBytes, info.arena + info.hblkhd); 41 outer_dump->AddScalar(MemoryAllocatorDump::kNameSize,
42 MemoryAllocatorDump::kUnitsBytes,
43 info.arena + info.hblkhd);
43 44
44 // Total allocated space is given by |uordblks|. 45 // Total allocated space is given by |uordblks|.
45 dump->AddScalar(MemoryAllocatorDump::kNameInnerSize, 46 MemoryAllocatorDump* inner_dump = pmd->CreateAllocatorDump(kAllocatedObjects);
46 MemoryAllocatorDump::kUnitsBytes, info.uordblks); 47 inner_dump->AddScalar(MemoryAllocatorDump::kNameSize,
48 MemoryAllocatorDump::kUnitsBytes, info.uordblks);
47 49
48 return true; 50 return true;
49 } 51 }
50 52
51 } // namespace trace_event 53 } // namespace trace_event
52 } // namespace base 54 } // namespace base
OLDNEW
« no previous file with comments | « base/trace_event/malloc_dump_provider.h ('k') | base/trace_event/memory_allocator_dump.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698