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

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

Issue 987043003: [tracing] Introduce support for userland memory allocators dumps. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mmaps_en
Patch Set: Rebase Created 5 years, 9 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
OLDNEW
(Empty)
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.
4
5 #include "base/trace_event/memory_allocator_dump.h"
6
7 #include "base/format_macros.h"
8 #include "base/trace_event/memory_allocator_attributes.h"
9 #include "base/trace_event/memory_dump_manager.h"
10 #include "base/trace_event/memory_dump_provider.h"
11 #include "base/trace_event/trace_event_argument.h"
12 #include "base/values.h"
13
14 namespace base {
15 namespace trace_event {
16
17 MemoryAllocatorDump::MemoryAllocatorDump(const std::string& name,
18 MemoryAllocatorDump* parent)
19 : name_(name),
20 parent_(parent),
21 physical_size_in_bytes_(0),
22 allocated_objects_count_(0),
23 allocated_objects_size_in_bytes_(0) {
24 }
25
26 MemoryAllocatorDump::~MemoryAllocatorDump() {
27 }
28
29 void MemoryAllocatorDump::SetExtraAttribute(const std::string& name,
30 int value) {
31 extra_attributes_.SetInteger(name, value);
32 }
33
34 int MemoryAllocatorDump::GetExtraIntegerAttribute(
35 const std::string& name) const {
36 bool res;
37 int value = -1;
38 res = extra_attributes_.GetInteger(name, &value);
39 DCHECK(res) << "Allocator attribute '" << name << "' not found";
40 return value;
41 }
42
43 void MemoryAllocatorDump::AsValueInto(TracedValue* value) const {
44 value->BeginDictionary(name_.c_str());
45
46 value->SetString("parent", parent_ ? parent_->name_ : "");
47 value->SetInteger("physical_size", physical_size_in_bytes_);
48 value->SetInteger("allocated_objects_count", allocated_objects_count_);
49 value->SetInteger("allocated_objects_size", allocated_objects_size_in_bytes_);
50
51 // Copy all the extra attributes.
52 const MemoryDumpProvider* mdp =
53 MemoryDumpManager::GetInstance()->dump_provider_currently_active();
54 const MemoryAllocatorDeclaredAttributes& extra_attributes_types =
55 mdp->allocator_attributes();
picksi 2015/03/16 09:18:06 mdp can bull a nullptr if this is called when a du
Primiano Tucci (use gerrit) 2015/03/16 09:57:17 Usually the rule in chromium is to NOT dcheck for
56
57 value->BeginDictionary("args");
58 for (DictionaryValue::Iterator it(extra_attributes_); !it.IsAtEnd();
59 it.Advance()) {
60 const std::string& attr_name = it.key();
61 const Value& attr_value = it.value();
62 value->BeginDictionary(attr_name.c_str());
63 value->SetValue("value", attr_value.DeepCopy());
64
65 auto attr_it = extra_attributes_types.find(attr_name);
66 DCHECK(attr_it != extra_attributes_types.end())
67 << "Allocator attribute " << attr_name
68 << " not declared for the dumper " << mdp->GetFriendlyName();
69 value->SetString("type", attr_it->second.type);
70
71 value->EndDictionary(); // "arg_name": { "type": "...", "value": "..." }
72 }
73 value->EndDictionary(); // "args": {}
74
75 value->EndDictionary(); // "allocator name": {}
76 }
77
78 } // namespace trace_event
79 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698