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
3 // found in the LICENSE file.
5 #ifndef BASE_TRACE_EVENT_MEMORY_ALLOCATOR_DUMP_H_
6 #define BASE_TRACE_EVENT_MEMORY_ALLOCATOR_DUMP_H_
8 #include "base/base_export.h"
9 #include "base/basictypes.h"
10 #include "base/logging.h"
11 #include "base/trace_event/memory_allocator_attributes_type_info.h"
12 #include "base/values.h"
15 namespace trace_event
{
17 class MemoryDumpManager
;
18 class ProcessMemoryDump
;
21 // Data model for user-land memory allocator dumps.
22 class BASE_EXPORT MemoryAllocatorDump
{
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
);
28 // Use as argument for |heap_name| when the allocator has only one root heap.
29 static const char kRootHeap
[];
31 // MemoryAllocatorDump is owned by ProcessMemoryDump.
32 MemoryAllocatorDump(const std::string
& allocator_name
,
33 const std::string
& heap_name
,
34 ProcessMemoryDump
* process_memory_dump
);
35 ~MemoryAllocatorDump();
37 // Name of the allocator, a plain string with no separators (e.g, "malloc").
38 const std::string
& allocator_name() const { return allocator_name_
; }
40 // Name of the heap being dumped, either: "heap", "heap/subheap" or kRootHeap
41 // if the allocator has just one root heap.
42 const std::string
& heap_name() const { return heap_name_
; }
44 // Absolute name, unique within the scope of an entire ProcessMemoryDump.
45 // In practice this is "allocator_name/heap/subheap".
46 std::string
GetAbsoluteName() const;
48 // Inner size: Bytes requested by clients of the allocator, without accounting
49 // for any metadata or allocator-specific bookeeping structs.
50 void set_allocated_objects_size_in_bytes(uint64 value
) {
51 allocated_objects_size_in_bytes_
= value
;
53 uint64
allocated_objects_size_in_bytes() const {
54 return allocated_objects_size_in_bytes_
;
57 // Outer size: bytes requested to the system to handle all the allocations,
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
;
64 uint64
physical_size_in_bytes() const { return physical_size_in_bytes_
; }
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
;
70 uint64
allocated_objects_count() const { return allocated_objects_count_
; }
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;
77 // Called at trace generation time to populate the TracedValue.
78 void AsValueInto(TracedValue
* value
) const;
80 // Get the ProcessMemoryDump instance that owns this.
81 ProcessMemoryDump
* process_memory_dump() const {
82 return process_memory_dump_
;
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;
90 const std::string allocator_name_
;
91 const std::string heap_name_
;
92 ProcessMemoryDump
* const process_memory_dump_
; // Not owned (PMD owns this).
93 uint64 physical_size_in_bytes_
;
94 uint64 allocated_objects_count_
;
95 uint64 allocated_objects_size_in_bytes_
;
96 DictionaryValue attributes_values_
;
98 DISALLOW_COPY_AND_ASSIGN(MemoryAllocatorDump
);
101 } // namespace trace_event
104 #endif // BASE_TRACE_EVENT_MEMORY_ALLOCATOR_DUMP_H_