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

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

Issue 1106943002: [tracing] Fix JSON format for memory allocator dumps. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkcr
Patch Set: Created 5 years, 8 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_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
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 May 2015.
petrcermak 2015/04/27 14:22:14 nit: "by May 2015" is ambiguous. Do you mean "by t
Primiano Tucci (use gerrit) 2015/04/27 15:03:18 Done.
80 value->SetString("allocated_objects_count", 81 value->BeginDictionary("outer_size");
81 StringPrintf(kHexFmt, allocated_objects_count_)); 82 value->SetString("type", "scalar");
82 value->SetString("allocated_objects_size_in_bytes", 83 value->SetString("units", "bytes");
84 value->SetString("value", StringPrintf(kHexFmt, physical_size_in_bytes_));
85 value->EndDictionary();
86
87 value->BeginDictionary("inner_size");
88 value->SetString("type", "scalar");
89 value->SetString("units", "bytes");
90 value->SetString("value",
83 StringPrintf(kHexFmt, allocated_objects_size_in_bytes_)); 91 StringPrintf(kHexFmt, allocated_objects_size_in_bytes_));
92 value->EndDictionary();
93
94 value->BeginDictionary("objects_count");
95 value->SetString("type", "scalar");
96 value->SetString("units", "objects");
97 value->SetString("value", StringPrintf(kHexFmt, allocated_objects_count_));
98 value->EndDictionary();
84 99
85 // Copy all the extra attributes. 100 // Copy all the extra attributes.
86 value->BeginDictionary("args");
87 for (DictionaryValue::Iterator it(attributes_values_); !it.IsAtEnd(); 101 for (DictionaryValue::Iterator it(attributes_values_); !it.IsAtEnd();
88 it.Advance()) { 102 it.Advance()) {
89 const std::string& attr_name = it.key(); 103 const std::string& attr_name = it.key();
90 const Value& attr_value = it.value(); 104 const Value& attr_value = it.value();
91 value->BeginDictionary(attr_name.c_str()); 105 value->BeginDictionary(attr_name.c_str());
92 value->SetValue("value", attr_value.DeepCopy()); 106 value->SetValue("value", attr_value.DeepCopy());
93 107
94 // TODO(primiano): the "type" should be dumped just once, not repeated on 108 // 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. 109 // on every event. The ability of doing so depends on crbug.com/466121.
petrcermak 2015/04/27 14:22:14 We're doing this any more - types will be dumped e
Primiano Tucci (use gerrit) 2015/04/27 15:03:18 Done.
96 const std::string& attr_type = 110 const std::string& attr_type =
97 GetAttributesTypeInfo().Get(allocator_name_, attr_name); 111 GetAttributesTypeInfo().Get(allocator_name_, attr_name);
98 DCHECK(!attr_type.empty()); 112 DCHECK(!attr_type.empty());
99 value->SetString("type", attr_type); 113 value->SetString("type", "scalar");
114 value->SetString("units", attr_type);
petrcermak 2015/04/27 14:22:14 Are you forcing all attributes to be scalars now?
Primiano Tucci (use gerrit) 2015/04/27 15:03:18 The latter, all this function is to be refactored.
100 115
101 value->EndDictionary(); // "arg_name": { "type": "...", "value": "..." } 116 value->EndDictionary(); // "arg_name": { "type": "...", "value": "..." }
102 } 117 }
103 value->EndDictionary(); // "args": { ... }
104 118
119 value->EndDictionary(); // "attrs": { ... }
105 value->EndDictionary(); // "allocator_name/heap_subheap": { ... } 120 value->EndDictionary(); // "allocator_name/heap_subheap": { ... }
106 } 121 }
107 122
108 const MemoryAllocatorAttributesTypeInfo& 123 const MemoryAllocatorAttributesTypeInfo&
109 MemoryAllocatorDump::GetAttributesTypeInfo() const { 124 MemoryAllocatorDump::GetAttributesTypeInfo() const {
110 return process_memory_dump_->session_state()->allocators_attributes_type_info; 125 return process_memory_dump_->session_state()->allocators_attributes_type_info;
111 } 126 }
112 127
113 } // namespace trace_event 128 } // namespace trace_event
114 } // namespace base 129 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698