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