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