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