Chromium Code Reviews| Index: base/trace_event/memory_allocator_dump.cc |
| diff --git a/base/trace_event/memory_allocator_dump.cc b/base/trace_event/memory_allocator_dump.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..035ca2ab4f90f5bb224607dcabe3612f4b551784 |
| --- /dev/null |
| +++ b/base/trace_event/memory_allocator_dump.cc |
| @@ -0,0 +1,79 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "base/trace_event/memory_allocator_dump.h" |
| + |
| +#include "base/format_macros.h" |
| +#include "base/trace_event/memory_allocator_attributes.h" |
| +#include "base/trace_event/memory_dump_manager.h" |
| +#include "base/trace_event/memory_dump_provider.h" |
| +#include "base/trace_event/trace_event_argument.h" |
| +#include "base/values.h" |
| + |
| +namespace base { |
| +namespace trace_event { |
| + |
| +MemoryAllocatorDump::MemoryAllocatorDump(const std::string& name, |
| + MemoryAllocatorDump* parent) |
| + : name_(name), |
| + parent_(parent), |
| + physical_size_in_bytes_(0), |
| + allocated_objects_count_(0), |
| + allocated_objects_size_in_bytes_(0) { |
| +} |
| + |
| +MemoryAllocatorDump::~MemoryAllocatorDump() { |
| +} |
| + |
| +void MemoryAllocatorDump::SetExtraAttribute(const std::string& name, |
| + int value) { |
| + extra_attributes_.SetInteger(name, value); |
| +} |
| + |
| +int MemoryAllocatorDump::GetExtraIntegerAttribute( |
| + const std::string& name) const { |
| + bool res; |
| + int value = -1; |
| + res = extra_attributes_.GetInteger(name, &value); |
| + DCHECK(res) << "Allocator attribute '" << name << "' not found"; |
| + return value; |
| +} |
| + |
| +void MemoryAllocatorDump::AsValueInto(TracedValue* value) const { |
| + value->BeginDictionary(name_.c_str()); |
| + |
| + value->SetString("parent", parent_ ? parent_->name_ : ""); |
| + value->SetInteger("physical_size", physical_size_in_bytes_); |
| + value->SetInteger("allocated_objects_count", allocated_objects_count_); |
| + value->SetInteger("allocated_objects_size", allocated_objects_size_in_bytes_); |
| + |
| + // Copy all the extra attributes. |
| + const MemoryDumpProvider* mdp = |
| + MemoryDumpManager::GetInstance()->dump_provider_currently_active(); |
| + const MemoryAllocatorDeclaredAttributes& extra_attributes_types = |
| + mdp->allocator_attributes(); |
|
picksi
2015/03/16 09:18:06
mdp can bull a nullptr if this is called when a du
Primiano Tucci (use gerrit)
2015/03/16 09:57:17
Usually the rule in chromium is to NOT dcheck for
|
| + |
| + value->BeginDictionary("args"); |
| + for (DictionaryValue::Iterator it(extra_attributes_); !it.IsAtEnd(); |
| + it.Advance()) { |
| + const std::string& attr_name = it.key(); |
| + const Value& attr_value = it.value(); |
| + value->BeginDictionary(attr_name.c_str()); |
| + value->SetValue("value", attr_value.DeepCopy()); |
| + |
| + auto attr_it = extra_attributes_types.find(attr_name); |
| + DCHECK(attr_it != extra_attributes_types.end()) |
| + << "Allocator attribute " << attr_name |
| + << " not declared for the dumper " << mdp->GetFriendlyName(); |
| + value->SetString("type", attr_it->second.type); |
| + |
| + value->EndDictionary(); // "arg_name": { "type": "...", "value": "..." } |
| + } |
| + value->EndDictionary(); // "args": {} |
| + |
| + value->EndDictionary(); // "allocator name": {} |
| +} |
| + |
| +} // namespace trace_event |
| +} // namespace base |