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

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

Issue 1536533004: [tracing] Simplify logic of MemoryDumpManager (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: more simplicity Created 5 years 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 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 #include <utility> 8 #include <utility>
9 9
10 #include "base/atomic_sequence_num.h" 10 #include "base/atomic_sequence_num.h"
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 } 186 }
187 187
188 void MemoryDumpManager::RegisterDumpProvider( 188 void MemoryDumpManager::RegisterDumpProvider(
189 MemoryDumpProvider* mdp, 189 MemoryDumpProvider* mdp,
190 const char* name, 190 const char* name,
191 const scoped_refptr<SingleThreadTaskRunner>& task_runner, 191 const scoped_refptr<SingleThreadTaskRunner>& task_runner,
192 const MemoryDumpProvider::Options& options) { 192 const MemoryDumpProvider::Options& options) {
193 if (dumper_registrations_ignored_for_testing_) 193 if (dumper_registrations_ignored_for_testing_)
194 return; 194 return;
195 195
196 MemoryDumpProviderInfo mdp_info(mdp, name, task_runner, options); 196 {
197 AutoLock lock(lock_); 197 AutoLock lock(lock_);
198 auto iter_new = dump_providers_.insert(mdp_info); 198 scoped_refptr<MemoryDumpProviderInfo> mdpinfo =
199 199 new MemoryDumpProviderInfo(mdp, name, task_runner, options);
200 // If there was a previous entry, replace it with the new one. This is to deal 200 dump_providers_.insert(mdpinfo);
201 // with the case where a dump provider unregisters itself and then re-
202 // registers before a memory dump happens, so its entry was still in the
203 // collection but flagged |unregistered|.
204 if (!iter_new.second) {
205 dump_providers_.erase(iter_new.first);
206 dump_providers_.insert(mdp_info);
207 } 201 }
208 202
209 if (heap_profiling_enabled_) 203 if (heap_profiling_enabled_)
210 mdp->OnHeapProfilingEnabled(true); 204 mdp->OnHeapProfilingEnabled(true);
211 } 205 }
212 206
213 void MemoryDumpManager::RegisterDumpProvider( 207 void MemoryDumpManager::RegisterDumpProvider(
214 MemoryDumpProvider* mdp, 208 MemoryDumpProvider* mdp,
215 const char* name, 209 const char* name,
216 const scoped_refptr<SingleThreadTaskRunner>& task_runner) { 210 const scoped_refptr<SingleThreadTaskRunner>& task_runner) {
217 RegisterDumpProvider(mdp, name, task_runner, MemoryDumpProvider::Options()); 211 RegisterDumpProvider(mdp, name, task_runner, MemoryDumpProvider::Options());
218 } 212 }
219 213
220 void MemoryDumpManager::UnregisterDumpProvider(MemoryDumpProvider* mdp) { 214 void MemoryDumpManager::UnregisterDumpProvider(MemoryDumpProvider* mdp) {
221 AutoLock lock(lock_); 215 AutoLock lock(lock_);
222 216
223 auto mdp_iter = dump_providers_.begin(); 217 auto mdp_iter = dump_providers_.begin();
224 for (; mdp_iter != dump_providers_.end(); ++mdp_iter) { 218 for (; mdp_iter != dump_providers_.end(); ++mdp_iter) {
225 if (mdp_iter->dump_provider == mdp) 219 if ((*mdp_iter)->dump_provider == mdp)
226 break; 220 break;
227 } 221 }
228 222
229 if (mdp_iter == dump_providers_.end()) 223 if (mdp_iter == dump_providers_.end())
230 return; 224 return;
231 225
232 // Unregistration of a MemoryDumpProvider while tracing is ongoing is safe 226 // Unregistration of a MemoryDumpProvider while tracing is ongoing is safe
233 // only if the MDP has specified a thread affinity (via task_runner()) AND 227 // only if the MDP has specified a thread affinity (via task_runner()) AND
234 // the unregistration happens on the same thread (so the MDP cannot unregister 228 // the unregistration happens on the same thread (so the MDP cannot unregister
235 // and OnMemoryDump() at the same time). 229 // and OnMemoryDump() at the same time).
236 // Otherwise, it is not possible to guarantee that its unregistration is 230 // Otherwise, it is not possible to guarantee that its unregistration is
237 // race-free. If you hit this DCHECK, your MDP has a bug. 231 // race-free. If you hit this DCHECK, your MDP has a bug.
238 DCHECK(!subtle::NoBarrier_Load(&memory_tracing_enabled_) || 232 DCHECK(!subtle::NoBarrier_Load(&memory_tracing_enabled_) ||
239 (mdp_iter->task_runner && 233 ((*mdp_iter)->task_runner &&
240 mdp_iter->task_runner->BelongsToCurrentThread())) 234 (*mdp_iter)->task_runner->BelongsToCurrentThread()))
241 << "MemoryDumpProvider \"" << mdp_iter->name << "\" attempted to " 235 << "MemoryDumpProvider \"" << (*mdp_iter)->name << "\" attempted to "
242 << "unregister itself in a racy way. Please file a crbug."; 236 << "unregister itself in a racy way. Please file a crbug.";
243 237
244 mdp_iter->unregistered = true; 238 // The MDPInfo instance can still be referenced by the
239 // |ProcessMemoryDumpAsyncState.pending_dump_providers|. For this reason
240 // the MDPInfo is flagged as disabled. It will cause ContinueAsyncProcessDump
241 // to just skip it, without actually invoking the |mdp|, which might be
242 // destroyed by the caller soon after this method returns.
243 (*mdp_iter)->disabled = true;
244 dump_providers_.erase(mdp_iter);
245 } 245 }
246 246
247 void MemoryDumpManager::RequestGlobalDump( 247 void MemoryDumpManager::RequestGlobalDump(
248 MemoryDumpType dump_type, 248 MemoryDumpType dump_type,
249 MemoryDumpLevelOfDetail level_of_detail, 249 MemoryDumpLevelOfDetail level_of_detail,
250 const MemoryDumpCallback& callback) { 250 const MemoryDumpCallback& callback) {
251 // Bail out immediately if tracing is not enabled at all. 251 // Bail out immediately if tracing is not enabled at all.
252 if (!UNLIKELY(subtle::NoBarrier_Load(&memory_tracing_enabled_))) { 252 if (!UNLIKELY(subtle::NoBarrier_Load(&memory_tracing_enabled_))) {
253 if (!callback.is_null()) 253 if (!callback.is_null())
254 callback.Run(0u /* guid */, false /* success */); 254 callback.Run(0u /* guid */, false /* success */);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 } 289 }
290 290
291 void MemoryDumpManager::CreateProcessDump(const MemoryDumpRequestArgs& args, 291 void MemoryDumpManager::CreateProcessDump(const MemoryDumpRequestArgs& args,
292 const MemoryDumpCallback& callback) { 292 const MemoryDumpCallback& callback) {
293 TRACE_EVENT_NESTABLE_ASYNC_BEGIN0(kTraceCategory, "ProcessMemoryDump", 293 TRACE_EVENT_NESTABLE_ASYNC_BEGIN0(kTraceCategory, "ProcessMemoryDump",
294 TRACE_ID_MANGLE(args.dump_guid)); 294 TRACE_ID_MANGLE(args.dump_guid));
295 295
296 scoped_ptr<ProcessMemoryDumpAsyncState> pmd_async_state; 296 scoped_ptr<ProcessMemoryDumpAsyncState> pmd_async_state;
297 { 297 {
298 AutoLock lock(lock_); 298 AutoLock lock(lock_);
299 pmd_async_state.reset(new ProcessMemoryDumpAsyncState( 299 pmd_async_state.reset(
300 args, dump_providers_.begin(), session_state_, callback, 300 new ProcessMemoryDumpAsyncState(args, dump_providers_, session_state_,
301 dump_thread_->task_runner())); 301 callback, dump_thread_->task_runner()));
302 } 302 }
303 303
304 TRACE_EVENT_WITH_FLOW0(kTraceCategory, "MemoryDumpManager::CreateProcessDump", 304 TRACE_EVENT_WITH_FLOW0(kTraceCategory, "MemoryDumpManager::CreateProcessDump",
305 TRACE_ID_MANGLE(args.dump_guid), 305 TRACE_ID_MANGLE(args.dump_guid),
306 TRACE_EVENT_FLAG_FLOW_OUT); 306 TRACE_EVENT_FLAG_FLOW_OUT);
307 307
308 // Start the thread hop. |dump_providers_| are kept sorted by thread, so 308 // Start the thread hop. |dump_providers_| are kept sorted by thread, so
309 // ContinueAsyncProcessDump will hop at most once per thread (w.r.t. thread 309 // ContinueAsyncProcessDump will hop at most once per thread (w.r.t. thread
310 // affinity specified by the MemoryDumpProvider(s) in RegisterDumpProvider()). 310 // affinity specified by the MemoryDumpProvider(s) in RegisterDumpProvider()).
311 ContinueAsyncProcessDump(std::move(pmd_async_state)); 311 ContinueAsyncProcessDump(pmd_async_state.release());
312 } 312 }
313 313
314 // At most one ContinueAsyncProcessDump() can be active at any time for a given 314 // At most one ContinueAsyncProcessDump() can be active at any time for a given
315 // PMD, regardless of status of the |lock_|. |lock_| is used here purely to 315 // PMD, regardless of status of the |lock_|. |lock_| is used here purely to
316 // ensure consistency w.r.t. (un)registrations of |dump_providers_|. 316 // ensure consistency w.r.t. (un)registrations of |dump_providers_|.
317 // The linearization of dump providers' OnMemoryDump invocations is achieved by 317 // The linearization of dump providers' OnMemoryDump invocations is achieved by
318 // means of subsequent PostTask(s). 318 // means of subsequent PostTask(s).
319 // 319 //
320 // 1) Prologue: 320 // 1) Prologue:
321 // - If this was the last hop, create a trace event, add it to the trace
322 // and finalize (invoke callback).
323 // - Check if we are on the right thread. If not hop and continue there.
321 // - Check if the dump provider is disabled, if so skip the dump. 324 // - Check if the dump provider is disabled, if so skip the dump.
322 // - Check if we are on the right thread. If not hop and continue there.
323 // 2) Invoke the dump provider's OnMemoryDump() (unless skipped). 325 // 2) Invoke the dump provider's OnMemoryDump() (unless skipped).
324 // 3) Epilogue: 326 // 3) Epilogue:
325 // - Unregister the dump provider if it failed too many times consecutively. 327 // - Unregister the dump provider if it failed too many times consecutively.
326 // - Advance the |next_dump_provider| iterator to the next dump provider. 328 // - Pop() the MDP from the |pending_dump_providers| list, eventually
327 // - If this was the last hop, create a trace event, add it to the trace 329 // destroying the MDPInfo if that was unregistered in the meantime.
328 // and finalize (invoke callback).
329
330 void MemoryDumpManager::ContinueAsyncProcessDump( 330 void MemoryDumpManager::ContinueAsyncProcessDump(
331 scoped_ptr<ProcessMemoryDumpAsyncState> pmd_async_state) { 331 ProcessMemoryDumpAsyncState* owned_pmd_async_state) {
332 // Initalizes the ThreadLocalEventBuffer to guarantee that the TRACE_EVENTs 332 // Initalizes the ThreadLocalEventBuffer to guarantee that the TRACE_EVENTs
333 // in the PostTask below don't end up registering their own dump providers 333 // in the PostTask below don't end up registering their own dump providers
334 // (for discounting trace memory overhead) while holding the |lock_|. 334 // (for discounting trace memory overhead) while holding the |lock_|.
335 TraceLog::GetInstance()->InitializeThreadLocalEventBufferIfSupported(); 335 TraceLog::GetInstance()->InitializeThreadLocalEventBufferIfSupported();
336 336
337 const uint64_t dump_guid = pmd_async_state->req_args.dump_guid; 337 // In theory |owned_pmd_async_state| should be a scoped_ptr. The only reason
338 const char* dump_provider_name = nullptr; 338 // why it isn't is because of the corner case logic of |did_post_task| below,
339 // which needs to take back the ownership of the |pmd_async_state| when a
340 // thread goes away and consequently the PostTask() fails.
341 // Unfortunately, PostTask() destroys the scoped_ptr arguments upon failure
342 // to prevent accidental leaks. Using a scoped_ptr would prevent us to to
343 // skip the hop and move on. Hence the manual naked -> scoped ptr juggling.
344 auto pmd_async_state = make_scoped_ptr(owned_pmd_async_state);
345 owned_pmd_async_state = nullptr;
339 346
340 // Pid of the target process being dumped. Often kNullProcessId (= current 347 if (pmd_async_state->pending_dump_providers.empty())
341 // process), non-zero when the coordinator process creates dumps on behalf 348 return FinalizeDumpAndAddToTrace(std::move(pmd_async_state));
342 // of child processes (see crbug.com/461788).
343 ProcessId pid;
344 349
345 // DO NOT put any LOG() statement in the locked sections, as in some contexts 350 // Read MemoryDumpProviderInfo thread safety considerations in
346 // (GPU process) LOG() ends up performing PostTask/IPCs. 351 // memory_dump_manager.h when accessing |mdpinfo| fields.
347 MemoryDumpProvider* mdp; 352 MemoryDumpProviderInfo* mdpinfo =
348 bool skip_dump = false; 353 pmd_async_state->pending_dump_providers.back().get();
349 {
350 AutoLock lock(lock_);
351 354
352 auto mdp_info = pmd_async_state->next_dump_provider; 355 // If the dump provider did not specify a thread affinity, dump on
353 mdp = mdp_info->dump_provider; 356 // |dump_thread_|. Note that |dump_thread_| might have been Stop()-ed at this
354 dump_provider_name = mdp_info->name; 357 // point (if tracing was disabled in the meanwhile). In such case the
355 pid = mdp_info->options.target_pid; 358 // PostTask() below will fail, but |task_runner| should always be non-null.
359 SingleThreadTaskRunner* task_runner = mdpinfo->task_runner.get();
360 if (!task_runner)
361 task_runner = pmd_async_state->dump_thread_task_runner.get();
356 362
357 // If the dump provider did not specify a thread affinity, dump on 363 if (!task_runner->BelongsToCurrentThread()) {
358 // |dump_thread_|. 364 // It's time to hop onto another thread.
359 SingleThreadTaskRunner* task_runner = mdp_info->task_runner.get(); 365 const bool did_post_task = task_runner->PostTask(
360 if (!task_runner) 366 FROM_HERE, Bind(&MemoryDumpManager::ContinueAsyncProcessDump,
361 task_runner = pmd_async_state->dump_thread_task_runner.get(); 367 Unretained(this), Unretained(pmd_async_state.get())));
368 if (did_post_task) {
369 // Ownership is tranferred to the next ContinueAsyncProcessDump().
370 ignore_result(pmd_async_state.release());
371 return;
372 }
373 // The thread is gone. Skip the dump provider and keep going.
374 mdpinfo->disabled = true;
375 }
362 376
363 // |dump_thread_| might have been Stop()-ed at this point (if tracing was 377 // We are now on the right thread to read non-const |mdpinfo| fields.
ssid 2015/12/18 15:16:53 Comment could be : Either we are on right thread o
Primiano Tucci (use gerrit) 2015/12/18 16:54:46 Done.
364 // disabled in the meanwhile). In such case the PostTask() below will fail.
365 // |task_runner|, however, should always be non-null.
366 DCHECK(task_runner);
367 378
368 if (mdp_info->disabled || mdp_info->unregistered) { 379 if (!mdpinfo->disabled) {
369 skip_dump = true; 380 // Invoke the dump provider.
370 } else if (!task_runner->BelongsToCurrentThread()) {
371 // It's time to hop onto another thread.
372
373 // Copy the callback + arguments just for the unlikley case in which
374 // PostTask fails. In such case the Bind helper will destroy the
375 // pmd_async_state and we must keep a copy of the fields to notify the
376 // abort.
377 MemoryDumpCallback callback = pmd_async_state->callback;
378 scoped_refptr<SingleThreadTaskRunner> callback_task_runner =
379 pmd_async_state->callback_task_runner;
380
381 const bool did_post_task = task_runner->PostTask(
382 FROM_HERE, Bind(&MemoryDumpManager::ContinueAsyncProcessDump,
383 Unretained(this), Passed(&pmd_async_state)));
384 if (did_post_task)
385 return;
386
387 // The thread is gone. At this point the best thing we can do is to
388 // disable the dump provider and abort this dump.
389 mdp_info->disabled = true;
390 return AbortDumpLocked(callback, callback_task_runner, dump_guid);
391 }
392 } // AutoLock(lock_)
393
394 // Invoke the dump provider without holding the |lock_|.
395 bool finalize = false;
396 bool dump_successful = false;
397
398 if (!skip_dump) {
399 TRACE_EVENT_WITH_FLOW1(kTraceCategory, 381 TRACE_EVENT_WITH_FLOW1(kTraceCategory,
400 "MemoryDumpManager::ContinueAsyncProcessDump", 382 "MemoryDumpManager::ContinueAsyncProcessDump",
401 TRACE_ID_MANGLE(dump_guid), 383 TRACE_ID_MANGLE(pmd_async_state->req_args.dump_guid),
402 TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT, 384 TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT,
403 "dump_provider.name", dump_provider_name); 385 "dump_provider.name", mdpinfo->name);
386
387 // Pid of the target process being dumped. Often kNullProcessId (= current
388 // process), non-zero when the coordinator process creates dumps on behalf
389 // of child processes (see crbug.com/461788).
390 ProcessId target_pid = mdpinfo->options.target_pid;
391 ProcessMemoryDump* pmd =
392 pmd_async_state->GetOrCreateMemoryDumpContainerForProcess(target_pid);
404 MemoryDumpArgs args = {pmd_async_state->req_args.level_of_detail}; 393 MemoryDumpArgs args = {pmd_async_state->req_args.level_of_detail};
405 ProcessMemoryDump* process_memory_dump = 394 bool dump_successful = mdpinfo->dump_provider->OnMemoryDump(args, pmd);
406 pmd_async_state->GetOrCreateMemoryDumpContainerForProcess(pid);
407 dump_successful = mdp->OnMemoryDump(args, process_memory_dump);
408 }
409 395
410 {
411 AutoLock lock(lock_);
412 auto mdp_info = pmd_async_state->next_dump_provider;
413 if (dump_successful) { 396 if (dump_successful) {
414 mdp_info->consecutive_failures = 0; 397 mdpinfo->consecutive_failures = 0;
415 } else if (!skip_dump) { 398 } else {
416 ++mdp_info->consecutive_failures; 399 ++mdpinfo->consecutive_failures;
417 if (mdp_info->consecutive_failures >= kMaxConsecutiveFailuresCount) { 400 if (mdpinfo->consecutive_failures >= kMaxConsecutiveFailuresCount) {
418 mdp_info->disabled = true; 401 mdpinfo->disabled = true;
402 LOG(ERROR) << "MemoryDumpProvider \"" << mdpinfo->name << "\" failed, "
403 << "possibly due to sandboxing (crbug.com/461788)."
404 << "Disabling dumper for current process. Try --no-sandbox.";
419 } 405 }
420 } 406 }
421 ++pmd_async_state->next_dump_provider; 407 } // if (!mdpinfo->disabled)
422 finalize = pmd_async_state->next_dump_provider == dump_providers_.end();
423 408
424 if (mdp_info->unregistered) 409 pmd_async_state->pending_dump_providers.pop_back();
425 dump_providers_.erase(mdp_info); 410 ContinueAsyncProcessDump(pmd_async_state.release());
426 }
427
428 if (!skip_dump && !dump_successful) {
429 LOG(ERROR) << "MemoryDumpProvider \"" << dump_provider_name << "\" failed, "
430 << "possibly due to sandboxing (crbug.com/461788)."
431 << "Disabling dumper for current process. Try --no-sandbox.";
432 }
433
434 if (finalize)
435 return FinalizeDumpAndAddToTrace(std::move(pmd_async_state));
436
437 ContinueAsyncProcessDump(std::move(pmd_async_state));
438 } 411 }
439 412
440 // static 413 // static
441 void MemoryDumpManager::FinalizeDumpAndAddToTrace( 414 void MemoryDumpManager::FinalizeDumpAndAddToTrace(
442 scoped_ptr<ProcessMemoryDumpAsyncState> pmd_async_state) { 415 scoped_ptr<ProcessMemoryDumpAsyncState> pmd_async_state) {
416 DCHECK(pmd_async_state->pending_dump_providers.empty());
443 const uint64_t dump_guid = pmd_async_state->req_args.dump_guid; 417 const uint64_t dump_guid = pmd_async_state->req_args.dump_guid;
444 if (!pmd_async_state->callback_task_runner->BelongsToCurrentThread()) { 418 if (!pmd_async_state->callback_task_runner->BelongsToCurrentThread()) {
445 scoped_refptr<SingleThreadTaskRunner> callback_task_runner = 419 scoped_refptr<SingleThreadTaskRunner> callback_task_runner =
446 pmd_async_state->callback_task_runner; 420 pmd_async_state->callback_task_runner;
447 callback_task_runner->PostTask( 421 callback_task_runner->PostTask(
448 FROM_HERE, Bind(&MemoryDumpManager::FinalizeDumpAndAddToTrace, 422 FROM_HERE, Bind(&MemoryDumpManager::FinalizeDumpAndAddToTrace,
449 Passed(&pmd_async_state))); 423 Passed(&pmd_async_state)));
450 return; 424 return;
451 } 425 }
452 426
(...skipping 23 matching lines...) Expand all
476 450
477 if (!pmd_async_state->callback.is_null()) { 451 if (!pmd_async_state->callback.is_null()) {
478 pmd_async_state->callback.Run(dump_guid, true /* success */); 452 pmd_async_state->callback.Run(dump_guid, true /* success */);
479 pmd_async_state->callback.Reset(); 453 pmd_async_state->callback.Reset();
480 } 454 }
481 455
482 TRACE_EVENT_NESTABLE_ASYNC_END0(kTraceCategory, "ProcessMemoryDump", 456 TRACE_EVENT_NESTABLE_ASYNC_END0(kTraceCategory, "ProcessMemoryDump",
483 TRACE_ID_MANGLE(dump_guid)); 457 TRACE_ID_MANGLE(dump_guid));
484 } 458 }
485 459
486 // static
487 void MemoryDumpManager::AbortDumpLocked(
488 MemoryDumpCallback callback,
489 scoped_refptr<SingleThreadTaskRunner> task_runner,
490 uint64_t dump_guid) {
491 if (callback.is_null())
492 return; // There is nothing to NACK.
493
494 // Post the callback even if we are already on the right thread to avoid
495 // invoking the callback while holding the lock_.
496 task_runner->PostTask(FROM_HERE,
497 Bind(callback, dump_guid, false /* success */));
498 }
499
500 void MemoryDumpManager::OnTraceLogEnabled() { 460 void MemoryDumpManager::OnTraceLogEnabled() {
501 bool enabled; 461 bool enabled;
502 TRACE_EVENT_CATEGORY_GROUP_ENABLED(kTraceCategory, &enabled); 462 TRACE_EVENT_CATEGORY_GROUP_ENABLED(kTraceCategory, &enabled);
503 if (!enabled) 463 if (!enabled)
504 return; 464 return;
505 465
506 // Initialize the TraceLog for the current thread. This is to avoid that the 466 // Initialize the TraceLog for the current thread. This is to avoid that the
507 // TraceLog memory dump provider is registered lazily in the PostTask() below 467 // TraceLog memory dump provider is registered lazily in the PostTask() below
508 // while the |lock_| is taken; 468 // while the |lock_| is taken;
509 TraceLog::GetInstance()->InitializeThreadLocalEventBufferIfSupported(); 469 TraceLog::GetInstance()->InitializeThreadLocalEventBufferIfSupported();
(...skipping 24 matching lines...) Expand all
534 TRACE_EVENT_API_ADD_METADATA_EVENT( 494 TRACE_EVENT_API_ADD_METADATA_EVENT(
535 "typeNames", "typeNames", 495 "typeNames", "typeNames",
536 scoped_refptr<ConvertableToTraceFormat>(type_name_deduplicator)); 496 scoped_refptr<ConvertableToTraceFormat>(type_name_deduplicator));
537 } 497 }
538 498
539 DCHECK(!dump_thread_); 499 DCHECK(!dump_thread_);
540 dump_thread_ = std::move(dump_thread); 500 dump_thread_ = std::move(dump_thread);
541 session_state_ = new MemoryDumpSessionState(stack_frame_deduplicator, 501 session_state_ = new MemoryDumpSessionState(stack_frame_deduplicator,
542 type_name_deduplicator); 502 type_name_deduplicator);
543 503
544 for (auto it = dump_providers_.begin(); it != dump_providers_.end(); ++it) {
545 it->disabled = false;
546 it->consecutive_failures = 0;
547 }
548
549 subtle::NoBarrier_Store(&memory_tracing_enabled_, 1); 504 subtle::NoBarrier_Store(&memory_tracing_enabled_, 1);
550 505
551 // TODO(primiano): This is a temporary hack to disable periodic memory dumps 506 // TODO(primiano): This is a temporary hack to disable periodic memory dumps
552 // when running memory benchmarks until telemetry uses TraceConfig to 507 // when running memory benchmarks until telemetry uses TraceConfig to
553 // enable/disable periodic dumps. See crbug.com/529184 . 508 // enable/disable periodic dumps. See crbug.com/529184 .
554 if (!is_coordinator_ || 509 if (!is_coordinator_ ||
555 CommandLine::ForCurrentProcess()->HasSwitch( 510 CommandLine::ForCurrentProcess()->HasSwitch(
556 "enable-memory-benchmarking")) { 511 "enable-memory-benchmarking")) {
557 return; 512 return;
558 } 513 }
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
610 MemoryDumpManager::MemoryDumpProviderInfo::MemoryDumpProviderInfo( 565 MemoryDumpManager::MemoryDumpProviderInfo::MemoryDumpProviderInfo(
611 MemoryDumpProvider* dump_provider, 566 MemoryDumpProvider* dump_provider,
612 const char* name, 567 const char* name,
613 const scoped_refptr<SingleThreadTaskRunner>& task_runner, 568 const scoped_refptr<SingleThreadTaskRunner>& task_runner,
614 const MemoryDumpProvider::Options& options) 569 const MemoryDumpProvider::Options& options)
615 : dump_provider(dump_provider), 570 : dump_provider(dump_provider),
616 name(name), 571 name(name),
617 task_runner(task_runner), 572 task_runner(task_runner),
618 options(options), 573 options(options),
619 consecutive_failures(0), 574 consecutive_failures(0),
620 disabled(false), 575 disabled(false) {}
621 unregistered(false) {}
622 576
623 MemoryDumpManager::MemoryDumpProviderInfo::~MemoryDumpProviderInfo() {} 577 MemoryDumpManager::MemoryDumpProviderInfo::~MemoryDumpProviderInfo() {}
624 578
625 bool MemoryDumpManager::MemoryDumpProviderInfo::operator<( 579 bool MemoryDumpManager::MemoryDumpProviderInfo::Comparator::operator()(
626 const MemoryDumpProviderInfo& other) const { 580 const scoped_refptr<MemoryDumpManager::MemoryDumpProviderInfo>& a,
627 if (task_runner == other.task_runner) 581 const scoped_refptr<MemoryDumpManager::MemoryDumpProviderInfo>& b) const {
628 return dump_provider < other.dump_provider; 582 if (!a || !b)
583 return a.get() < b.get();
629 // Ensure that unbound providers (task_runner == nullptr) always run last. 584 // Ensure that unbound providers (task_runner == nullptr) always run last.
630 return !(task_runner < other.task_runner); 585 // Rationale: some unbound dump providers are known to be slow, keep them last
586 // to avoid skewing timings of the other dump providers.
ssid 2015/12/18 15:16:53 I think there are much slower dump providers now,
Primiano Tucci (use gerrit) 2015/12/18 16:54:46 Yeah I think in future CLs I'll need to introduce
587 return std::tie(a->task_runner, a->dump_provider) >
588 std::tie(b->task_runner, b->dump_provider);
631 } 589 }
632 590
633 MemoryDumpManager::ProcessMemoryDumpAsyncState::ProcessMemoryDumpAsyncState( 591 MemoryDumpManager::ProcessMemoryDumpAsyncState::ProcessMemoryDumpAsyncState(
634 MemoryDumpRequestArgs req_args, 592 MemoryDumpRequestArgs req_args,
635 MemoryDumpProviderInfoSet::iterator next_dump_provider, 593 const MemoryDumpProviderInfo::OrderedSet& dump_providers,
636 const scoped_refptr<MemoryDumpSessionState>& session_state, 594 const scoped_refptr<MemoryDumpSessionState>& session_state,
637 MemoryDumpCallback callback, 595 MemoryDumpCallback callback,
638 const scoped_refptr<SingleThreadTaskRunner>& dump_thread_task_runner) 596 const scoped_refptr<SingleThreadTaskRunner>& dump_thread_task_runner)
639 : req_args(req_args), 597 : req_args(req_args),
640 next_dump_provider(next_dump_provider),
641 session_state(session_state), 598 session_state(session_state),
642 callback(callback), 599 callback(callback),
643 callback_task_runner(MessageLoop::current()->task_runner()), 600 callback_task_runner(MessageLoop::current()->task_runner()),
644 dump_thread_task_runner(dump_thread_task_runner) {} 601 dump_thread_task_runner(dump_thread_task_runner) {
602 pending_dump_providers.reserve(dump_providers.size());
603 pending_dump_providers.assign(dump_providers.rbegin(), dump_providers.rend());
604 }
645 605
646 MemoryDumpManager::ProcessMemoryDumpAsyncState::~ProcessMemoryDumpAsyncState() { 606 MemoryDumpManager::ProcessMemoryDumpAsyncState::~ProcessMemoryDumpAsyncState() {
647 } 607 }
648 608
649 ProcessMemoryDump* MemoryDumpManager::ProcessMemoryDumpAsyncState:: 609 ProcessMemoryDump* MemoryDumpManager::ProcessMemoryDumpAsyncState::
650 GetOrCreateMemoryDumpContainerForProcess(ProcessId pid) { 610 GetOrCreateMemoryDumpContainerForProcess(ProcessId pid) {
651 auto iter = process_dumps.find(pid); 611 auto iter = process_dumps.find(pid);
652 if (iter == process_dumps.end()) { 612 if (iter == process_dumps.end()) {
653 scoped_ptr<ProcessMemoryDump> new_pmd(new ProcessMemoryDump(session_state)); 613 scoped_ptr<ProcessMemoryDump> new_pmd(new ProcessMemoryDump(session_state));
654 iter = process_dumps.insert(std::make_pair(pid, std::move(new_pmd))).first; 614 iter = process_dumps.insert(std::make_pair(pid, std::move(new_pmd))).first;
655 } 615 }
656 return iter->second.get(); 616 return iter->second.get();
657 } 617 }
658 618
659 } // namespace trace_event 619 } // namespace trace_event
660 } // namespace base 620 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698