OLD | NEW |
---|---|
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 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
310 // straight away (FinalizeDumpAndAddToTrace() takes care of the callback). | 310 // straight away (FinalizeDumpAndAddToTrace() takes care of the callback). |
311 if (did_any_provider_dump && pmd_holder->num_pending_async_requests == 0) | 311 if (did_any_provider_dump && pmd_holder->num_pending_async_requests == 0) |
312 FinalizeDumpAndAddToTrace(pmd_holder); | 312 FinalizeDumpAndAddToTrace(pmd_holder); |
313 } | 313 } |
314 | 314 |
315 // Invokes the MemoryDumpProvider.OnMemoryDump(), taking care of the fail-safe | 315 // Invokes the MemoryDumpProvider.OnMemoryDump(), taking care of the fail-safe |
316 // logic which disables the dumper when failing (crbug.com/461788). | 316 // logic which disables the dumper when failing (crbug.com/461788). |
317 bool MemoryDumpManager::InvokeDumpProviderLocked(MemoryDumpProvider* mdp, | 317 bool MemoryDumpManager::InvokeDumpProviderLocked(MemoryDumpProvider* mdp, |
318 ProcessMemoryDump* pmd) { | 318 ProcessMemoryDump* pmd) { |
319 lock_.AssertAcquired(); | 319 lock_.AssertAcquired(); |
320 const int kMaxConsecutiveFailuresCount = 3; | |
320 bool dump_successful = mdp->OnMemoryDump(pmd); | 321 bool dump_successful = mdp->OnMemoryDump(pmd); |
322 MemoryDumpProviderInfo* mdp_info = &dump_providers_.find(mdp)->second; | |
321 if (!dump_successful) { | 323 if (!dump_successful) { |
322 LOG(ERROR) << "The memory dumper failed, possibly due to sandboxing " | 324 // Disable the MDP if it fails kMaxConsecutiveFailuresCount times |
323 "(crbug.com/461788), disabling it for current process. Try " | 325 // consecutively. |
324 "restarting chrome with the --no-sandbox switch."; | 326 mdp_info->consecutive_failures++; |
325 dump_providers_.find(mdp)->second.disabled = true; | 327 if (mdp_info->consecutive_failures >= kMaxConsecutiveFailuresCount) { |
328 mdp_info->disabled = true; | |
329 LOG(ERROR) << "The memory dumper failed, possibly due to sandboxing " | |
330 "(crbug.com/461788), disabling it for current process. Try " | |
331 "restarting chrome with the --no-sandbox switch."; | |
332 } | |
333 } else { | |
334 mdp_info->consecutive_failures = 0; | |
326 } | 335 } |
picksi
2015/06/16 12:56:44
nit: Removing the '!' and swapping the if/else bod
ssid
2015/06/16 14:52:35
Done.
| |
327 return dump_successful; | 336 return dump_successful; |
328 } | 337 } |
329 | 338 |
330 // This is posted to arbitrary threads as a continuation of CreateProcessDump(), | 339 // This is posted to arbitrary threads as a continuation of CreateProcessDump(), |
331 // when one or more MemoryDumpProvider(s) require the OnMemoryDump() call to | 340 // when one or more MemoryDumpProvider(s) require the OnMemoryDump() call to |
332 // happen on a different thread. | 341 // happen on a different thread. |
333 void MemoryDumpManager::ContinueAsyncProcessDump( | 342 void MemoryDumpManager::ContinueAsyncProcessDump( |
334 MemoryDumpProvider* mdp, | 343 MemoryDumpProvider* mdp, |
335 scoped_refptr<ProcessMemoryDumpHolder> pmd_holder) { | 344 scoped_refptr<ProcessMemoryDumpHolder> pmd_holder) { |
336 bool should_finalize_dump = false; | 345 bool should_finalize_dump = false; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
368 | 377 |
369 // There is no point starting the tracing without a delegate. | 378 // There is no point starting the tracing without a delegate. |
370 if (!enabled || !delegate_) { | 379 if (!enabled || !delegate_) { |
371 // Disable all the providers. | 380 // Disable all the providers. |
372 for (auto it = dump_providers_.begin(); it != dump_providers_.end(); ++it) | 381 for (auto it = dump_providers_.begin(); it != dump_providers_.end(); ++it) |
373 it->second.disabled = true; | 382 it->second.disabled = true; |
374 return; | 383 return; |
375 } | 384 } |
376 | 385 |
377 session_state_ = new MemoryDumpSessionState(); | 386 session_state_ = new MemoryDumpSessionState(); |
378 for (auto it = dump_providers_.begin(); it != dump_providers_.end(); ++it) | 387 for (auto it = dump_providers_.begin(); it != dump_providers_.end(); ++it) { |
379 it->second.disabled = false; | 388 it->second.disabled = false; |
389 it->second.consecutive_failures = 0; | |
390 } | |
380 | 391 |
381 subtle::NoBarrier_Store(&memory_tracing_enabled_, 1); | 392 subtle::NoBarrier_Store(&memory_tracing_enabled_, 1); |
382 | 393 |
383 if (delegate_->IsCoordinatorProcess()) { | 394 if (delegate_->IsCoordinatorProcess()) { |
384 periodic_dump_timer_.Start(FROM_HERE, | 395 periodic_dump_timer_.Start(FROM_HERE, |
385 TimeDelta::FromSeconds(kDumpIntervalSeconds), | 396 TimeDelta::FromSeconds(kDumpIntervalSeconds), |
386 base::Bind(&RequestPeriodicGlobalDump)); | 397 base::Bind(&RequestPeriodicGlobalDump)); |
387 } | 398 } |
388 } | 399 } |
389 | 400 |
390 void MemoryDumpManager::OnTraceLogDisabled() { | 401 void MemoryDumpManager::OnTraceLogDisabled() { |
391 AutoLock lock(lock_); | 402 AutoLock lock(lock_); |
392 periodic_dump_timer_.Stop(); | 403 periodic_dump_timer_.Stop(); |
393 subtle::NoBarrier_Store(&memory_tracing_enabled_, 0); | 404 subtle::NoBarrier_Store(&memory_tracing_enabled_, 0); |
394 session_state_ = nullptr; | 405 session_state_ = nullptr; |
395 } | 406 } |
396 | 407 |
397 MemoryDumpManager::MemoryDumpProviderInfo::MemoryDumpProviderInfo( | 408 MemoryDumpManager::MemoryDumpProviderInfo::MemoryDumpProviderInfo( |
398 const scoped_refptr<SingleThreadTaskRunner>& task_runner) | 409 const scoped_refptr<SingleThreadTaskRunner>& task_runner) |
399 : task_runner(task_runner), disabled(false) { | 410 : task_runner(task_runner), consecutive_failures(0), disabled(false) { |
400 } | 411 } |
401 MemoryDumpManager::MemoryDumpProviderInfo::~MemoryDumpProviderInfo() { | 412 MemoryDumpManager::MemoryDumpProviderInfo::~MemoryDumpProviderInfo() { |
402 } | 413 } |
403 | 414 |
404 } // namespace trace_event | 415 } // namespace trace_event |
405 } // namespace base | 416 } // namespace base |
OLD | NEW |