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
{
16 const char kDumperFriendlyName
[] = "Malloc";
17 const char kDumperName
[] = "malloc";
22 MallocDumpProvider
* MallocDumpProvider::GetInstance() {
23 return Singleton
<MallocDumpProvider
,
24 LeakySingletonTraits
<MallocDumpProvider
>>::get();
27 MallocDumpProvider::MallocDumpProvider() {
30 MallocDumpProvider::~MallocDumpProvider() {
33 // Called at trace dump point time. Creates a snapshot the memory counters for
34 // the current process.
35 bool MallocDumpProvider::DumpInto(ProcessMemoryDump
* pmd
) {
36 struct mallinfo info
= mallinfo();
37 DCHECK(info
.uordblks
> 0);
38 DCHECK_GE(info
.arena
+ info
.hblkhd
, info
.uordblks
);
40 MemoryAllocatorDump
* dump
= pmd
->CreateAllocatorDump(kDumperName
);
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
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|.
48 // For more details see link: http://goo.gl/fMR8lF.
49 dump
->set_physical_size_in_bytes(info
.arena
+ info
.hblkhd
);
51 // mallinfo doesn't support any allocated object count.
52 dump
->set_allocated_objects_count(0);
54 // Total allocated space is given by |uordblks|.
55 dump
->set_allocated_objects_size_in_bytes(info
.uordblks
);
60 const char* MallocDumpProvider::GetFriendlyName() const {
61 return kDumperFriendlyName
;
64 } // namespace trace_event