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

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

Issue 1124763003: Update from https://crrev.com/327068 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: update nacl, buildtools, fix display_change_notifier_unittest Created 5 years, 7 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
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/trace_event/memory_allocator_dump.h" 5 #include "base/trace_event/memory_allocator_dump.h"
6 6
7 #include "base/format_macros.h" 7 #include "base/format_macros.h"
8 #include "base/strings/stringprintf.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" 9 #include "base/trace_event/memory_dump_manager.h"
11 #include "base/trace_event/memory_dump_provider.h" 10 #include "base/trace_event/memory_dump_provider.h"
11 #include "base/trace_event/process_memory_dump.h"
12 #include "base/trace_event/trace_event_argument.h" 12 #include "base/trace_event/trace_event_argument.h"
13 #include "base/values.h" 13 #include "base/values.h"
14 14
15 namespace base { 15 namespace base {
16 namespace trace_event { 16 namespace trace_event {
17 17
18 MemoryAllocatorDump::MemoryAllocatorDump(const std::string& name, 18 // static
19 MemoryAllocatorDump* parent) 19 const char MemoryAllocatorDump::kRootHeap[] = "";
20 : name_(name), 20
21 parent_(parent), 21 // static
22 std::string MemoryAllocatorDump::GetAbsoluteName(
23 const std::string& allocator_name,
24 const std::string& heap_name) {
25 return allocator_name + (heap_name == kRootHeap ? "" : "/" + heap_name);
26 }
27
28 MemoryAllocatorDump::MemoryAllocatorDump(const std::string& allocator_name,
29 const std::string& heap_name,
30 ProcessMemoryDump* process_memory_dump)
31 : allocator_name_(allocator_name),
32 heap_name_(heap_name),
33 process_memory_dump_(process_memory_dump),
22 physical_size_in_bytes_(0), 34 physical_size_in_bytes_(0),
23 allocated_objects_count_(0), 35 allocated_objects_count_(0),
24 allocated_objects_size_in_bytes_(0) { 36 allocated_objects_size_in_bytes_(0) {
25 // Dots are not allowed in the name as the underlying base::DictionaryValue 37 // The allocator name cannot be empty or contain slash separators.
38 DCHECK(!allocator_name.empty());
39 DCHECK_EQ(std::string::npos, allocator_name.find_first_of('/'));
40
41 // The heap_name can be empty and contain slash separator, but not
42 // leading or trailing ones.
43 DCHECK(heap_name.empty() ||
44 (heap_name[0] != '/' && *heap_name.rbegin() != '/'));
45
46 // Dots are not allowed anywhere as the underlying base::DictionaryValue
26 // would treat them magically and split in sub-nodes, which is not intended. 47 // would treat them magically and split in sub-nodes, which is not intended.
27 DCHECK_EQ(std::string::npos, name.find_first_of('.')); 48 DCHECK_EQ(std::string::npos, allocator_name.find_first_of('.'));
49 DCHECK_EQ(std::string::npos, heap_name.find_first_of('.'));
28 } 50 }
29 51
30 MemoryAllocatorDump::~MemoryAllocatorDump() { 52 MemoryAllocatorDump::~MemoryAllocatorDump() {
31 } 53 }
32 54
33 void MemoryAllocatorDump::SetExtraAttribute(const std::string& name, 55 void MemoryAllocatorDump::SetAttribute(const std::string& name, int value) {
34 int value) { 56 DCHECK(GetAttributesTypeInfo().Exists(allocator_name_, name))
35 extra_attributes_.SetInteger(name, value); 57 << "attribute '" << name << "' not declared."
58 << "See MemoryDumpProvider.DeclareAllocatorAttribute()";
59 attributes_values_.SetInteger(name, value);
36 } 60 }
37 61
38 int MemoryAllocatorDump::GetExtraIntegerAttribute( 62 std::string MemoryAllocatorDump::GetAbsoluteName() const {
39 const std::string& name) const { 63 return GetAbsoluteName(allocator_name_, heap_name_);
40 bool res; 64 }
65
66 int MemoryAllocatorDump::GetIntegerAttribute(const std::string& name) const {
41 int value = -1; 67 int value = -1;
42 res = extra_attributes_.GetInteger(name, &value); 68 bool res = attributes_values_.GetInteger(name, &value);
43 DCHECK(res) << "Allocator attribute '" << name << "' not found"; 69 DCHECK(res) << "Attribute '" << name << "' not found";
44 return value; 70 return value;
45 } 71 }
46 72
47 void MemoryAllocatorDump::AsValueInto(TracedValue* value) const { 73 void MemoryAllocatorDump::AsValueInto(TracedValue* value) const {
48 static const char kHexFmt[] = "%" PRIx64; 74 static const char kHexFmt[] = "%" PRIx64;
49 75
50 value->BeginDictionary(name_.c_str()); 76 value->BeginDictionary(GetAbsoluteName().c_str());
77 value->BeginDictionary("attrs");
51 78
52 value->SetString("parent", parent_ ? parent_->name_ : ""); 79 // TODO(primiano): these hard-coded types are temporary to transition to the
53 value->SetString("physical_size_in_bytes", 80 // new generalized attribute format. This code will be refactored by the end
54 StringPrintf(kHexFmt, physical_size_in_bytes_)); 81 // of May 2015.
55 value->SetString("allocated_objects_count", 82 value->BeginDictionary("outer_size");
56 StringPrintf(kHexFmt, allocated_objects_count_)); 83 value->SetString("type", "scalar");
57 value->SetString("allocated_objects_size_in_bytes", 84 value->SetString("units", "bytes");
85 value->SetString("value", StringPrintf(kHexFmt, physical_size_in_bytes_));
86 value->EndDictionary();
87
88 value->BeginDictionary("inner_size");
89 value->SetString("type", "scalar");
90 value->SetString("units", "bytes");
91 value->SetString("value",
58 StringPrintf(kHexFmt, allocated_objects_size_in_bytes_)); 92 StringPrintf(kHexFmt, allocated_objects_size_in_bytes_));
93 value->EndDictionary();
94
95 value->BeginDictionary("objects_count");
96 value->SetString("type", "scalar");
97 value->SetString("units", "objects");
98 value->SetString("value", StringPrintf(kHexFmt, allocated_objects_count_));
99 value->EndDictionary();
59 100
60 // Copy all the extra attributes. 101 // Copy all the extra attributes.
61 const MemoryDumpProvider* mdp = 102 for (DictionaryValue::Iterator it(attributes_values_); !it.IsAtEnd();
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()) { 103 it.Advance()) {
69 const std::string& attr_name = it.key(); 104 const std::string& attr_name = it.key();
70 const Value& attr_value = it.value(); 105 const Value& attr_value = it.value();
71 value->BeginDictionary(attr_name.c_str()); 106 value->BeginDictionary(attr_name.c_str());
72 value->SetValue("value", attr_value.DeepCopy()); 107 value->SetValue("value", attr_value.DeepCopy());
73 108
74 auto attr_it = extra_attributes_types.find(attr_name); 109 const std::string& attr_type =
75 DCHECK(attr_it != extra_attributes_types.end()) 110 GetAttributesTypeInfo().Get(allocator_name_, attr_name);
76 << "Allocator attribute " << attr_name 111 DCHECK(!attr_type.empty());
77 << " not declared for the dumper " << mdp->GetFriendlyName(); 112 value->SetString("type", "scalar");
78 113 value->SetString("units", attr_type);
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 114
83 value->EndDictionary(); // "arg_name": { "type": "...", "value": "..." } 115 value->EndDictionary(); // "arg_name": { "type": "...", "value": "..." }
84 } 116 }
85 value->EndDictionary(); // "args": {}
86 117
87 value->EndDictionary(); // "allocator name": {} 118 value->EndDictionary(); // "attrs": { ... }
119 value->EndDictionary(); // "allocator_name/heap_subheap": { ... }
120 }
121
122 const MemoryAllocatorAttributesTypeInfo&
123 MemoryAllocatorDump::GetAttributesTypeInfo() const {
124 return process_memory_dump_->session_state()->allocators_attributes_type_info;
88 } 125 }
89 126
90 } // namespace trace_event 127 } // namespace trace_event
91 } // namespace base 128 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698