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

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

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

Powered by Google App Engine
This is Rietveld 408576698