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.h" | 11 #include "base/trace_event/memory_allocator_attributes_type_info.h" |
12 #include "base/values.h" | 12 #include "base/values.h" |
13 | 13 |
14 namespace base { | 14 namespace base { |
15 namespace trace_event { | 15 namespace trace_event { |
16 | 16 |
17 class MemoryDumpManager; | 17 class MemoryDumpManager; |
| 18 class ProcessMemoryDump; |
18 class TracedValue; | 19 class TracedValue; |
19 | 20 |
20 // Data model for user-land memory allocator dumps. | 21 // Data model for user-land memory allocator dumps. |
21 class BASE_EXPORT MemoryAllocatorDump { | 22 class BASE_EXPORT MemoryAllocatorDump { |
22 public: | 23 public: |
23 MemoryAllocatorDump(const std::string& name, MemoryAllocatorDump* parent); | 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. |
| 32 MemoryAllocatorDump(const std::string& allocator_name, |
| 33 const std::string& heap_name, |
| 34 ProcessMemoryDump* process_memory_dump); |
24 ~MemoryAllocatorDump(); | 35 ~MemoryAllocatorDump(); |
25 | 36 |
26 const std::string& name() const { return name_; } | 37 // Name of the allocator, a plain string with no separators (e.g, "malloc"). |
27 const MemoryAllocatorDump* parent() const { return parent_; } | 38 const std::string& allocator_name() const { return allocator_name_; } |
28 | 39 |
29 void set_physical_size_in_bytes(uint64 value) { | 40 // Name of the heap being dumped, either: "heap", "heap/subheap" or kRootHeap |
30 physical_size_in_bytes_ = value; | 41 // if the allocator has just one root heap. |
31 } | 42 const std::string& heap_name() const { return heap_name_; } |
32 uint64 physical_size_in_bytes() const { return physical_size_in_bytes_; } | |
33 | 43 |
34 void set_allocated_objects_count(uint64 value) { | 44 // Absolute name, unique within the scope of an entire ProcessMemoryDump. |
35 allocated_objects_count_ = value; | 45 // In practice this is "allocator_name/heap/subheap". |
36 } | 46 std::string GetAbsoluteName() const; |
37 uint64 allocated_objects_count() const { return allocated_objects_count_; } | |
38 | 47 |
| 48 // Inner size: Bytes requested by clients of the allocator, without accounting |
| 49 // for any metadata or allocator-specific bookeeping structs. |
39 void set_allocated_objects_size_in_bytes(uint64 value) { | 50 void set_allocated_objects_size_in_bytes(uint64 value) { |
40 allocated_objects_size_in_bytes_ = value; | 51 allocated_objects_size_in_bytes_ = value; |
41 } | 52 } |
42 uint64 allocated_objects_size_in_bytes() const { | 53 uint64 allocated_objects_size_in_bytes() const { |
43 return allocated_objects_size_in_bytes_; | 54 return allocated_objects_size_in_bytes_; |
44 } | 55 } |
45 | 56 |
46 void SetExtraAttribute(const std::string& name, int value); | 57 // Outer size: bytes requested to the system to handle all the allocations, |
47 int GetExtraIntegerAttribute(const std::string& name) const; | 58 // including any allocator-internal metadata / bookeeping structs. For |
| 59 // instance, in the case of an allocator which gets pages to the system via |
| 60 // mmap() or similar, this is the number of requested pages * 4k. |
| 61 void set_physical_size_in_bytes(uint64 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; |
48 | 76 |
49 // Called at trace generation time to populate the TracedValue. | 77 // Called at trace generation time to populate the TracedValue. |
50 void AsValueInto(TracedValue* value) const; | 78 void AsValueInto(TracedValue* value) const; |
51 | 79 |
| 80 // Get the ProcessMemoryDump instance that owns this. |
| 81 ProcessMemoryDump* process_memory_dump() const { |
| 82 return process_memory_dump_; |
| 83 } |
| 84 |
| 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 |
52 private: | 89 private: |
53 const std::string name_; | 90 const std::string allocator_name_; |
54 MemoryAllocatorDump* const parent_; // Not owned. | 91 const std::string heap_name_; |
| 92 ProcessMemoryDump* const process_memory_dump_; // Not owned (PMD owns this). |
55 uint64 physical_size_in_bytes_; | 93 uint64 physical_size_in_bytes_; |
56 uint64 allocated_objects_count_; | 94 uint64 allocated_objects_count_; |
57 uint64 allocated_objects_size_in_bytes_; | 95 uint64 allocated_objects_size_in_bytes_; |
58 DictionaryValue extra_attributes_; | 96 DictionaryValue attributes_values_; |
59 | 97 |
60 DISALLOW_COPY_AND_ASSIGN(MemoryAllocatorDump); | 98 DISALLOW_COPY_AND_ASSIGN(MemoryAllocatorDump); |
61 }; | 99 }; |
62 | 100 |
63 } // namespace trace_event | 101 } // namespace trace_event |
64 } // namespace base | 102 } // namespace base |
65 | 103 |
66 #endif // BASE_TRACE_EVENT_MEMORY_ALLOCATOR_DUMP_H_ | 104 #endif // BASE_TRACE_EVENT_MEMORY_ALLOCATOR_DUMP_H_ |
OLD | NEW |