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
3 // found in the LICENSE file.
5 #include "base/trace_event/malloc_dump_provider.h"
9 #include "base/trace_event/process_memory_dump.h"
12 namespace trace_event
{
15 MallocDumpProvider
* MallocDumpProvider::GetInstance() {
16 return Singleton
<MallocDumpProvider
,
17 LeakySingletonTraits
<MallocDumpProvider
>>::get();
20 MallocDumpProvider::MallocDumpProvider() {
23 MallocDumpProvider::~MallocDumpProvider() {
26 // Called at trace dump point time. Creates a snapshot the memory counters for
27 // the current process.
28 bool MallocDumpProvider::OnMemoryDump(ProcessMemoryDump
* pmd
) {
29 struct mallinfo info
= mallinfo();
30 DCHECK_GE(info
.arena
+ info
.hblkhd
, info
.uordblks
);
32 MemoryAllocatorDump
* dump
= pmd
->CreateAllocatorDump("malloc");
36 // 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
38 // |arena| is 0 and the outer pages size is reported by |hblkhd|. In case of
39 // dlmalloc the total is given by |arena| + |hblkhd|.
40 // For more details see link: http://goo.gl/fMR8lF.
41 dump
->AddScalar(MemoryAllocatorDump::kNameOuterSize
,
42 MemoryAllocatorDump::kUnitsBytes
, info
.arena
+ info
.hblkhd
);
44 // Total allocated space is given by |uordblks|.
45 dump
->AddScalar(MemoryAllocatorDump::kNameInnerSize
,
46 MemoryAllocatorDump::kUnitsBytes
, info
.uordblks
);
51 } // namespace trace_event