Supervised user import: Listen for profile creation/deletion
[chromium-blink-merge.git] / base / trace_event / process_memory_dump.cc
blob54fcad6f2319211e7fb4fc1572cd49861571fc4f
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/process_memory_dump.h"
7 #include "base/trace_event/process_memory_totals.h"
8 #include "base/trace_event/trace_event_argument.h"
10 namespace base {
11 namespace trace_event {
13 ProcessMemoryDump::ProcessMemoryDump(
14 const scoped_refptr<MemoryDumpSessionState>& session_state)
15 : has_process_totals_(false),
16 has_process_mmaps_(false),
17 session_state_(session_state) {
20 ProcessMemoryDump::~ProcessMemoryDump() {
23 MemoryAllocatorDump* ProcessMemoryDump::CreateAllocatorDump(
24 const std::string& absolute_name) {
25 MemoryAllocatorDump* mad = new MemoryAllocatorDump(absolute_name, this);
26 DCHECK_EQ(0ul, allocator_dumps_.count(absolute_name));
27 allocator_dumps_storage_.push_back(mad);
28 allocator_dumps_[absolute_name] = mad;
29 return mad;
32 MemoryAllocatorDump* ProcessMemoryDump::GetAllocatorDump(
33 const std::string& absolute_name) const {
34 auto it = allocator_dumps_.find(absolute_name);
35 return it == allocator_dumps_.end() ? nullptr : it->second;
38 void ProcessMemoryDump::AsValueInto(TracedValue* value) const {
39 // Build up the [dumper name] -> [value] dictionary.
40 if (has_process_totals_) {
41 value->BeginDictionary("process_totals");
42 process_totals_.AsValueInto(value);
43 value->EndDictionary();
45 if (has_process_mmaps_) {
46 value->BeginDictionary("process_mmaps");
47 process_mmaps_.AsValueInto(value);
48 value->EndDictionary();
50 if (allocator_dumps_storage_.size() > 0) {
51 value->BeginDictionary("allocators");
52 for (const MemoryAllocatorDump* allocator_dump : allocator_dumps_storage_)
53 allocator_dump->AsValueInto(value);
54 value->EndDictionary();
58 } // namespace trace_event
59 } // namespace base