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_PROCESS_MEMORY_DUMP_H_
6 #define BASE_TRACE_EVENT_PROCESS_MEMORY_DUMP_H_
8 #include "base/base_export.h"
9 #include "base/containers/hash_tables.h"
10 #include "base/containers/small_map.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_vector.h"
13 #include "base/trace_event/memory_allocator_dump.h"
14 #include "base/trace_event/memory_dump_session_state.h"
15 #include "base/trace_event/process_memory_maps.h"
16 #include "base/trace_event/process_memory_totals.h"
19 namespace trace_event
{
21 class ConvertableToTraceFormat
;
22 class MemoryDumpManager
;
23 class MemoryDumpSessionState
;
25 // ProcessMemoryDump is as a strongly typed container which enforces the data
26 // model for each memory dump and holds the dumps produced by the
27 // MemoryDumpProvider(s) for a specific process.
28 // At trace generation time (i.e. when AsValue() is called), ProcessMemoryDump
29 // will compose a key-value dictionary of the various dumps obtained at trace
31 class BASE_EXPORT ProcessMemoryDump
{
33 // Maps allocator dumps absolute names (allocator_name/heap/subheap) to
34 // MemoryAllocatorDump instances.
35 using AllocatorDumpsMap
=
36 SmallMap
<hash_map
<std::string
, MemoryAllocatorDump
*>>;
38 ProcessMemoryDump(const scoped_refptr
<MemoryDumpSessionState
>& session_state
);
41 // Called at trace generation time to populate the TracedValue.
42 void AsValueInto(TracedValue
* value
) const;
44 ProcessMemoryTotals
* process_totals() { return &process_totals_
; }
45 bool has_process_totals() const { return has_process_totals_
; }
46 void set_has_process_totals() { has_process_totals_
= true; }
48 ProcessMemoryMaps
* process_mmaps() { return &process_mmaps_
; }
49 bool has_process_mmaps() const { return has_process_mmaps_
; }
50 void set_has_process_mmaps() { has_process_mmaps_
= true; }
52 // Creates a new MemoryAllocatorDump with the given name and returns the
53 // empty object back to the caller.
55 // absolute_name: a name that uniquely identifies allocator dumps produced
56 // by this provider. It is possible to specify nesting by using a
57 // path-like string (e.g., v8/isolate1/heap1, v8/isolate1/heap2).
58 // Leading or trailing slashes are not allowed.
59 // ProcessMemoryDump handles the memory ownership of its MemoryAllocatorDumps.
60 MemoryAllocatorDump
* CreateAllocatorDump(const std::string
& absolute_name
);
62 // Looks up a MemoryAllocatorDump given its allocator and heap names, or
63 // nullptr if not found.
64 MemoryAllocatorDump
* GetAllocatorDump(const std::string
& absolute_name
) const;
66 // Returns the map of the MemoryAllocatorDumps added to this dump.
67 const AllocatorDumpsMap
& allocator_dumps() const { return allocator_dumps_
; }
69 const scoped_refptr
<MemoryDumpSessionState
>& session_state() const {
70 return session_state_
;
74 ProcessMemoryTotals process_totals_
;
75 bool has_process_totals_
;
77 ProcessMemoryMaps process_mmaps_
;
78 bool has_process_mmaps_
;
80 AllocatorDumpsMap allocator_dumps_
;
82 // ProcessMemoryDump handles the memory ownership of all its belongings.
83 ScopedVector
<MemoryAllocatorDump
> allocator_dumps_storage_
;
85 // State shared among all PMDs instances created in a given trace session.
86 scoped_refptr
<MemoryDumpSessionState
> session_state_
;
88 DISALLOW_COPY_AND_ASSIGN(ProcessMemoryDump
);
91 } // namespace trace_event
94 #endif // BASE_TRACE_EVENT_PROCESS_MEMORY_DUMP_H_