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