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

Side by Side Diff: services/resource_coordinator/memory/coordinator/coordinator_impl.cc

Issue 2734193002: memory-infra: Finish moving to Mojo (2nd attempt) (Closed)
Patch Set: rebase Created 3 years, 9 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
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"
15 #include "services/resource_coordinator/public/interfaces/memory/memory_instrume ntation.mojom.h" 17 #include "services/resource_coordinator/public/interfaces/memory/memory_instrume ntation.mojom.h"
16 18
17 namespace memory_instrumentation { 19 namespace memory_instrumentation {
18 20
19 namespace {
20
21 base::LazyInstance<CoordinatorImpl>::Leaky g_coordinator =
22 LAZY_INSTANCE_INITIALIZER;
23
24 } // namespace
25
26 // static 21 // static
27 CoordinatorImpl* CoordinatorImpl::GetInstance() { 22 CoordinatorImpl* CoordinatorImpl::GetInstance() {
28 return g_coordinator.Pointer(); 23 static CoordinatorImpl* instance = new CoordinatorImpl(true);
24 DCHECK(instance->initialize_memory_dump_manager());
25 return instance;
29 } 26 }
30 27
31 // TODO(chiniforooshan): Initialize the global MemoryDumpManager instance here. 28 CoordinatorImpl::CoordinatorImpl(bool initialize_memory_dump_manager)
32 // This is how the global MemoryDumpManager gets a reference to the delegate on 29 : failed_memory_dump_count_(0),
33 // the service (read the browser) process for service process memory dumps. This 30 initialize_memory_dump_manager_(initialize_memory_dump_manager) {
34 // can be done when the delegate implementation is landed. 31 if (initialize_memory_dump_manager) {
35 CoordinatorImpl::CoordinatorImpl() : failed_memory_dump_count_(0) {} 32 MemoryDumpManagerDelegateImpl::Config config(this);
33 MemoryDumpManagerDelegateImpl::Create(config);
34 }
35 }
36 36
37 CoordinatorImpl::~CoordinatorImpl() {} 37 CoordinatorImpl::~CoordinatorImpl() {}
38 38
39 void CoordinatorImpl::BindCoordinatorRequest( 39 void CoordinatorImpl::BindCoordinatorRequest(
40 mojom::CoordinatorRequest request) { 40 mojom::CoordinatorRequest request) {
41 DCHECK(thread_checker_.CalledOnValidThread());
41 bindings_.AddBinding(this, std::move(request)); 42 bindings_.AddBinding(this, std::move(request));
42 } 43 }
43 44
44 CoordinatorImpl::QueuedMemoryDumpRequest::QueuedMemoryDumpRequest( 45 CoordinatorImpl::QueuedMemoryDumpRequest::QueuedMemoryDumpRequest(
45 const base::trace_event::MemoryDumpRequestArgs args, 46 const base::trace_event::MemoryDumpRequestArgs args,
46 const RequestGlobalMemoryDumpCallback callback) 47 const RequestGlobalMemoryDumpCallback callback)
47 : args(args), callback(callback) {} 48 : args(args), callback(callback) {}
48 49
49 CoordinatorImpl::QueuedMemoryDumpRequest::~QueuedMemoryDumpRequest() {} 50 CoordinatorImpl::QueuedMemoryDumpRequest::~QueuedMemoryDumpRequest() {}
50 51
51 void CoordinatorImpl::RequestGlobalMemoryDump( 52 void CoordinatorImpl::RequestGlobalMemoryDump(
52 const base::trace_event::MemoryDumpRequestArgs& args, 53 const base::trace_event::MemoryDumpRequestArgs& args,
53 const RequestGlobalMemoryDumpCallback& callback) { 54 const RequestGlobalMemoryDumpCallback& callback) {
54 DCHECK(thread_checker_.CalledOnValidThread()); 55 DCHECK(thread_checker_.CalledOnValidThread());
55
56 bool another_dump_already_in_progress = !queued_memory_dump_requests_.empty(); 56 bool another_dump_already_in_progress = !queued_memory_dump_requests_.empty();
57 57
58 // If this is a periodic memory dump request and there already is another 58 // If this is a periodic memory dump request and there already is another
59 // request in the queue with the same level of detail, there's no point in 59 // request in the queue with the same level of detail, there's no point in
60 // enqueuing this request. 60 // enqueuing this request.
61 if (another_dump_already_in_progress && 61 if (another_dump_already_in_progress &&
62 args.dump_type == base::trace_event::MemoryDumpType::PERIODIC_INTERVAL) { 62 args.dump_type == base::trace_event::MemoryDumpType::PERIODIC_INTERVAL) {
63 for (const auto& request : queued_memory_dump_requests_) { 63 for (const auto& request : queued_memory_dump_requests_) {
64 if (request.args.level_of_detail == args.level_of_detail) { 64 if (request.args.level_of_detail == args.level_of_detail) {
65 VLOG(1) << base::trace_event::MemoryDumpManager::kLogPrefix << " (" 65 VLOG(1) << base::trace_event::MemoryDumpManager::kLogPrefix << " ("
(...skipping 15 matching lines...) Expand all
81 // scheduled when the other dump finishes. 81 // scheduled when the other dump finishes.
82 if (another_dump_already_in_progress) 82 if (another_dump_already_in_progress)
83 return; 83 return;
84 84
85 PerformNextQueuedGlobalMemoryDump(); 85 PerformNextQueuedGlobalMemoryDump();
86 } 86 }
87 87
88 void CoordinatorImpl::RegisterProcessLocalDumpManager( 88 void CoordinatorImpl::RegisterProcessLocalDumpManager(
89 mojom::ProcessLocalDumpManagerPtr process_manager) { 89 mojom::ProcessLocalDumpManagerPtr process_manager) {
90 DCHECK(thread_checker_.CalledOnValidThread()); 90 DCHECK(thread_checker_.CalledOnValidThread());
91
92 process_manager.set_connection_error_handler( 91 process_manager.set_connection_error_handler(
93 base::Bind(&CoordinatorImpl::UnregisterProcessLocalDumpManager, 92 base::Bind(&CoordinatorImpl::UnregisterProcessLocalDumpManager,
94 base::Unretained(this), process_manager.get())); 93 base::Unretained(this), process_manager.get()));
95 auto result = process_managers_.insert( 94 auto result = process_managers_.insert(
96 std::make_pair<mojom::ProcessLocalDumpManager*, 95 std::make_pair<mojom::ProcessLocalDumpManager*,
97 mojom::ProcessLocalDumpManagerPtr>( 96 mojom::ProcessLocalDumpManagerPtr>(
98 process_manager.get(), std::move(process_manager))); 97 process_manager.get(), std::move(process_manager)));
99 DCHECK(result.second); 98 DCHECK(result.second);
100 } 99 }
101 100
102 void CoordinatorImpl::UnregisterProcessLocalDumpManager( 101 void CoordinatorImpl::UnregisterProcessLocalDumpManager(
103 mojom::ProcessLocalDumpManager* process_manager) { 102 mojom::ProcessLocalDumpManager* process_manager) {
104 DCHECK(process_managers_.erase(process_manager) == 1); 103 size_t num_deleted = process_managers_.erase(process_manager);
104 DCHECK(num_deleted == 1);
105 105
106 // Check if we are waiting for an ack from this process-local manager. 106 // Check if we are waiting for an ack from this process-local manager.
107 if (pending_process_managers_.find(process_manager) != 107 if (pending_process_managers_.find(process_manager) !=
108 pending_process_managers_.end()) { 108 pending_process_managers_.end()) {
109 DCHECK(!queued_memory_dump_requests_.empty()); 109 DCHECK(!queued_memory_dump_requests_.empty());
110 OnProcessMemoryDumpResponse( 110 OnProcessMemoryDumpResponse(
111 process_manager, queued_memory_dump_requests_.front().args.dump_guid, 111 process_manager, queued_memory_dump_requests_.front().args.dump_guid,
112 false /* success */); 112 false /* success */);
113 } 113 }
114 } 114 }
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 // Schedule the next queued dump (if applicable). 171 // Schedule the next queued dump (if applicable).
172 if (!queued_memory_dump_requests_.empty()) { 172 if (!queued_memory_dump_requests_.empty()) {
173 base::ThreadTaskRunnerHandle::Get()->PostTask( 173 base::ThreadTaskRunnerHandle::Get()->PostTask(
174 FROM_HERE, 174 FROM_HERE,
175 base::Bind(&CoordinatorImpl::PerformNextQueuedGlobalMemoryDump, 175 base::Bind(&CoordinatorImpl::PerformNextQueuedGlobalMemoryDump,
176 base::Unretained(this))); 176 base::Unretained(this)));
177 } 177 }
178 } 178 }
179 179
180 } // namespace memory_instrumentation 180 } // namespace memory_instrumentation
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698