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

Side by Side Diff: services/resource_coordinator/public/cpp/memory/memory_dump_manager_delegate_impl.cc

Issue 2724793002: Revert of memory-infra: Finish moving memory_infra from TracingController (Closed)
Patch Set: 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/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"
12 #include "base/trace_event/memory_dump_request_args.h" 7 #include "base/trace_event/memory_dump_request_args.h"
13 #include "mojo/public/cpp/bindings/interface_request.h" 8 #include "mojo/public/cpp/bindings/interface_request.h"
14 #include "services/resource_coordinator/public/cpp/memory/coordinator.h" 9 #include "services/resource_coordinator/public/cpp/memory/coordinator.h"
15 #include "services/resource_coordinator/public/interfaces/memory/memory_instrume ntation.mojom.h" 10 #include "services/resource_coordinator/public/interfaces/memory/memory_instrume ntation.mojom.h"
16 #include "services/service_manager/public/cpp/interface_provider.h" 11 #include "services/service_manager/public/cpp/interface_provider.h"
17 12
18 namespace memory_instrumentation { 13 namespace memory_instrumentation {
19 14
20 namespace { 15 MemoryDumpManagerDelegateImpl::MemoryDumpManagerDelegateImpl(
21 16 service_manager::InterfaceProvider* interface_provider)
22 base::LazyInstance<MemoryDumpManagerDelegateImpl>::Leaky 17 : is_coordinator_(false), binding_(this) {
23 g_memory_dump_manager_delegate = LAZY_INSTANCE_INITIALIZER; 18 interface_provider->GetInterface(mojo::MakeRequest(&coordinator_));
24 19 coordinator_->RegisterProcessLocalDumpManager(
25 } // namespace 20 binding_.CreateInterfacePtrAndBind());
26
27 // static
28 MemoryDumpManagerDelegateImpl* MemoryDumpManagerDelegateImpl::GetInstance() {
29 return g_memory_dump_manager_delegate.Pointer();
30 } 21 }
31 22
32 MemoryDumpManagerDelegateImpl::MemoryDumpManagerDelegateImpl() 23 MemoryDumpManagerDelegateImpl::MemoryDumpManagerDelegateImpl(
33 : initialized_(false), 24 Coordinator* coordinator)
34 binding_(this), 25 : is_coordinator_(true), binding_(this) {
35 task_runner_(nullptr), 26 coordinator->BindCoordinatorRequest(mojo::MakeRequest(&coordinator_));
36 pending_memory_dump_guid_(0) {} 27 coordinator_->RegisterProcessLocalDumpManager(
28 binding_.CreateInterfacePtrAndBind());
29 }
37 30
38 MemoryDumpManagerDelegateImpl::~MemoryDumpManagerDelegateImpl() {} 31 MemoryDumpManagerDelegateImpl::~MemoryDumpManagerDelegateImpl() {}
39 32
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 interface_provider->GetInterface(mojo::MakeRequest(&coordinator_));
49 coordinator_->RegisterProcessLocalDumpManager(
50 binding_.CreateInterfacePtrAndBind());
51 base::trace_event::MemoryDumpManager::GetInstance()->Initialize(this);
52 }
53
54 void MemoryDumpManagerDelegateImpl::InitializeWithCoordinator(
55 Coordinator* coordinator,
56 scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
57 DCHECK(task_runner);
58 if (!task_runner->RunsTasksOnCurrentThread()) {
59 task_runner->PostTask(
60 FROM_HERE,
61 base::Bind(&MemoryDumpManagerDelegateImpl::InitializeWithCoordinator,
62 base::Unretained(this), base::Unretained(coordinator),
63 task_runner));
64 return;
65 }
66
67 {
68 base::AutoLock lock(initialized_lock_);
69 DCHECK(!initialized_);
70 initialized_ = true;
71 }
72
73 task_runner_ = task_runner;
74 coordinator->BindCoordinatorRequest(mojo::MakeRequest(&coordinator_));
75 coordinator_->RegisterProcessLocalDumpManager(
76 binding_.CreateInterfacePtrAndBind());
77 base::trace_event::MemoryDumpManager::GetInstance()->Initialize(this);
78 }
79
80 bool MemoryDumpManagerDelegateImpl::IsCoordinator() const { 33 bool MemoryDumpManagerDelegateImpl::IsCoordinator() const {
81 return task_runner_ != nullptr; 34 return is_coordinator_;
82 } 35 }
83 36
84 void MemoryDumpManagerDelegateImpl::RequestProcessMemoryDump( 37 void MemoryDumpManagerDelegateImpl::RequestProcessMemoryDump(
85 const base::trace_event::MemoryDumpRequestArgs& args, 38 const base::trace_event::MemoryDumpRequestArgs& args,
86 const RequestProcessMemoryDumpCallback& callback) { 39 const RequestProcessMemoryDumpCallback& callback) {
87 MemoryDumpManagerDelegate::CreateProcessDump(args, callback); 40 MemoryDumpManagerDelegate::CreateProcessDump(args, callback);
88 } 41 }
89 42
90 void MemoryDumpManagerDelegateImpl::RequestGlobalMemoryDump( 43 void MemoryDumpManagerDelegateImpl::RequestGlobalMemoryDump(
91 const base::trace_event::MemoryDumpRequestArgs& args, 44 const base::trace_event::MemoryDumpRequestArgs& args,
92 const base::trace_event::MemoryDumpCallback& callback) { 45 const base::trace_event::MemoryDumpCallback& callback) {
93 // Note: This condition is here to match the old behavior. If the delegate is 46 coordinator_->RequestGlobalMemoryDump(args, callback);
94 // in the browser process, we do not drop parallel requests in the delegate
95 // and so they will be queued by the Coordinator service (see
96 // CoordinatorImpl::RequestGlobalMemoryDump). If the delegate is in a child
97 // process, parallel requests will be cancelled.
98 //
99 // TODO(chiniforooshan): After transitioning to the mojo-based service is
100 // completed, we should enable queueing parallel global memory dump requests
101 // by delegates on all processes.
102 if (task_runner_) {
103 DCHECK(task_runner_);
104 task_runner_->PostTask(
105 FROM_HERE,
106 base::Bind(&mojom::Coordinator::RequestGlobalMemoryDump,
107 base::Unretained(coordinator_.get()), args, callback));
108 return;
109 }
110
111 {
112 base::AutoLock lock(pending_memory_dump_guid_lock_);
113 if (pending_memory_dump_guid_) {
114 callback.Run(args.dump_guid, false);
115 return;
116 }
117 pending_memory_dump_guid_ = args.dump_guid;
118 }
119 DCHECK(!task_runner_);
120 auto callback_proxy =
121 base::Bind(&MemoryDumpManagerDelegateImpl::MemoryDumpCallbackProxy,
122 base::Unretained(this), callback);
123 coordinator_->RequestGlobalMemoryDump(args, callback_proxy);
124 }
125
126 void MemoryDumpManagerDelegateImpl::MemoryDumpCallbackProxy(
127 const base::trace_event::MemoryDumpCallback& callback,
128 uint64_t dump_guid,
129 bool success) {
130 DCHECK_NE(0U, pending_memory_dump_guid_);
131 pending_memory_dump_guid_ = 0;
132 callback.Run(dump_guid, success);
133 }
134
135 void MemoryDumpManagerDelegateImpl::SetAsNonCoordinatorForTesting() {
136 task_runner_ = nullptr;
137 } 47 }
138 48
139 } // namespace memory_instrumentation 49 } // namespace memory_instrumentation
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698