Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(144)

Side by Side Diff: third_party/WebKit/Source/platform/web_process_memory_dump.h

Issue 2028483002: Remove abstract classes for memory dumper (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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.
4
5 #ifndef WebProcessMemoryDump_h
6 #define WebProcessMemoryDump_h
7
8 #include "base/gtest_prod_util.h"
9 #include "base/macros.h"
10 #include "base/trace_event/heap_profiler_allocation_context.h"
11 #include "base/trace_event/memory_dump_request_args.h"
12 #include "platform/PlatformExport.h"
13 #include "platform/web_memory_allocator_dump.h"
14 #include "wtf/HashMap.h"
15 #include "wtf/OwnPtr.h"
16 #include "wtf/text/WTFString.h"
17
18 #include <map>
19 #include <memory>
20 #include <vector>
21
22 class SkTraceMemoryDump;
23
24 namespace base {
25 class DiscardableMemory;
26 namespace trace_event {
27 class MemoryAllocatorDump;
28 class ProcessMemoryDump;
29 class TraceEventMemoryOverhead;
30 } // namespace base
31 } // namespace trace_event
32
33 namespace skia {
34 class SkiaTraceMemoryDumpImpl;
35 } // namespace skia
36
37 namespace blink {
38
39 // Used to specify the type of memory dump the WebProcessMemoryDump should
40 // generate on dump requests.
41 // TODO(hajimehoshi): Remove this and use base::trace_event::
42 // MemoryDumpLevelOfDetail instead.
43 enum class WebMemoryDumpLevelOfDetail {
44 Light,
45 Detailed
46 };
47
48 // A container which holds all the dumps for the various allocators for a given
49 // process. Embedders of WebMemoryDumpProvider are expected to populate a
50 // WebProcessMemoryDump instance with the stats of their allocators.
51 class PLATFORM_EXPORT WebProcessMemoryDump final {
52 public:
53 // Creates a standalone WebProcessMemoryDump, which owns the underlying
54 // ProcessMemoryDump.
55 WebProcessMemoryDump();
56
57 // Wraps (without owning) an existing ProcessMemoryDump.
58 explicit WebProcessMemoryDump(
59 base::trace_event::MemoryDumpLevelOfDetail level_of_detail,
60 base::trace_event::ProcessMemoryDump* process_memory_dump);
61
62 ~WebProcessMemoryDump();
63
64 // Creates a new MemoryAllocatorDump with the given name and returns the
65 // empty object back to the caller. |absoluteName| uniquely identifies the
66 // dump within the scope of a ProcessMemoryDump. It is possible to express
67 // nesting by means of a slash-separated path naming (e.g.,
68 // "allocator_name/arena_1/subheap_X").
69 // |guid| is an optional identifier, unique among all processes within the
70 // scope of a global dump. This is only relevant when using
71 // addOwnershipEdge(). If omitted, it will be automatically generated.
72 blink::WebMemoryAllocatorDump* createMemoryAllocatorDump(
73 const String& absolute_name);
74 blink::WebMemoryAllocatorDump* createMemoryAllocatorDump(
75 const String& absolute_name,
76 blink::WebMemoryAllocatorDumpGuid guid);
77
78 // Gets a previously created MemoryAllocatorDump given its name.
79 blink::WebMemoryAllocatorDump* getMemoryAllocatorDump(
80 const String& absolute_name) const;
81
82 // Removes all the WebMemoryAllocatorDump(s) contained in this instance.
83 // This WebProcessMemoryDump can be safely reused as if it was new once this
84 // method returns.
85 void clear();
86
87 // Merges all WebMemoryAllocatorDump(s) contained in |other| inside this
88 // WebProcessMemoryDump, transferring their ownership to this instance.
89 // |other| will be an empty WebProcessMemoryDump after this method returns
90 // and can be reused as if it was new.
91 void takeAllDumpsFrom(blink::WebProcessMemoryDump* other);
92
93 // Adds an ownership relationship between two MemoryAllocatorDump(s) with
94 // the semantics: |source| owns |target|, and has the effect of attributing
95 // the memory usage of |target| to |source|. |importance| is optional and
96 // relevant only for the cases of co-ownership, where it acts as a z-index:
97 // the owner with the highest importance will be attributed |target|'s
98 // memory.
99 void addOwnershipEdge(blink::WebMemoryAllocatorDumpGuid source,
100 blink::WebMemoryAllocatorDumpGuid target,
101 int importance);
102 void addOwnershipEdge(blink::WebMemoryAllocatorDumpGuid source,
103 blink::WebMemoryAllocatorDumpGuid target);
104
105 // Utility method to add a suballocation relationship with the following
106 // semantics: |source| is suballocated from |target_node_name|.
107 // This creates a child node of |target_node_name| and adds an ownership
108 // edge between |source| and the new child node. As a result, the UI will
109 // not account the memory of |source| in the target node.
110 void addSuballocation(blink::WebMemoryAllocatorDumpGuid source,
111 const String& target_node_name);
112
113 // Returns the SkTraceMemoryDump proxy interface that can be passed to Skia
114 // to dump into this WebProcessMemoryDump. Multiple SkTraceMemoryDump
115 // objects can be created using this method. The created dumpers are owned
116 // by WebProcessMemoryDump and cannot outlive the WebProcessMemoryDump
117 // object owning them. |dumpNamePrefix| is prefix appended to each dump
118 // created by the SkTraceMemoryDump implementation, if the dump should be
119 // placed under different namespace and not "skia".
120 SkTraceMemoryDump* createDumpAdapterForSkia(
121 const String& dump_name_prefix);
122
123 const base::trace_event::ProcessMemoryDump* process_memory_dump() const {
124 return process_memory_dump_;
125 }
126
127 blink::WebMemoryAllocatorDump* createDiscardableMemoryAllocatorDump(
128 const std::string& name,
129 base::DiscardableMemory* discardable);
130
131 // Dumps heap memory usage. |allocatorName| is used as an absolute name for
132 // base::trace_event::ProcessMemoryDump::DumpHeapUsage().
133 void dumpHeapUsage(
134 const base::hash_map<base::trace_event::AllocationContext, base::trace_eve nt::AllocationMetrics>&
135 metrics_by_context,
136 base::trace_event::TraceEventMemoryOverhead& overhead,
137 const char* allocator_name);
138
139 private:
140 FRIEND_TEST_ALL_PREFIXES(WebProcessMemoryDumpTest, IntegrationTest);
141
142 blink::WebMemoryAllocatorDump* createWebMemoryAllocatorDump(
143 base::trace_event::MemoryAllocatorDump* memory_allocator_dump);
144
145 // Only for the case of ProcessMemoryDump being owned (i.e. the default ctor).
146 std::unique_ptr<base::trace_event::ProcessMemoryDump> owned_process_memory_dum p_;
147
148 // The underlying ProcessMemoryDump instance to which the
149 // createMemoryAllocatorDump() calls will be proxied to.
150 base::trace_event::ProcessMemoryDump* process_memory_dump_; // Not owned.
151
152 // TODO(ssid): Remove it once this information is added to ProcessMemoryDump.
153 base::trace_event::MemoryDumpLevelOfDetail level_of_detail_;
154
155 // Reverse index of MemoryAllocatorDump -> WebMemoryAllocatorDump wrapper.
156 // By design WebMemoryDumpProvider(s) are not supposed to hold the pointer
157 // to the WebProcessMemoryDump passed as argument of the onMemoryDump() call.
158 // Those pointers are valid only within the scope of the call and can be
159 // safely torn down once the WebProcessMemoryDump itself is destroyed.
160 HashMap<base::trace_event::MemoryAllocatorDump*,
161 OwnPtr<WebMemoryAllocatorDump>> memory_allocator_dumps_;
162
163 // Stores SkTraceMemoryDump for the current ProcessMemoryDump.
164 std::vector<std::unique_ptr<skia::SkiaTraceMemoryDumpImpl>> sk_trace_dump_list _;
165
166 DISALLOW_COPY_AND_ASSIGN(WebProcessMemoryDump);
167 };
168
169 } // namespace blink
170
171 #endif // WebProcessMemoryDump_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698