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 |
60 uint64_t MemoryAllocatorDump::GetSize() { | |
61 return size_; | |
62 } | |
63 | |
59 void MemoryAllocatorDump::AddScalar(const char* name, | 64 void MemoryAllocatorDump::AddScalar(const char* name, |
60 const char* units, | 65 const char* units, |
61 uint64_t value) { | 66 uint64_t value) { |
67 if (strcmp(kNameSize, name) == 0) { | |
Primiano Tucci (use gerrit)
2017/03/23 15:50:49
nit: for consistency with the rest of the code in
hjd
2017/03/23 16:16:39
Done.
| |
68 size_ = value; | |
69 } | |
62 SStringPrintf(&string_conversion_buffer_, "%" PRIx64, value); | 70 SStringPrintf(&string_conversion_buffer_, "%" PRIx64, value); |
63 attributes_->BeginDictionary(name); | 71 attributes_->BeginDictionary(name); |
64 attributes_->SetString("type", kTypeScalar); | 72 attributes_->SetString("type", kTypeScalar); |
65 attributes_->SetString("units", units); | 73 attributes_->SetString("units", units); |
66 attributes_->SetString("value", string_conversion_buffer_); | 74 attributes_->SetString("value", string_conversion_buffer_); |
67 attributes_->EndDictionary(); | 75 attributes_->EndDictionary(); |
68 } | 76 } |
69 | 77 |
70 void MemoryAllocatorDump::AddScalarF(const char* name, | 78 void MemoryAllocatorDump::AddScalarF(const char* name, |
71 const char* units, | 79 const char* units, |
(...skipping 26 matching lines...) Expand all Loading... | |
98 value->BeginDictionaryWithCopiedName(absolute_name_); | 106 value->BeginDictionaryWithCopiedName(absolute_name_); |
99 value->SetString("guid", guid_.ToString()); | 107 value->SetString("guid", guid_.ToString()); |
100 value->SetValue("attrs", *attributes_); | 108 value->SetValue("attrs", *attributes_); |
101 if (flags_) | 109 if (flags_) |
102 value->SetInteger("flags", flags_); | 110 value->SetInteger("flags", flags_); |
103 value->EndDictionary(); // "allocator_name/heap_subheap": { ... } | 111 value->EndDictionary(); // "allocator_name/heap_subheap": { ... } |
104 } | 112 } |
105 | 113 |
106 } // namespace trace_event | 114 } // namespace trace_event |
107 } // namespace base | 115 } // namespace base |
OLD | NEW |