| 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" |
| 11 #include "base/trace_event/process_memory_dump.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 const char MemoryAllocatorDump::kNameSize[] = "size"; | 18 const char MemoryAllocatorDump::kNameSize[] = "size"; |
| 19 const char MemoryAllocatorDump::kNameObjectCount[] = "object_count"; | 19 const char MemoryAllocatorDump::kNameObjectCount[] = "object_count"; |
| 20 const char MemoryAllocatorDump::kTypeScalar[] = "scalar"; | 20 const char MemoryAllocatorDump::kTypeScalar[] = "scalar"; |
| 21 const char MemoryAllocatorDump::kTypeString[] = "string"; | 21 const char MemoryAllocatorDump::kTypeString[] = "string"; |
| 22 const char MemoryAllocatorDump::kUnitsBytes[] = "bytes"; | 22 const char MemoryAllocatorDump::kUnitsBytes[] = "bytes"; |
| 23 const char MemoryAllocatorDump::kUnitsObjects[] = "objects"; | 23 const char MemoryAllocatorDump::kUnitsObjects[] = "objects"; |
| 24 | 24 |
| 25 MemoryAllocatorDump::MemoryAllocatorDump(const std::string& absolute_name, | 25 MemoryAllocatorDump::MemoryAllocatorDump(const std::string& absolute_name, |
| 26 ProcessMemoryDump* process_memory_dump, | 26 ProcessMemoryDump* process_memory_dump, |
| 27 const MemoryAllocatorDumpGuid& guid) | 27 const MemoryAllocatorDumpGuid& guid, |
| 28 uint8_t flags) |
| 28 : absolute_name_(absolute_name), | 29 : absolute_name_(absolute_name), |
| 29 process_memory_dump_(process_memory_dump), | 30 process_memory_dump_(process_memory_dump), |
| 30 attributes_(new TracedValue), | 31 attributes_(new TracedValue), |
| 31 guid_(guid) { | 32 guid_(guid), |
| 33 flags_(flags) { |
| 32 // The |absolute_name| cannot be empty. | 34 // The |absolute_name| cannot be empty. |
| 33 DCHECK(!absolute_name.empty()); | 35 DCHECK(!absolute_name.empty()); |
| 34 | 36 |
| 35 // The |absolute_name| can contain slash separator, but not leading or | 37 // The |absolute_name| can contain slash separator, but not leading or |
| 36 // trailing ones. | 38 // trailing ones. |
| 37 DCHECK(absolute_name[0] != '/' && *absolute_name.rbegin() != '/'); | 39 DCHECK(absolute_name[0] != '/' && *absolute_name.rbegin() != '/'); |
| 38 } | 40 } |
| 39 | 41 |
| 42 MemoryAllocatorDump::MemoryAllocatorDump(const std::string& absolute_name, |
| 43 ProcessMemoryDump* process_memory_dump, |
| 44 const MemoryAllocatorDumpGuid& guid) |
| 45 : MemoryAllocatorDump(absolute_name, |
| 46 process_memory_dump, |
| 47 guid, |
| 48 0 /* flags */) {} |
| 49 |
| 40 // If the caller didn't provide a guid, make one up by hashing the | 50 // If the caller didn't provide a guid, make one up by hashing the |
| 41 // absolute_name with the current PID. | 51 // absolute_name with the current PID. |
| 42 // Rationale: |absolute_name| is already supposed to be unique within a | 52 // Rationale: |absolute_name| is already supposed to be unique within a |
| 43 // process, the pid will make it unique among all processes. | 53 // process, the pid will make it unique among all processes. |
| 44 MemoryAllocatorDump::MemoryAllocatorDump(const std::string& absolute_name, | 54 MemoryAllocatorDump::MemoryAllocatorDump(const std::string& absolute_name, |
| 45 ProcessMemoryDump* process_memory_dump) | 55 ProcessMemoryDump* process_memory_dump) |
| 46 : MemoryAllocatorDump(absolute_name, | 56 : MemoryAllocatorDump(absolute_name, |
| 47 process_memory_dump, | 57 process_memory_dump, |
| 48 MemoryAllocatorDumpGuid(StringPrintf( | 58 MemoryAllocatorDumpGuid(StringPrintf( |
| 49 "%d:%s", | 59 "%d:%s", |
| 50 TraceLog::GetInstance()->process_id(), | 60 TraceLog::GetInstance()->process_id(), |
| 51 absolute_name.c_str()))) { | 61 absolute_name.c_str())), |
| 62 0 /* flags */) { |
| 52 string_conversion_buffer_.reserve(16); | 63 string_conversion_buffer_.reserve(16); |
| 53 } | 64 } |
| 54 | 65 |
| 55 MemoryAllocatorDump::~MemoryAllocatorDump() { | 66 MemoryAllocatorDump::~MemoryAllocatorDump() { |
| 56 } | 67 } |
| 57 | 68 |
| 58 void MemoryAllocatorDump::AddScalar(const char* name, | 69 void MemoryAllocatorDump::AddScalar(const char* name, |
| 59 const char* units, | 70 const char* units, |
| 60 uint64_t value) { | 71 uint64_t value) { |
| 61 SStringPrintf(&string_conversion_buffer_, "%" PRIx64, value); | 72 SStringPrintf(&string_conversion_buffer_, "%" PRIx64, value); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 83 attributes_->SetString("type", kTypeString); | 94 attributes_->SetString("type", kTypeString); |
| 84 attributes_->SetString("units", units); | 95 attributes_->SetString("units", units); |
| 85 attributes_->SetString("value", value); | 96 attributes_->SetString("value", value); |
| 86 attributes_->EndDictionary(); | 97 attributes_->EndDictionary(); |
| 87 } | 98 } |
| 88 | 99 |
| 89 void MemoryAllocatorDump::AsValueInto(TracedValue* value) const { | 100 void MemoryAllocatorDump::AsValueInto(TracedValue* value) const { |
| 90 value->BeginDictionaryWithCopiedName(absolute_name_); | 101 value->BeginDictionaryWithCopiedName(absolute_name_); |
| 91 value->SetString("guid", guid_.ToString()); | 102 value->SetString("guid", guid_.ToString()); |
| 92 value->SetValue("attrs", *attributes_); | 103 value->SetValue("attrs", *attributes_); |
| 104 if (flags_) |
| 105 value->SetInteger("flags", static_cast<int>(flags_)); |
| 93 value->EndDictionary(); // "allocator_name/heap_subheap": { ... } | 106 value->EndDictionary(); // "allocator_name/heap_subheap": { ... } |
| 94 } | 107 } |
| 95 | 108 |
| 96 } // namespace trace_event | 109 } // namespace trace_event |
| 97 } // namespace base | 110 } // namespace base |
| OLD | NEW |