OLD | NEW |
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_dump_manager.h" | 9 #include "base/trace_event/memory_dump_manager.h" |
10 #include "base/trace_event/memory_dump_provider.h" | 10 #include "base/trace_event/memory_dump_provider.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 // Dots are not allowed anywhere as the underlying base::DictionaryValue | 46 // Dots are not allowed anywhere as the underlying base::DictionaryValue |
47 // 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. |
48 DCHECK_EQ(std::string::npos, allocator_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('.')); | 49 DCHECK_EQ(std::string::npos, heap_name.find_first_of('.')); |
50 } | 50 } |
51 | 51 |
52 MemoryAllocatorDump::~MemoryAllocatorDump() { | 52 MemoryAllocatorDump::~MemoryAllocatorDump() { |
53 } | 53 } |
54 | 54 |
55 void MemoryAllocatorDump::SetAttribute(const std::string& name, int value) { | 55 void MemoryAllocatorDump::SetAttribute(const std::string& name, int value) { |
56 DCHECK(GetAttributesTypeInfo().Exists(allocator_name_, name)) | |
57 << "attribute '" << name << "' not declared." | |
58 << "See MemoryDumpProvider.DeclareAllocatorAttribute()"; | |
59 attributes_values_.SetInteger(name, value); | 56 attributes_values_.SetInteger(name, value); |
60 } | 57 } |
61 | 58 |
62 std::string MemoryAllocatorDump::GetAbsoluteName() const { | 59 std::string MemoryAllocatorDump::GetAbsoluteName() const { |
63 return GetAbsoluteName(allocator_name_, heap_name_); | 60 return GetAbsoluteName(allocator_name_, heap_name_); |
64 } | 61 } |
65 | 62 |
66 int MemoryAllocatorDump::GetIntegerAttribute(const std::string& name) const { | 63 int MemoryAllocatorDump::GetIntegerAttribute(const std::string& name) const { |
67 int value = -1; | 64 int value = -1; |
68 bool res = attributes_values_.GetInteger(name, &value); | 65 bool res = attributes_values_.GetInteger(name, &value); |
(...skipping 22 matching lines...) Expand all Loading... |
91 value->SetString("value", | 88 value->SetString("value", |
92 StringPrintf(kHexFmt, allocated_objects_size_in_bytes_)); | 89 StringPrintf(kHexFmt, allocated_objects_size_in_bytes_)); |
93 value->EndDictionary(); | 90 value->EndDictionary(); |
94 | 91 |
95 value->BeginDictionary("objects_count"); | 92 value->BeginDictionary("objects_count"); |
96 value->SetString("type", "scalar"); | 93 value->SetString("type", "scalar"); |
97 value->SetString("units", "objects"); | 94 value->SetString("units", "objects"); |
98 value->SetString("value", StringPrintf(kHexFmt, allocated_objects_count_)); | 95 value->SetString("value", StringPrintf(kHexFmt, allocated_objects_count_)); |
99 value->EndDictionary(); | 96 value->EndDictionary(); |
100 | 97 |
101 // Copy all the extra attributes. | |
102 for (DictionaryValue::Iterator it(attributes_values_); !it.IsAtEnd(); | |
103 it.Advance()) { | |
104 const std::string& attr_name = it.key(); | |
105 const Value& attr_value = it.value(); | |
106 value->BeginDictionary(attr_name.c_str()); | |
107 value->SetValue("value", attr_value.DeepCopy()); | |
108 | |
109 const std::string& attr_type = | |
110 GetAttributesTypeInfo().Get(allocator_name_, attr_name); | |
111 DCHECK(!attr_type.empty()); | |
112 value->SetString("type", "scalar"); | |
113 value->SetString("units", attr_type); | |
114 | |
115 value->EndDictionary(); // "arg_name": { "type": "...", "value": "..." } | |
116 } | |
117 | |
118 value->EndDictionary(); // "attrs": { ... } | 98 value->EndDictionary(); // "attrs": { ... } |
119 value->EndDictionary(); // "allocator_name/heap_subheap": { ... } | 99 value->EndDictionary(); // "allocator_name/heap_subheap": { ... } |
120 } | 100 } |
121 | 101 |
122 const MemoryAllocatorAttributesTypeInfo& | |
123 MemoryAllocatorDump::GetAttributesTypeInfo() const { | |
124 return process_memory_dump_->session_state()->allocators_attributes_type_info; | |
125 } | |
126 | |
127 } // namespace trace_event | 102 } // namespace trace_event |
128 } // namespace base | 103 } // namespace base |
OLD | NEW |