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/values.h"
14 namespace trace_event
{
16 class MemoryDumpManager
;
17 class ProcessMemoryDump
;
20 // Data model for user-land memory allocator dumps.
21 class BASE_EXPORT MemoryAllocatorDump
{
23 // MemoryAllocatorDump is owned by ProcessMemoryDump.
24 MemoryAllocatorDump(const std::string
& absolute_name
,
25 ProcessMemoryDump
* process_memory_dump
);
26 ~MemoryAllocatorDump();
28 // Standard attribute name to model total space requested by the allocator
29 // (e.g., amount of pages requested to the system).
30 static const char kNameOuterSize
[];
32 // Standard attribute name to model space for allocated objects, without
33 // taking into account allocator metadata or fragmentation.
34 static const char kNameInnerSize
[];
36 // Standard attribute name to model the number of objects allocated.
37 static const char kNameObjectsCount
[];
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.
44 // Absolute name, unique within the scope of an entire ProcessMemoryDump.
45 const std::string
& absolute_name() const { return absolute_name_
; }
47 // Generic attribute setter / getter.
48 void Add(const std::string
& name
,
51 scoped_ptr
<Value
> value
);
52 bool Get(const std::string
& name
,
53 const char** out_type
,
54 const char** out_units
,
55 const Value
** out_value
) const;
57 // Helper setter for scalar attributes.
58 void AddScalar(const std::string
& name
, const char* units
, uint64 value
);
59 void AddString(const std::string
& name
,
61 const std::string
& value
);
63 // Called at trace generation time to populate the TracedValue.
64 void AsValueInto(TracedValue
* value
) const;
66 // Get the ProcessMemoryDump instance that owns this.
67 ProcessMemoryDump
* process_memory_dump() const {
68 return process_memory_dump_
;
72 const std::string absolute_name_
;
73 ProcessMemoryDump
* const process_memory_dump_
; // Not owned (PMD owns this).
74 DictionaryValue attributes_
;
76 DISALLOW_COPY_AND_ASSIGN(MemoryAllocatorDump
);
79 } // namespace trace_event
82 #endif // BASE_TRACE_EVENT_MEMORY_ALLOCATOR_DUMP_H_