OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "services/resource_coordinator/memory/coordinator/coordinator_impl.h" | 5 #include "services/resource_coordinator/memory/coordinator/coordinator_impl.h" |
6 | 6 |
| 7 #include "base/bind.h" |
7 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
8 #include "base/lazy_instance.h" | |
9 #include "base/location.h" | 9 #include "base/location.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "base/threading/thread_task_runner_handle.h" | 12 #include "base/single_thread_task_runner.h" |
| 13 #include "base/threading/platform_thread.h" |
13 #include "base/trace_event/memory_dump_manager.h" | 14 #include "base/trace_event/memory_dump_manager.h" |
14 #include "base/trace_event/memory_dump_request_args.h" | 15 #include "base/trace_event/memory_dump_request_args.h" |
| 16 #include "services/resource_coordinator/public/cpp/memory/memory_dump_manager_de
legate_impl.h" |
| 17 #include "services/resource_coordinator/public/interfaces/memory/constants.mojom
.h" |
15 #include "services/resource_coordinator/public/interfaces/memory/memory_instrume
ntation.mojom.h" | 18 #include "services/resource_coordinator/public/interfaces/memory/memory_instrume
ntation.mojom.h" |
16 | 19 |
| 20 namespace { |
| 21 |
| 22 memory_instrumentation::CoordinatorImpl* g_coordinator_impl; |
| 23 |
| 24 } // namespace |
| 25 |
17 namespace memory_instrumentation { | 26 namespace memory_instrumentation { |
18 | 27 |
19 namespace { | |
20 | |
21 base::LazyInstance<CoordinatorImpl>::Leaky g_coordinator = | |
22 LAZY_INSTANCE_INITIALIZER; | |
23 | |
24 } // namespace | |
25 | |
26 // static | 28 // static |
27 CoordinatorImpl* CoordinatorImpl::GetInstance() { | 29 CoordinatorImpl* CoordinatorImpl::GetInstance() { |
28 return g_coordinator.Pointer(); | 30 return g_coordinator_impl; |
29 } | 31 } |
30 | 32 |
31 // TODO(chiniforooshan): Initialize the global MemoryDumpManager instance here. | 33 CoordinatorImpl::CoordinatorImpl(bool initialize_memory_dump_manager) |
32 // This is how the global MemoryDumpManager gets a reference to the delegate on | 34 : failed_memory_dump_count_(0), |
33 // the service (read the browser) process for service process memory dumps. This | 35 initialize_memory_dump_manager_(initialize_memory_dump_manager) { |
34 // can be done when the delegate implementation is landed. | 36 if (initialize_memory_dump_manager) { |
35 CoordinatorImpl::CoordinatorImpl() : failed_memory_dump_count_(0) {} | 37 MemoryDumpManagerDelegateImpl::Config config(this); |
| 38 auto delegate = base::MakeUnique<MemoryDumpManagerDelegateImpl>(config); |
| 39 base::trace_event::MemoryDumpManager::GetInstance()->set_tracing_process_id( |
| 40 mojom::kServiceTracingProcessId); |
| 41 base::trace_event::MemoryDumpManager::GetInstance()->Initialize( |
| 42 std::move(delegate)); |
| 43 } |
| 44 g_coordinator_impl = this; |
| 45 } |
36 | 46 |
37 CoordinatorImpl::~CoordinatorImpl() {} | 47 CoordinatorImpl::~CoordinatorImpl() { |
| 48 g_coordinator_impl = nullptr; |
| 49 } |
38 | 50 |
39 void CoordinatorImpl::BindCoordinatorRequest( | 51 void CoordinatorImpl::BindCoordinatorRequest( |
40 mojom::CoordinatorRequest request) { | 52 mojom::CoordinatorRequest request) { |
| 53 DCHECK(thread_checker_.CalledOnValidThread()); |
41 bindings_.AddBinding(this, std::move(request)); | 54 bindings_.AddBinding(this, std::move(request)); |
42 } | 55 } |
43 | 56 |
44 CoordinatorImpl::QueuedMemoryDumpRequest::QueuedMemoryDumpRequest( | 57 CoordinatorImpl::QueuedMemoryDumpRequest::QueuedMemoryDumpRequest( |
45 const base::trace_event::MemoryDumpRequestArgs args, | 58 const base::trace_event::MemoryDumpRequestArgs args, |
46 const RequestGlobalMemoryDumpCallback callback) | 59 const RequestGlobalMemoryDumpCallback callback) |
47 : args(args), callback(callback) {} | 60 : args(args), callback(callback) {} |
48 | 61 |
49 CoordinatorImpl::QueuedMemoryDumpRequest::~QueuedMemoryDumpRequest() {} | 62 CoordinatorImpl::QueuedMemoryDumpRequest::~QueuedMemoryDumpRequest() {} |
50 | 63 |
51 void CoordinatorImpl::RequestGlobalMemoryDump( | 64 void CoordinatorImpl::RequestGlobalMemoryDump( |
52 const base::trace_event::MemoryDumpRequestArgs& args, | 65 const base::trace_event::MemoryDumpRequestArgs& args, |
53 const RequestGlobalMemoryDumpCallback& callback) { | 66 const RequestGlobalMemoryDumpCallback& callback) { |
54 DCHECK(thread_checker_.CalledOnValidThread()); | 67 DCHECK(thread_checker_.CalledOnValidThread()); |
55 | |
56 bool another_dump_already_in_progress = !queued_memory_dump_requests_.empty(); | 68 bool another_dump_already_in_progress = !queued_memory_dump_requests_.empty(); |
57 | 69 |
58 // If this is a periodic or peak memory dump request and there already is | 70 // If this is a periodic or peak memory dump request and there already is |
59 // another request in the queue with the same level of detail, there's no | 71 // another request in the queue with the same level of detail, there's no |
60 // point in enqueuing this request. | 72 // point in enqueuing this request. |
61 if (another_dump_already_in_progress && | 73 if (another_dump_already_in_progress && |
62 args.dump_type != | 74 args.dump_type != |
63 base::trace_event::MemoryDumpType::EXPLICITLY_TRIGGERED) { | 75 base::trace_event::MemoryDumpType::EXPLICITLY_TRIGGERED) { |
64 for (const auto& request : queued_memory_dump_requests_) { | 76 for (const auto& request : queued_memory_dump_requests_) { |
65 if (request.args.level_of_detail == args.level_of_detail) { | 77 if (request.args.level_of_detail == args.level_of_detail) { |
(...skipping 16 matching lines...) Expand all Loading... |
82 // scheduled when the other dump finishes. | 94 // scheduled when the other dump finishes. |
83 if (another_dump_already_in_progress) | 95 if (another_dump_already_in_progress) |
84 return; | 96 return; |
85 | 97 |
86 PerformNextQueuedGlobalMemoryDump(); | 98 PerformNextQueuedGlobalMemoryDump(); |
87 } | 99 } |
88 | 100 |
89 void CoordinatorImpl::RegisterProcessLocalDumpManager( | 101 void CoordinatorImpl::RegisterProcessLocalDumpManager( |
90 mojom::ProcessLocalDumpManagerPtr process_manager) { | 102 mojom::ProcessLocalDumpManagerPtr process_manager) { |
91 DCHECK(thread_checker_.CalledOnValidThread()); | 103 DCHECK(thread_checker_.CalledOnValidThread()); |
92 | |
93 process_manager.set_connection_error_handler( | 104 process_manager.set_connection_error_handler( |
94 base::Bind(&CoordinatorImpl::UnregisterProcessLocalDumpManager, | 105 base::Bind(&CoordinatorImpl::UnregisterProcessLocalDumpManager, |
95 base::Unretained(this), process_manager.get())); | 106 base::Unretained(this), process_manager.get())); |
96 auto result = process_managers_.insert( | 107 auto result = process_managers_.insert( |
97 std::make_pair<mojom::ProcessLocalDumpManager*, | 108 std::make_pair<mojom::ProcessLocalDumpManager*, |
98 mojom::ProcessLocalDumpManagerPtr>( | 109 mojom::ProcessLocalDumpManagerPtr>( |
99 process_manager.get(), std::move(process_manager))); | 110 process_manager.get(), std::move(process_manager))); |
100 DCHECK(result.second); | 111 DCHECK(result.second); |
101 } | 112 } |
102 | 113 |
103 void CoordinatorImpl::UnregisterProcessLocalDumpManager( | 114 void CoordinatorImpl::UnregisterProcessLocalDumpManager( |
104 mojom::ProcessLocalDumpManager* process_manager) { | 115 mojom::ProcessLocalDumpManager* process_manager) { |
105 DCHECK(process_managers_.erase(process_manager) == 1); | 116 size_t num_deleted = process_managers_.erase(process_manager); |
| 117 DCHECK(num_deleted == 1); |
106 | 118 |
107 // Check if we are waiting for an ack from this process-local manager. | 119 // Check if we are waiting for an ack from this process-local manager. |
108 if (pending_process_managers_.find(process_manager) != | 120 if (pending_process_managers_.find(process_manager) != |
109 pending_process_managers_.end()) { | 121 pending_process_managers_.end()) { |
110 DCHECK(!queued_memory_dump_requests_.empty()); | 122 DCHECK(!queued_memory_dump_requests_.empty()); |
111 OnProcessMemoryDumpResponse( | 123 OnProcessMemoryDumpResponse( |
112 process_manager, queued_memory_dump_requests_.front().args.dump_guid, | 124 process_manager, queued_memory_dump_requests_.front().args.dump_guid, |
113 false /* success */); | 125 false /* success */); |
114 } | 126 } |
115 } | 127 } |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 // Schedule the next queued dump (if applicable). | 184 // Schedule the next queued dump (if applicable). |
173 if (!queued_memory_dump_requests_.empty()) { | 185 if (!queued_memory_dump_requests_.empty()) { |
174 base::ThreadTaskRunnerHandle::Get()->PostTask( | 186 base::ThreadTaskRunnerHandle::Get()->PostTask( |
175 FROM_HERE, | 187 FROM_HERE, |
176 base::Bind(&CoordinatorImpl::PerformNextQueuedGlobalMemoryDump, | 188 base::Bind(&CoordinatorImpl::PerformNextQueuedGlobalMemoryDump, |
177 base::Unretained(this))); | 189 base::Unretained(this))); |
178 } | 190 } |
179 } | 191 } |
180 | 192 |
181 } // namespace memory_instrumentation | 193 } // namespace memory_instrumentation |
OLD | NEW |