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

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

Issue 1028333002: Chromium -> Mojo roll. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: 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/strings/stringprintf.h"
9 #include "base/trace_event/memory_allocator_attributes.h"
10 #include "base/trace_event/memory_dump_manager.h"
11 #include "base/trace_event/memory_dump_provider.h"
12 #include "base/trace_event/trace_event_argument.h"
13 #include "base/values.h"
14
15 namespace base {
16 namespace trace_event {
17
18 MemoryAllocatorDump::MemoryAllocatorDump(const std::string& name,
19 MemoryAllocatorDump* parent)
20 : name_(name),
21 parent_(parent),
22 physical_size_in_bytes_(0),
23 allocated_objects_count_(0),
24 allocated_objects_size_in_bytes_(0) {
25 // Dots are not allowed in the name as the underlying base::DictionaryValue
26 // would treat them magically and split in sub-nodes, which is not intended.
27 DCHECK_EQ(std::string::npos, name.find_first_of('.'));
28 }
29
30 MemoryAllocatorDump::~MemoryAllocatorDump() {
31 }
32
33 void MemoryAllocatorDump::SetExtraAttribute(const std::string& name,
34 int value) {
35 extra_attributes_.SetInteger(name, value);
36 }
37
38 int MemoryAllocatorDump::GetExtraIntegerAttribute(
39 const std::string& name) const {
40 bool res;
41 int value = -1;
42 res = extra_attributes_.GetInteger(name, &value);
43 DCHECK(res) << "Allocator attribute '" << name << "' not found";
44 return value;
45 }
46
47 void MemoryAllocatorDump::AsValueInto(TracedValue* value) const {
48 static const char kHexFmt[] = "%" PRIx64;
49
50 value->BeginDictionary(name_.c_str());
51
52 value->SetString("parent", parent_ ? parent_->name_ : "");
53 value->SetString("physical_size_in_bytes",
54 StringPrintf(kHexFmt, physical_size_in_bytes_));
55 value->SetString("allocated_objects_count",
56 StringPrintf(kHexFmt, allocated_objects_count_));
57 value->SetString("allocated_objects_size_in_bytes",
58 StringPrintf(kHexFmt, allocated_objects_size_in_bytes_));
59
60 // Copy all the extra attributes.
61 const MemoryDumpProvider* mdp =
62 MemoryDumpManager::GetInstance()->dump_provider_currently_active();
63 const MemoryAllocatorDeclaredAttributes& extra_attributes_types =
64 mdp->allocator_attributes();
65
66 value->BeginDictionary("args");
67 for (DictionaryValue::Iterator it(extra_attributes_); !it.IsAtEnd();
68 it.Advance()) {
69 const std::string& attr_name = it.key();
70 const Value& attr_value = it.value();
71 value->BeginDictionary(attr_name.c_str());
72 value->SetValue("value", attr_value.DeepCopy());
73
74 auto attr_it = extra_attributes_types.find(attr_name);
75 DCHECK(attr_it != extra_attributes_types.end())
76 << "Allocator attribute " << attr_name
77 << " not declared for the dumper " << mdp->GetFriendlyName();
78
79 // TODO(primiano): the "type" should be dumped just once, not repeated on
80 // on every event. The ability of doing so depends on crbug.com/466121.
81 value->SetString("type", attr_it->second.type);
82
83 value->EndDictionary(); // "arg_name": { "type": "...", "value": "..." }
84 }
85 value->EndDictionary(); // "args": {}
86
87 value->EndDictionary(); // "allocator name": {}
88 }
89
90 } // namespace trace_event
91 } // namespace base
OLDNEW
« no previous file with comments | « base/trace_event/memory_allocator_dump.h ('k') | base/trace_event/memory_allocator_dump_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698