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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 int value = -1; | 67 int value = -1; |
68 bool res = attributes_values_.GetInteger(name, &value); | 68 bool res = attributes_values_.GetInteger(name, &value); |
69 DCHECK(res) << "Attribute '" << name << "' not found"; | 69 DCHECK(res) << "Attribute '" << name << "' not found"; |
70 return value; | 70 return value; |
71 } | 71 } |
72 | 72 |
73 void MemoryAllocatorDump::AsValueInto(TracedValue* value) const { | 73 void MemoryAllocatorDump::AsValueInto(TracedValue* value) const { |
74 static const char kHexFmt[] = "%" PRIx64; | 74 static const char kHexFmt[] = "%" PRIx64; |
75 | 75 |
76 value->BeginDictionary(GetAbsoluteName().c_str()); | 76 value->BeginDictionary(GetAbsoluteName().c_str()); |
| 77 value->BeginDictionary("attrs"); |
77 | 78 |
78 value->SetString("physical_size_in_bytes", | 79 // TODO(primiano): these hard-coded types are temporary to transition to the |
79 StringPrintf(kHexFmt, physical_size_in_bytes_)); | 80 // new generalized attribute format. This code will be refactored by the end |
80 value->SetString("allocated_objects_count", | 81 // of May 2015. |
81 StringPrintf(kHexFmt, allocated_objects_count_)); | 82 value->BeginDictionary("outer_size"); |
82 value->SetString("allocated_objects_size_in_bytes", | 83 value->SetString("type", "scalar"); |
| 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", |
83 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(); |
84 | 100 |
85 // Copy all the extra attributes. | 101 // Copy all the extra attributes. |
86 value->BeginDictionary("args"); | |
87 for (DictionaryValue::Iterator it(attributes_values_); !it.IsAtEnd(); | 102 for (DictionaryValue::Iterator it(attributes_values_); !it.IsAtEnd(); |
88 it.Advance()) { | 103 it.Advance()) { |
89 const std::string& attr_name = it.key(); | 104 const std::string& attr_name = it.key(); |
90 const Value& attr_value = it.value(); | 105 const Value& attr_value = it.value(); |
91 value->BeginDictionary(attr_name.c_str()); | 106 value->BeginDictionary(attr_name.c_str()); |
92 value->SetValue("value", attr_value.DeepCopy()); | 107 value->SetValue("value", attr_value.DeepCopy()); |
93 | 108 |
94 // TODO(primiano): the "type" should be dumped just once, not repeated on | |
95 // on every event. The ability of doing so depends on crbug.com/466121. | |
96 const std::string& attr_type = | 109 const std::string& attr_type = |
97 GetAttributesTypeInfo().Get(allocator_name_, attr_name); | 110 GetAttributesTypeInfo().Get(allocator_name_, attr_name); |
98 DCHECK(!attr_type.empty()); | 111 DCHECK(!attr_type.empty()); |
99 value->SetString("type", attr_type); | 112 value->SetString("type", "scalar"); |
| 113 value->SetString("units", attr_type); |
100 | 114 |
101 value->EndDictionary(); // "arg_name": { "type": "...", "value": "..." } | 115 value->EndDictionary(); // "arg_name": { "type": "...", "value": "..." } |
102 } | 116 } |
103 value->EndDictionary(); // "args": { ... } | |
104 | 117 |
| 118 value->EndDictionary(); // "attrs": { ... } |
105 value->EndDictionary(); // "allocator_name/heap_subheap": { ... } | 119 value->EndDictionary(); // "allocator_name/heap_subheap": { ... } |
106 } | 120 } |
107 | 121 |
108 const MemoryAllocatorAttributesTypeInfo& | 122 const MemoryAllocatorAttributesTypeInfo& |
109 MemoryAllocatorDump::GetAttributesTypeInfo() const { | 123 MemoryAllocatorDump::GetAttributesTypeInfo() const { |
110 return process_memory_dump_->session_state()->allocators_attributes_type_info; | 124 return process_memory_dump_->session_state()->allocators_attributes_type_info; |
111 } | 125 } |
112 | 126 |
113 } // namespace trace_event | 127 } // namespace trace_event |
114 } // namespace base | 128 } // namespace base |
OLD | NEW |