blob: 92d513f99d3e311bef9aecce5d3a186736a78957 [file] [log] [blame]
ssid07386852015-04-14 15:32:371// 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.
4
5#include "base/trace_event/malloc_dump_provider.h"
6
7#include <malloc.h>
8
9#include "base/trace_event/process_memory_dump.h"
10
11namespace base {
12namespace trace_event {
13
ssid07386852015-04-14 15:32:3714// static
primianofadec05e2015-06-03 16:57:3215const char MallocDumpProvider::kAllocatedObjects[] = "malloc/allocated_objects";
16
17// static
ssid07386852015-04-14 15:32:3718MallocDumpProvider* MallocDumpProvider::GetInstance() {
19 return Singleton<MallocDumpProvider,
20 LeakySingletonTraits<MallocDumpProvider>>::get();
21}
22
23MallocDumpProvider::MallocDumpProvider() {
24}
25
26MallocDumpProvider::~MallocDumpProvider() {
27}
28
29// Called at trace dump point time. Creates a snapshot the memory counters for
30// the current process.
primiano2d56df1b2015-04-28 10:06:2631bool MallocDumpProvider::OnMemoryDump(ProcessMemoryDump* pmd) {
ssid07386852015-04-14 15:32:3732 struct mallinfo info = mallinfo();
ssid07386852015-04-14 15:32:3733 DCHECK_GE(info.arena + info.hblkhd, info.uordblks);
34
ssid07386852015-04-14 15:32:3735 // When the system allocator is implemented by tcmalloc, the total physical
36 // size is given by |arena| and |hblkhd| is 0. In case of Android's jemalloc
37 // |arena| is 0 and the outer pages size is reported by |hblkhd|. In case of
38 // dlmalloc the total is given by |arena| + |hblkhd|.
39 // For more details see link: http://goo.gl/fMR8lF.
primianofadec05e2015-06-03 16:57:3240 MemoryAllocatorDump* outer_dump = pmd->CreateAllocatorDump("malloc");
41 outer_dump->AddScalar(MemoryAllocatorDump::kNameSize,
42 MemoryAllocatorDump::kUnitsBytes,
43 info.arena + info.hblkhd);
ssid07386852015-04-14 15:32:3744
45 // Total allocated space is given by |uordblks|.
primianofadec05e2015-06-03 16:57:3246 MemoryAllocatorDump* inner_dump = pmd->CreateAllocatorDump(kAllocatedObjects);
47 inner_dump->AddScalar(MemoryAllocatorDump::kNameSize,
48 MemoryAllocatorDump::kUnitsBytes, info.uordblks);
ssid07386852015-04-14 15:32:3749
50 return true;
51}
52
ssid07386852015-04-14 15:32:3753} // namespace trace_event
54} // namespace base