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 #ifndef BASE_TRACE_EVENT_MEMORY_ALLOCATOR_DUMP_H_ | 5 #ifndef BASE_TRACE_EVENT_MEMORY_ALLOCATOR_DUMP_H_ |
6 #define BASE_TRACE_EVENT_MEMORY_ALLOCATOR_DUMP_H_ | 6 #define BASE_TRACE_EVENT_MEMORY_ALLOCATOR_DUMP_H_ |
7 | 7 |
8 #include "base/base_export.h" | 8 #include "base/base_export.h" |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/values.h" | 11 #include "base/values.h" |
12 | 12 |
13 namespace base { | 13 namespace base { |
14 namespace trace_event { | 14 namespace trace_event { |
15 | 15 |
16 class MemoryDumpManager; | 16 class MemoryDumpManager; |
17 class ProcessMemoryDump; | 17 class ProcessMemoryDump; |
18 class TracedValue; | 18 class TracedValue; |
19 | 19 |
20 // Data model for user-land memory allocator dumps. | 20 // Data model for user-land memory allocator dumps. |
21 class BASE_EXPORT MemoryAllocatorDump { | 21 class BASE_EXPORT MemoryAllocatorDump { |
22 public: | 22 public: |
23 // Returns the absolute name for a given (|allocator_name|,|heap_name|) tuple. | |
24 static std::string GetAbsoluteName(const std::string& allocator_name, | |
25 const std::string& heap_name); | |
26 | |
27 // Use as argument for |heap_name| when the allocator has only one root heap. | |
28 static const char kRootHeap[]; | |
29 | |
30 // MemoryAllocatorDump is owned by ProcessMemoryDump. | 23 // MemoryAllocatorDump is owned by ProcessMemoryDump. |
31 MemoryAllocatorDump(const std::string& allocator_name, | 24 MemoryAllocatorDump(const std::string& absolute_name, |
32 const std::string& heap_name, | |
33 ProcessMemoryDump* process_memory_dump); | 25 ProcessMemoryDump* process_memory_dump); |
34 ~MemoryAllocatorDump(); | 26 ~MemoryAllocatorDump(); |
35 | 27 |
36 // Name of the allocator, a plain string with no separators (e.g, "malloc"). | 28 // Standard attribute name to model total space requested by the allocator |
37 const std::string& allocator_name() const { return allocator_name_; } | 29 // (e.g., amount of pages requested to the system). |
| 30 static const char kNameOuterSize[]; |
38 | 31 |
39 // Name of the heap being dumped, either: "heap", "heap/subheap" or kRootHeap | 32 // Standard attribute name to model space for allocated objects, without |
40 // if the allocator has just one root heap. | 33 // taking into account allocator metadata or fragmentation. |
41 const std::string& heap_name() const { return heap_name_; } | 34 static const char kNameInnerSize[]; |
| 35 |
| 36 // Standard attribute name to model the number of objects allocated. |
| 37 static const char kNameObjectsCount[]; |
| 38 |
| 39 static const char kTypeScalar[]; // Type name for scalar attributes. |
| 40 static const char kTypeString[]; // Type name for string attributes. |
| 41 static const char kUnitsBytes[]; // Unit name to represent bytes. |
| 42 static const char kUnitsObjects[]; // Unit name to represent #objects. |
42 | 43 |
43 // Absolute name, unique within the scope of an entire ProcessMemoryDump. | 44 // Absolute name, unique within the scope of an entire ProcessMemoryDump. |
44 // In practice this is "allocator_name/heap/subheap". | 45 const std::string& absolute_name() const { return absolute_name_; } |
45 std::string GetAbsoluteName() const; | |
46 | 46 |
47 // Inner size: Bytes requested by clients of the allocator, without accounting | 47 // Generic attribute setter / getter. |
48 // for any metadata or allocator-specific bookeeping structs. | 48 void Add(const std::string& name, |
49 void set_allocated_objects_size_in_bytes(uint64 value) { | 49 const char* type, |
50 allocated_objects_size_in_bytes_ = value; | 50 const char* units, |
51 } | 51 scoped_ptr<Value> value); |
52 uint64 allocated_objects_size_in_bytes() const { | 52 bool Get(const std::string& name, |
53 return allocated_objects_size_in_bytes_; | 53 const char** out_type, |
54 } | 54 const char** out_units, |
| 55 const Value** out_value) const; |
55 | 56 |
56 // Outer size: bytes requested to the system to handle all the allocations, | 57 // Helper setter for scalar attributes. |
57 // including any allocator-internal metadata / bookeeping structs. For | 58 void AddScalar(const std::string& name, const char* units, uint64 value); |
58 // instance, in the case of an allocator which gets pages to the system via | 59 void AddString(const std::string& name, |
59 // mmap() or similar, this is the number of requested pages * 4k. | 60 const char* units, |
60 void set_physical_size_in_bytes(uint64 value) { | 61 const std::string& value); |
61 physical_size_in_bytes_ = value; | |
62 } | |
63 uint64 physical_size_in_bytes() const { return physical_size_in_bytes_; } | |
64 | |
65 // Number of objects allocated, if known, or 0 if not available. | |
66 void set_allocated_objects_count(uint64 value) { | |
67 allocated_objects_count_ = value; | |
68 } | |
69 uint64 allocated_objects_count() const { return allocated_objects_count_; } | |
70 | |
71 // Get/Set extra attributes. The attributes name must have been previously | |
72 // declared through MemoryDumpProvider.DeclareAllocatorAttribute(). | |
73 void SetAttribute(const std::string& name, int value); | |
74 int GetIntegerAttribute(const std::string& name) const; | |
75 | 62 |
76 // Called at trace generation time to populate the TracedValue. | 63 // Called at trace generation time to populate the TracedValue. |
77 void AsValueInto(TracedValue* value) const; | 64 void AsValueInto(TracedValue* value) const; |
78 | 65 |
79 // Get the ProcessMemoryDump instance that owns this. | 66 // Get the ProcessMemoryDump instance that owns this. |
80 ProcessMemoryDump* process_memory_dump() const { | 67 ProcessMemoryDump* process_memory_dump() const { |
81 return process_memory_dump_; | 68 return process_memory_dump_; |
82 } | 69 } |
83 | 70 |
84 private: | 71 private: |
85 const std::string allocator_name_; | 72 const std::string absolute_name_; |
86 const std::string heap_name_; | |
87 ProcessMemoryDump* const process_memory_dump_; // Not owned (PMD owns this). | 73 ProcessMemoryDump* const process_memory_dump_; // Not owned (PMD owns this). |
88 uint64 physical_size_in_bytes_; | 74 DictionaryValue attributes_; |
89 uint64 allocated_objects_count_; | |
90 uint64 allocated_objects_size_in_bytes_; | |
91 DictionaryValue attributes_values_; | |
92 | 75 |
93 DISALLOW_COPY_AND_ASSIGN(MemoryAllocatorDump); | 76 DISALLOW_COPY_AND_ASSIGN(MemoryAllocatorDump); |
94 }; | 77 }; |
95 | 78 |
96 } // namespace trace_event | 79 } // namespace trace_event |
97 } // namespace base | 80 } // namespace base |
98 | 81 |
99 #endif // BASE_TRACE_EVENT_MEMORY_ALLOCATOR_DUMP_H_ | 82 #endif // BASE_TRACE_EVENT_MEMORY_ALLOCATOR_DUMP_H_ |
OLD | NEW |