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

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

Issue 2871223002: memory-infra: add ProcessType and expose data in RequestGlobalDump() (Closed)
Patch Set: review comments Created 3 years, 7 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/process_local_dump_man ager_impl.h" 5 #include "services/resource_coordinator/public/cpp/memory/process_local_dump_man ager_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/single_thread_task_runner.h" 9 #include "base/single_thread_task_runner.h"
10 #include "base/synchronization/lock.h" 10 #include "base/synchronization/lock.h"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 base::Unretained(this)), 51 base::Unretained(this)),
52 is_coordinator_process); 52 is_coordinator_process);
53 } 53 }
54 54
55 ProcessLocalDumpManagerImpl::~ProcessLocalDumpManagerImpl() {} 55 ProcessLocalDumpManagerImpl::~ProcessLocalDumpManagerImpl() {}
56 56
57 void ProcessLocalDumpManagerImpl::RequestProcessMemoryDump( 57 void ProcessLocalDumpManagerImpl::RequestProcessMemoryDump(
58 const base::trace_event::MemoryDumpRequestArgs& args, 58 const base::trace_event::MemoryDumpRequestArgs& args,
59 const RequestProcessMemoryDumpCallback& callback) { 59 const RequestProcessMemoryDumpCallback& callback) {
60 base::trace_event::MemoryDumpManager::GetInstance()->CreateProcessDump( 60 base::trace_event::MemoryDumpManager::GetInstance()->CreateProcessDump(
61 args, callback); 61 args, base::Bind(&ProcessLocalDumpManagerImpl::OnProcessMemoryDumpDone,
62 base::Unretained(this), callback));
63 }
64
65 void ProcessLocalDumpManagerImpl::OnProcessMemoryDumpDone(
66 const RequestProcessMemoryDumpCallback& callback,
67 uint64_t dump_guid,
68 bool success,
69 const base::Optional<base::trace_event::MemoryDumpCallbackResult>& result) {
70 mojom::ProcessMemoryDumpPtr process_memory_dump(
71 mojom::ProcessMemoryDump::New());
72 process_memory_dump->process_type = config_.process_type();
73 if (result) {
74 process_memory_dump->os_dump = result->os_dump;
dcheng 2017/05/12 08:07:41 Is there a reason to switch from using StructTrait
Primiano Tucci (use gerrit) 2017/05/12 11:42:46 Yes. the MemoryDumpManager::CreateProcessDump() ca
75 process_memory_dump->chrome_dump = result->chrome_dump;
76 for (const auto& kv : result->extra_processes_dump) {
77 const base::ProcessId pid = kv.first;
78 const base::trace_event::MemoryDumpCallbackResult::OSMemDump&
79 os_mem_dump = kv.second;
80 DCHECK_EQ(0u, process_memory_dump->extra_processes_dump.count(pid));
81 process_memory_dump->extra_processes_dump[pid] = os_mem_dump;
82 }
83 }
84 callback.Run(dump_guid, success, std::move(process_memory_dump));
62 } 85 }
63 86
64 void ProcessLocalDumpManagerImpl::RequestGlobalMemoryDump( 87 void ProcessLocalDumpManagerImpl::RequestGlobalMemoryDump(
65 const base::trace_event::MemoryDumpRequestArgs& args, 88 const base::trace_event::MemoryDumpRequestArgs& args,
66 const base::trace_event::GlobalMemoryDumpCallback& callback) { 89 const base::trace_event::GlobalMemoryDumpCallback& callback) {
67 // Note: This condition is here to match the old behavior. If the delegate is 90 // Note: This condition is here to match the old behavior. If the delegate is
68 // in the browser process, we do not drop parallel requests in the delegate 91 // in the browser process, we do not drop parallel requests in the delegate
69 // and so they will be queued by the Coordinator service (see 92 // and so they will be queued by the Coordinator service (see
70 // CoordinatorImpl::RequestGlobalMemoryDump). If the delegate is in a child 93 // CoordinatorImpl::RequestGlobalMemoryDump). If the delegate is in a child
71 // process, parallel requests will be cancelled. 94 // process, parallel requests will be cancelled.
72 // 95 //
73 // TODO(chiniforooshan): Unify the child and browser behavior. 96 // TODO(primiano): Remove all this boilerplate. There should be no need of
97 // any lock, proxy, callback adaption or early out. The service is able to
98 // deal with queueing.
74 if (task_runner_) { 99 if (task_runner_) {
100 auto callback_proxy =
101 base::Bind(&ProcessLocalDumpManagerImpl::MemoryDumpCallbackProxy,
102 base::Unretained(this), callback);
75 task_runner_->PostTask( 103 task_runner_->PostTask(
76 FROM_HERE, 104 FROM_HERE,
77 base::Bind(&mojom::Coordinator::RequestGlobalMemoryDump, 105 base::Bind(&mojom::Coordinator::RequestGlobalMemoryDump,
78 base::Unretained(coordinator_.get()), args, callback)); 106 base::Unretained(coordinator_.get()), args, callback_proxy));
79 return; 107 return;
80 } 108 }
81 109
110 bool early_out_because_of_another_dump_pending = false;
82 { 111 {
83 base::AutoLock lock(pending_memory_dump_guid_lock_); 112 base::AutoLock lock(pending_memory_dump_guid_lock_);
84 if (pending_memory_dump_guid_) { 113 if (pending_memory_dump_guid_)
85 callback.Run(args.dump_guid, false); 114 early_out_because_of_another_dump_pending = true;
86 return; 115 else
87 } 116 pending_memory_dump_guid_ = args.dump_guid;
88 pending_memory_dump_guid_ = args.dump_guid;
89 } 117 }
118 if (early_out_because_of_another_dump_pending) {
119 callback.Run(args.dump_guid, false);
120 return;
121 }
122
90 auto callback_proxy = 123 auto callback_proxy =
91 base::Bind(&ProcessLocalDumpManagerImpl::MemoryDumpCallbackProxy, 124 base::Bind(&ProcessLocalDumpManagerImpl::MemoryDumpCallbackProxy,
92 base::Unretained(this), callback); 125 base::Unretained(this), callback);
93 coordinator_->RequestGlobalMemoryDump(args, callback_proxy); 126 coordinator_->RequestGlobalMemoryDump(args, callback_proxy);
94 } 127 }
95 128
96 void ProcessLocalDumpManagerImpl::MemoryDumpCallbackProxy( 129 void ProcessLocalDumpManagerImpl::MemoryDumpCallbackProxy(
97 const base::trace_event::GlobalMemoryDumpCallback& callback, 130 const base::trace_event::GlobalMemoryDumpCallback& callback,
98 uint64_t dump_guid, 131 uint64_t dump_guid,
99 bool success) { 132 bool success,
133 mojom::GlobalMemoryDumpPtr) {
100 { 134 {
101 base::AutoLock lock(pending_memory_dump_guid_lock_); 135 base::AutoLock lock(pending_memory_dump_guid_lock_);
102 DCHECK_NE(0U, pending_memory_dump_guid_);
103 pending_memory_dump_guid_ = 0; 136 pending_memory_dump_guid_ = 0;
104 } 137 }
138
139 // The GlobalMemoryDumpPtr argument is ignored. The actual data of the dump
140 // is exposed only through the service and is not passed back to base.
141 // TODO(primiano): All these roundtrips are transitional until we move all
142 // the clients of memory-infra to use directly the service. crbug.com/720352 .
105 callback.Run(dump_guid, success); 143 callback.Run(dump_guid, success);
106 } 144 }
107 145
108 void ProcessLocalDumpManagerImpl::SetAsNonCoordinatorForTesting() { 146 void ProcessLocalDumpManagerImpl::SetAsNonCoordinatorForTesting() {
109 task_runner_ = nullptr; 147 task_runner_ = nullptr;
110 } 148 }
111 149
112 } // namespace memory_instrumentation 150 } // namespace memory_instrumentation
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698