Chromium Code Reviews| 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/public/cpp/memory/memory_dump_manager_de legate_impl.h" | 5 #include "services/resource_coordinator/public/cpp/memory/memory_dump_manager_de legate_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | |
| 8 #include "base/bind_helpers.h" | |
| 9 #include "base/lazy_instance.h" | |
| 10 #include "base/single_thread_task_runner.h" | |
| 11 #include "base/synchronization/lock.h" | |
| 7 #include "base/trace_event/memory_dump_request_args.h" | 12 #include "base/trace_event/memory_dump_request_args.h" |
| 8 #include "mojo/public/cpp/bindings/interface_request.h" | 13 #include "mojo/public/cpp/bindings/interface_request.h" |
| 9 #include "services/resource_coordinator/public/cpp/memory/coordinator.h" | 14 #include "services/resource_coordinator/public/cpp/memory/coordinator.h" |
| 10 #include "services/resource_coordinator/public/interfaces/memory/memory_instrume ntation.mojom.h" | 15 #include "services/resource_coordinator/public/interfaces/memory/memory_instrume ntation.mojom.h" |
| 11 #include "services/service_manager/public/cpp/interface_provider.h" | 16 #include "services/service_manager/public/cpp/interface_provider.h" |
| 12 | 17 |
| 13 namespace memory_instrumentation { | 18 namespace memory_instrumentation { |
| 14 | 19 |
| 15 MemoryDumpManagerDelegateImpl::MemoryDumpManagerDelegateImpl( | 20 namespace { |
| 16 service_manager::InterfaceProvider* interface_provider) | 21 |
| 17 : is_coordinator_(false), binding_(this) { | 22 base::LazyInstance<MemoryDumpManagerDelegateImpl>::Leaky |
| 23 g_memory_dump_manager_delegate = LAZY_INSTANCE_INITIALIZER; | |
| 24 | |
| 25 } // namespace | |
| 26 | |
| 27 // static | |
| 28 MemoryDumpManagerDelegateImpl* MemoryDumpManagerDelegateImpl::GetInstance() { | |
| 29 return g_memory_dump_manager_delegate.Pointer(); | |
| 30 } | |
| 31 | |
| 32 MemoryDumpManagerDelegateImpl::MemoryDumpManagerDelegateImpl() | |
| 33 : initialized_(false), | |
| 34 binding_(this), | |
| 35 task_runner_(nullptr), | |
| 36 pending_memory_dump_guid_(0) {} | |
| 37 | |
| 38 MemoryDumpManagerDelegateImpl::~MemoryDumpManagerDelegateImpl() {} | |
| 39 | |
| 40 void MemoryDumpManagerDelegateImpl::InitializeWithInterfaceProvider( | |
| 41 service_manager::InterfaceProvider* interface_provider) { | |
| 42 { | |
| 43 base::AutoLock lock(initialized_lock_); | |
| 44 DCHECK(!initialized_); | |
| 45 initialized_ = true; | |
| 46 } | |
| 47 | |
| 48 is_coordinator_ = false; | |
| 18 interface_provider->GetInterface(mojo::MakeRequest(&coordinator_)); | 49 interface_provider->GetInterface(mojo::MakeRequest(&coordinator_)); |
| 19 coordinator_->RegisterProcessLocalDumpManager( | 50 coordinator_->RegisterProcessLocalDumpManager( |
| 20 binding_.CreateInterfacePtrAndBind()); | 51 binding_.CreateInterfacePtrAndBind()); |
| 52 base::trace_event::MemoryDumpManager::GetInstance()->Initialize(this); | |
| 21 } | 53 } |
| 22 | 54 |
| 23 MemoryDumpManagerDelegateImpl::MemoryDumpManagerDelegateImpl( | 55 void MemoryDumpManagerDelegateImpl::InitializeWithCoordinator( |
| 24 Coordinator* coordinator) | 56 Coordinator* coordinator, |
| 25 : is_coordinator_(true), binding_(this) { | 57 scoped_refptr<base::SingleThreadTaskRunner> task_runner) { |
| 58 DCHECK(task_runner); | |
| 59 if (!task_runner->RunsTasksOnCurrentThread()) { | |
| 60 task_runner->PostTask( | |
| 61 FROM_HERE, | |
| 62 base::Bind(&MemoryDumpManagerDelegateImpl::InitializeWithCoordinator, | |
| 63 base::Unretained(this), base::Unretained(coordinator), | |
| 64 task_runner)); | |
| 65 return; | |
| 66 } | |
| 67 | |
| 68 { | |
| 69 base::AutoLock lock(initialized_lock_); | |
| 70 DCHECK(!initialized_); | |
| 71 initialized_ = true; | |
| 72 } | |
| 73 | |
| 74 task_runner_ = task_runner; | |
| 75 is_coordinator_ = true; | |
| 26 coordinator->BindCoordinatorRequest(mojo::MakeRequest(&coordinator_)); | 76 coordinator->BindCoordinatorRequest(mojo::MakeRequest(&coordinator_)); |
| 27 coordinator_->RegisterProcessLocalDumpManager( | 77 coordinator_->RegisterProcessLocalDumpManager( |
| 28 binding_.CreateInterfacePtrAndBind()); | 78 binding_.CreateInterfacePtrAndBind()); |
| 79 base::trace_event::MemoryDumpManager::GetInstance()->Initialize(this); | |
| 29 } | 80 } |
| 30 | 81 |
| 31 MemoryDumpManagerDelegateImpl::~MemoryDumpManagerDelegateImpl() {} | |
| 32 | |
| 33 bool MemoryDumpManagerDelegateImpl::IsCoordinator() const { | 82 bool MemoryDumpManagerDelegateImpl::IsCoordinator() const { |
| 34 return is_coordinator_; | 83 return is_coordinator_; |
| 35 } | 84 } |
| 36 | 85 |
| 37 void MemoryDumpManagerDelegateImpl::RequestProcessMemoryDump( | 86 void MemoryDumpManagerDelegateImpl::RequestProcessMemoryDump( |
| 38 const base::trace_event::MemoryDumpRequestArgs& args, | 87 const base::trace_event::MemoryDumpRequestArgs& args, |
| 39 const RequestProcessMemoryDumpCallback& callback) { | 88 const RequestProcessMemoryDumpCallback& callback) { |
| 40 MemoryDumpManagerDelegate::CreateProcessDump(args, callback); | 89 MemoryDumpManagerDelegate::CreateProcessDump(args, callback); |
| 41 } | 90 } |
| 42 | 91 |
| 43 void MemoryDumpManagerDelegateImpl::RequestGlobalMemoryDump( | 92 void MemoryDumpManagerDelegateImpl::RequestGlobalMemoryDump( |
| 44 const base::trace_event::MemoryDumpRequestArgs& args, | 93 const base::trace_event::MemoryDumpRequestArgs& args, |
| 45 const base::trace_event::MemoryDumpCallback& callback) { | 94 const base::trace_event::MemoryDumpCallback& callback) { |
| 46 coordinator_->RequestGlobalMemoryDump(args, callback); | 95 // TODO(chiniforooshan): This condition is here to match the current |
|
ssid
2017/02/24 23:19:05
Match the old behavior? and add "behavior of queui
chiniforooshan
2017/02/25 00:04:51
Yes. Is the new comment more clear?
ssid
2017/02/25 16:07:21
Yes thanks
| |
| 96 // behaviour. After the transition, we should enable queueing parallel global | |
| 97 // memory dump requests by delegates on all processes. | |
| 98 if (is_coordinator_) { | |
| 99 DCHECK(task_runner_); | |
| 100 task_runner_->PostTask( | |
| 101 FROM_HERE, | |
| 102 base::Bind(&mojom::Coordinator::RequestGlobalMemoryDump, | |
| 103 base::Unretained(coordinator_.get()), args, callback)); | |
| 104 return; | |
| 105 } | |
| 106 | |
| 107 { | |
| 108 base::AutoLock lock(pending_memory_dump_guid_lock_); | |
| 109 if (pending_memory_dump_guid_) { | |
| 110 callback.Run(args.dump_guid, false); | |
| 111 return; | |
| 112 } | |
| 113 pending_memory_dump_guid_ = args.dump_guid; | |
| 114 } | |
| 115 DCHECK(!task_runner_); | |
| 116 auto callback_proxy = | |
| 117 base::Bind(&MemoryDumpManagerDelegateImpl::MemoryDumpCallbackProxy, | |
| 118 base::Unretained(this), callback); | |
| 119 coordinator_->RequestGlobalMemoryDump(args, callback_proxy); | |
| 120 } | |
| 121 | |
| 122 void MemoryDumpManagerDelegateImpl::MemoryDumpCallbackProxy( | |
| 123 const base::trace_event::MemoryDumpCallback& callback, | |
| 124 uint64_t dump_guid, | |
| 125 bool success) { | |
| 126 DCHECK_NE(0U, pending_memory_dump_guid_); | |
| 127 pending_memory_dump_guid_ = 0; | |
| 128 callback.Run(dump_guid, success); | |
| 129 } | |
| 130 | |
| 131 void MemoryDumpManagerDelegateImpl::SetAsNonCoordinatorForTesting() { | |
| 132 is_coordinator_ = false; | |
| 133 task_runner_ = nullptr; | |
| 47 } | 134 } |
| 48 | 135 |
| 49 } // namespace memory_instrumentation | 136 } // namespace memory_instrumentation |
| OLD | NEW |