| 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 WebProcessMemoryDumpImpl_h | |
| 6 #define WebProcessMemoryDumpImpl_h | |
| 7 | |
| 8 #include "base/gtest_prod_util.h" | |
| 9 #include "base/macros.h" | |
| 10 #include "base/trace_event/memory_dump_request_args.h" | |
| 11 #include "platform/WebProcessMemoryDump.h" | |
| 12 #include "wtf/HashMap.h" | |
| 13 #include "wtf/OwnPtr.h" | |
| 14 | |
| 15 #include <map> | |
| 16 #include <memory> | |
| 17 #include <vector> | |
| 18 | |
| 19 namespace base { | |
| 20 class DiscardableMemory; | |
| 21 namespace trace_event { | |
| 22 class MemoryAllocatorDump; | |
| 23 class ProcessMemoryDump; | |
| 24 } // namespace base | |
| 25 } // namespace trace_event | |
| 26 | |
| 27 namespace skia { | |
| 28 class SkiaTraceMemoryDumpImpl; | |
| 29 } // namespace skia | |
| 30 | |
| 31 namespace blink { | |
| 32 | |
| 33 class WebMemoryAllocatorDumpImpl; | |
| 34 | |
| 35 // Implements the blink::WebProcessMemoryDump interface by means of proxying the | |
| 36 // calls to createMemoryAllocatorDump() to the underlying | |
| 37 // base::trace_event::ProcessMemoryDump instance. | |
| 38 class PLATFORM_EXPORT WebProcessMemoryDumpImpl final | |
| 39 : public NON_EXPORTED_BASE(blink::WebProcessMemoryDump) { | |
| 40 public: | |
| 41 // Creates a standalone WebProcessMemoryDumpImp, which owns the underlying | |
| 42 // ProcessMemoryDump. | |
| 43 WebProcessMemoryDumpImpl(); | |
| 44 | |
| 45 // Wraps (without owning) an existing ProcessMemoryDump. | |
| 46 explicit WebProcessMemoryDumpImpl( | |
| 47 base::trace_event::MemoryDumpLevelOfDetail level_of_detail, | |
| 48 base::trace_event::ProcessMemoryDump* process_memory_dump); | |
| 49 | |
| 50 ~WebProcessMemoryDumpImpl() override; | |
| 51 | |
| 52 // blink::WebProcessMemoryDump implementation. | |
| 53 blink::WebMemoryAllocatorDump* createMemoryAllocatorDump( | |
| 54 const blink::WebString& absolute_name) override; | |
| 55 blink::WebMemoryAllocatorDump* createMemoryAllocatorDump( | |
| 56 const blink::WebString& absolute_name, | |
| 57 blink::WebMemoryAllocatorDumpGuid guid) override; | |
| 58 blink::WebMemoryAllocatorDump* getMemoryAllocatorDump( | |
| 59 const blink::WebString& absolute_name) const override; | |
| 60 void clear() override; | |
| 61 void takeAllDumpsFrom(blink::WebProcessMemoryDump* other) override; | |
| 62 void addOwnershipEdge(blink::WebMemoryAllocatorDumpGuid source, | |
| 63 blink::WebMemoryAllocatorDumpGuid target, | |
| 64 int importance) override; | |
| 65 void addOwnershipEdge(blink::WebMemoryAllocatorDumpGuid source, | |
| 66 blink::WebMemoryAllocatorDumpGuid target) override; | |
| 67 void addSuballocation(blink::WebMemoryAllocatorDumpGuid source, | |
| 68 const blink::WebString& target_node_name) override; | |
| 69 SkTraceMemoryDump* createDumpAdapterForSkia( | |
| 70 const blink::WebString& dump_name_prefix) override; | |
| 71 | |
| 72 const base::trace_event::ProcessMemoryDump* process_memory_dump() const { | |
| 73 return process_memory_dump_; | |
| 74 } | |
| 75 | |
| 76 blink::WebMemoryAllocatorDump* createDiscardableMemoryAllocatorDump( | |
| 77 const std::string& name, | |
| 78 base::DiscardableMemory* discardable) override; | |
| 79 | |
| 80 void dumpHeapUsage( | |
| 81 const base::hash_map<base::trace_event::AllocationContext, base::trace_eve
nt::AllocationMetrics>& | |
| 82 metrics_by_context, | |
| 83 base::trace_event::TraceEventMemoryOverhead& overhead, | |
| 84 const char* allocator_name) override; | |
| 85 | |
| 86 private: | |
| 87 FRIEND_TEST_ALL_PREFIXES(WebProcessMemoryDumpImplTest, IntegrationTest); | |
| 88 | |
| 89 blink::WebMemoryAllocatorDump* createWebMemoryAllocatorDump( | |
| 90 base::trace_event::MemoryAllocatorDump* memory_allocator_dump); | |
| 91 | |
| 92 // Only for the case of ProcessMemoryDump being owned (i.e. the default ctor). | |
| 93 std::unique_ptr<base::trace_event::ProcessMemoryDump> owned_process_memory_dum
p_; | |
| 94 | |
| 95 // The underlying ProcessMemoryDump instance to which the | |
| 96 // createMemoryAllocatorDump() calls will be proxied to. | |
| 97 base::trace_event::ProcessMemoryDump* process_memory_dump_; // Not owned. | |
| 98 | |
| 99 // TODO(ssid): Remove it once this information is added to ProcessMemoryDump. | |
| 100 base::trace_event::MemoryDumpLevelOfDetail level_of_detail_; | |
| 101 | |
| 102 // Reverse index of MemoryAllocatorDump -> WebMemoryAllocatorDumpImpl wrapper. | |
| 103 // By design WebMemoryDumpProvider(s) are not supposed to hold the pointer | |
| 104 // to the WebProcessMemoryDump passed as argument of the onMemoryDump() call. | |
| 105 // Those pointers are valid only within the scope of the call and can be | |
| 106 // safely torn down once the WebProcessMemoryDumpImpl itself is destroyed. | |
| 107 HashMap<base::trace_event::MemoryAllocatorDump*, | |
| 108 OwnPtr<WebMemoryAllocatorDumpImpl>> memory_allocator_dumps_; | |
| 109 | |
| 110 // Stores SkTraceMemoryDump for the current ProcessMemoryDump. | |
| 111 std::vector<std::unique_ptr<skia::SkiaTraceMemoryDumpImpl>> sk_trace_dump_list
_; | |
| 112 | |
| 113 DISALLOW_COPY_AND_ASSIGN(WebProcessMemoryDumpImpl); | |
| 114 }; | |
| 115 | |
| 116 } // namespace blink | |
| 117 | |
| 118 #endif // WebProcessMemoryDumpImpl_h | |
| OLD | NEW |