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

Side by Side Diff: base/trace_event/memory_dump_manager.cc

Issue 1186053006: [tracing] fix a data race in MemoryDumpManager (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: femto perf improvement Created 5 years, 6 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
« no previous file with comments | « no previous file | base/trace_event/memory_dump_manager_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "base/trace_event/memory_dump_manager.h" 5 #include "base/trace_event/memory_dump_manager.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/atomic_sequence_num.h" 9 #include "base/atomic_sequence_num.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 RequestGlobalDump(dump_type, MemoryDumpCallback()); 276 RequestGlobalDump(dump_type, MemoryDumpCallback());
277 } 277 }
278 278
279 // Creates a memory dump for the current process and appends it to the trace. 279 // Creates a memory dump for the current process and appends it to the trace.
280 void MemoryDumpManager::CreateProcessDump(const MemoryDumpRequestArgs& args, 280 void MemoryDumpManager::CreateProcessDump(const MemoryDumpRequestArgs& args,
281 const MemoryDumpCallback& callback) { 281 const MemoryDumpCallback& callback) {
282 scoped_refptr<ProcessMemoryDumpHolder> pmd_holder( 282 scoped_refptr<ProcessMemoryDumpHolder> pmd_holder(
283 new ProcessMemoryDumpHolder(args, session_state_, callback)); 283 new ProcessMemoryDumpHolder(args, session_state_, callback));
284 ProcessMemoryDump* pmd = &pmd_holder->process_memory_dump; 284 ProcessMemoryDump* pmd = &pmd_holder->process_memory_dump;
285 bool did_any_provider_dump = false; 285 bool did_any_provider_dump = false;
286 bool did_post_any_async_task = false;
286 287
287 // Iterate over the active dump providers and invoke OnMemoryDump(pmd). 288 // Iterate over the active dump providers and invoke OnMemoryDump(pmd).
288 // The MDM guarantees linearity (at most one MDP is active within one 289 // The MDM guarantees linearity (at most one MDP is active within one
289 // process) and thread-safety (MDM enforces the right locking when entering / 290 // process) and thread-safety (MDM enforces the right locking when entering /
290 // leaving the MDP.OnMemoryDump() call). This is to simplify the clients' 291 // leaving the MDP.OnMemoryDump() call). This is to simplify the clients'
291 // design 292 // design
292 // and not let the MDPs worry about locking. 293 // and not let the MDPs worry about locking.
293 // As regards thread affinity, depending on the MDP configuration (see 294 // As regards thread affinity, depending on the MDP configuration (see
294 // memory_dump_provider.h), the OnMemoryDump() invocation can happen: 295 // memory_dump_provider.h), the OnMemoryDump() invocation can happen:
295 // - Synchronousy on the MDM thread, when MDP.task_runner() is not set. 296 // - Synchronousy on the MDM thread, when MDP.task_runner() is not set.
(...skipping 11 matching lines...) Expand all
307 continue; 308 continue;
308 } 309 }
309 if (mdp_info->disabled) 310 if (mdp_info->disabled)
310 continue; 311 continue;
311 if (mdp_info->task_runner) { 312 if (mdp_info->task_runner) {
312 // The OnMemoryDump() call must be posted. 313 // The OnMemoryDump() call must be posted.
313 bool did_post_async_task = mdp_info->task_runner->PostTask( 314 bool did_post_async_task = mdp_info->task_runner->PostTask(
314 FROM_HERE, Bind(&MemoryDumpManager::ContinueAsyncProcessDump, 315 FROM_HERE, Bind(&MemoryDumpManager::ContinueAsyncProcessDump,
315 Unretained(this), Unretained(mdp), pmd_holder)); 316 Unretained(this), Unretained(mdp), pmd_holder));
316 // The thread underlying the TaskRunner might have gone away. 317 // The thread underlying the TaskRunner might have gone away.
317 if (did_post_async_task) 318 if (did_post_async_task) {
318 ++pmd_holder->num_pending_async_requests; 319 ++pmd_holder->num_pending_async_requests;
320 did_post_any_async_task = true;
321 }
319 } else { 322 } else {
320 // Invoke the dump provider synchronously. 323 // Invoke the dump provider synchronously.
321 did_any_provider_dump |= InvokeDumpProviderLocked(mdp, pmd); 324 did_any_provider_dump |= InvokeDumpProviderLocked(mdp, pmd);
322 } 325 }
323 } 326 }
324 } // AutoLock 327 } // AutoLock
325 328
326 // If at least one synchronous provider did dump and there are no pending 329 // If at least one synchronous provider did dump and there are no pending
327 // asynchronous requests, add the dump to the trace and invoke the callback 330 // asynchronous requests, add the dump to the trace and invoke the callback
328 // straight away (FinalizeDumpAndAddToTrace() takes care of the callback). 331 // straight away (FinalizeDumpAndAddToTrace() takes care of the callback).
329 if (did_any_provider_dump && pmd_holder->num_pending_async_requests == 0) 332 if (did_any_provider_dump && !did_post_any_async_task)
330 FinalizeDumpAndAddToTrace(pmd_holder); 333 FinalizeDumpAndAddToTrace(pmd_holder);
331 } 334 }
332 335
333 // Invokes the MemoryDumpProvider.OnMemoryDump(), taking care of the fail-safe 336 // Invokes the MemoryDumpProvider.OnMemoryDump(), taking care of the fail-safe
334 // logic which disables the dumper when failing (crbug.com/461788). 337 // logic which disables the dumper when failing (crbug.com/461788).
335 bool MemoryDumpManager::InvokeDumpProviderLocked(MemoryDumpProvider* mdp, 338 bool MemoryDumpManager::InvokeDumpProviderLocked(MemoryDumpProvider* mdp,
336 ProcessMemoryDump* pmd) { 339 ProcessMemoryDump* pmd) {
337 lock_.AssertAcquired(); 340 lock_.AssertAcquired();
338 bool dump_successful = mdp->OnMemoryDump(pmd); 341 bool dump_successful = mdp->OnMemoryDump(pmd);
339 if (!dump_successful) { 342 if (!dump_successful) {
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 418
416 MemoryDumpManager::MemoryDumpProviderInfo::MemoryDumpProviderInfo( 419 MemoryDumpManager::MemoryDumpProviderInfo::MemoryDumpProviderInfo(
417 const scoped_refptr<SingleThreadTaskRunner>& task_runner) 420 const scoped_refptr<SingleThreadTaskRunner>& task_runner)
418 : task_runner(task_runner), disabled(false) { 421 : task_runner(task_runner), disabled(false) {
419 } 422 }
420 MemoryDumpManager::MemoryDumpProviderInfo::~MemoryDumpProviderInfo() { 423 MemoryDumpManager::MemoryDumpProviderInfo::~MemoryDumpProviderInfo() {
421 } 424 }
422 425
423 } // namespace trace_event 426 } // namespace trace_event
424 } // namespace base 427 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | base/trace_event/memory_dump_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698