Chromium Code Reviews| 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/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 31 | 31 |
| 32 #if defined(OS_WIN) | 32 #if defined(OS_WIN) |
| 33 #include "base/trace_event/winheap_dump_provider_win.h" | 33 #include "base/trace_event/winheap_dump_provider_win.h" |
| 34 #endif | 34 #endif |
| 35 | 35 |
| 36 namespace base { | 36 namespace base { |
| 37 namespace trace_event { | 37 namespace trace_event { |
| 38 | 38 |
| 39 namespace { | 39 namespace { |
| 40 | 40 |
| 41 // Throttle mmaps at a rate of once every kHeavyMmapsDumpsRate standard dumps. | |
| 42 const int kHeavyDumpsRate = 8; // 250 ms * 8 = 2000 ms. | |
| 43 const int kDumpIntervalMs = 250; | |
| 44 const int kTraceEventNumArgs = 1; | 41 const int kTraceEventNumArgs = 1; |
| 45 const char* kTraceEventArgNames[] = {"dumps"}; | 42 const char* kTraceEventArgNames[] = {"dumps"}; |
| 46 const unsigned char kTraceEventArgTypes[] = {TRACE_VALUE_TYPE_CONVERTABLE}; | 43 const unsigned char kTraceEventArgTypes[] = {TRACE_VALUE_TYPE_CONVERTABLE}; |
| 47 | 44 |
| 48 StaticAtomicSequenceNumber g_next_guid; | 45 StaticAtomicSequenceNumber g_next_guid; |
| 49 uint32 g_periodic_dumps_count = 0; | 46 uint32 g_periodic_dumps_count = 0; |
| 47 uint32 g_heavy_dumps_rate = 0; | |
| 50 MemoryDumpManager* g_instance_for_testing = nullptr; | 48 MemoryDumpManager* g_instance_for_testing = nullptr; |
| 51 | 49 |
| 52 void RequestPeriodicGlobalDump() { | 50 void RequestPeriodicGlobalDump() { |
| 53 MemoryDumpArgs::LevelOfDetail dump_level_of_detail = | 51 MemoryDumpArgs::LevelOfDetail dump_level_of_detail = |
| 54 g_periodic_dumps_count == 0 ? MemoryDumpArgs::LevelOfDetail::HIGH | 52 g_periodic_dumps_count == 0 ? MemoryDumpArgs::LevelOfDetail::HIGH |
| 55 : MemoryDumpArgs::LevelOfDetail::LOW; | 53 : MemoryDumpArgs::LevelOfDetail::LOW; |
| 56 if (++g_periodic_dumps_count == kHeavyDumpsRate) | 54 |
| 55 if (++g_periodic_dumps_count == g_heavy_dumps_rate) | |
|
Primiano Tucci (use gerrit)
2015/09/03 08:39:51
since g_heavy_dumps_rate can be 0 this should beco
ssid
2015/09/03 16:30:18
Done.
| |
| 57 g_periodic_dumps_count = 0; | 56 g_periodic_dumps_count = 0; |
| 58 | 57 |
| 59 MemoryDumpArgs dump_args = {dump_level_of_detail}; | 58 MemoryDumpArgs dump_args = {dump_level_of_detail}; |
| 60 MemoryDumpManager::GetInstance()->RequestGlobalDump( | 59 MemoryDumpManager::GetInstance()->RequestGlobalDump( |
| 61 MemoryDumpType::PERIODIC_INTERVAL, dump_args); | 60 MemoryDumpType::PERIODIC_INTERVAL, dump_args); |
| 62 } | 61 } |
| 63 | 62 |
| 64 } // namespace | 63 } // namespace |
| 65 | 64 |
| 66 // static | 65 // static |
| (...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 412 | 411 |
| 413 session_state_ = new MemoryDumpSessionState(); | 412 session_state_ = new MemoryDumpSessionState(); |
| 414 for (auto it = dump_providers_.begin(); it != dump_providers_.end(); ++it) { | 413 for (auto it = dump_providers_.begin(); it != dump_providers_.end(); ++it) { |
| 415 it->disabled = false; | 414 it->disabled = false; |
| 416 it->consecutive_failures = 0; | 415 it->consecutive_failures = 0; |
| 417 } | 416 } |
| 418 | 417 |
| 419 subtle::NoBarrier_Store(&memory_tracing_enabled_, 1); | 418 subtle::NoBarrier_Store(&memory_tracing_enabled_, 1); |
| 420 | 419 |
| 421 // TODO(primiano): This is a temporary hack to disable periodic memory dumps | 420 // TODO(primiano): This is a temporary hack to disable periodic memory dumps |
| 422 // when running memory benchmarks until they can be enabled/disabled in | 421 // when running memory benchmarks until telemetry uses TraceConfig to |
| 423 // base::trace_event::TraceConfig. See https://goo.gl/5Hj3o0. | 422 // enable/disable periodic dumps. |
| 424 // The same mechanism should be used to disable periodic dumps in tests. | 423 // The same mechanism should be used to disable periodic dumps in tests. |
| 425 if (delegate_->IsCoordinatorProcess() && | 424 if (!delegate_->IsCoordinatorProcess() || |
| 426 !CommandLine::ForCurrentProcess()->HasSwitch( | 425 CommandLine::ForCurrentProcess()->HasSwitch( |
| 427 "enable-memory-benchmarking") && | 426 "enable-memory-benchmarking") || |
| 428 !disable_periodic_dumps_for_testing_) { | 427 disable_periodic_dumps_for_testing_) { |
| 429 g_periodic_dumps_count = 0; | 428 return; |
| 430 periodic_dump_timer_.Start(FROM_HERE, | |
| 431 TimeDelta::FromMilliseconds(kDumpIntervalMs), | |
| 432 base::Bind(&RequestPeriodicGlobalDump)); | |
| 433 } | 429 } |
| 430 | |
| 431 g_periodic_dumps_count = 0; | |
|
Primiano Tucci (use gerrit)
2015/09/03 08:39:50
Please add a comment here saying:
// Enable perio
ssid
2015/09/03 16:30:18
Done.
| |
| 432 const TraceConfig trace_config = | |
| 433 TraceLog::GetInstance()->GetCurrentTraceConfig(); | |
| 434 const TraceConfig::MemoryDumpConfig& config_list = | |
| 435 trace_config.memory_dump_config(); | |
| 436 if (config_list.empty()) | |
| 437 return; | |
| 438 | |
| 439 uint32 timer_period_ms = std::numeric_limits<uint32>::max(); | |
|
Primiano Tucci (use gerrit)
2015/09/03 08:39:50
nit: rename to min_timer_period_ms;
ssid
2015/09/03 16:30:18
Done.
| |
| 440 uint32 heavy_dump_period_ms = 0; | |
|
Primiano Tucci (use gerrit)
2015/09/03 08:39:50
Also add a DCHECK_LE(config_list.size(), 2)
ssid
2015/09/03 16:30:18
Done.
| |
| 441 for (const TraceConfig::MemoryDumpTriggerConfig& config : config_list) { | |
| 442 if (config.level_of_detail == MemoryDumpArgs::LevelOfDetail::HIGH) | |
|
Primiano Tucci (use gerrit)
2015/09/03 08:39:50
Also add a:
if (config.periodic_interval_ms == 0)
ssid
2015/09/03 16:30:18
Done.
| |
| 443 heavy_dump_period_ms = config.periodic_interval_ms; | |
| 444 timer_period_ms = std::min(timer_period_ms, config.periodic_interval_ms); | |
| 445 } | |
| 446 DCHECK_EQ(0u, heavy_dump_period_ms % timer_period_ms); | |
| 447 g_heavy_dumps_rate = heavy_dump_period_ms / timer_period_ms; | |
| 448 | |
| 449 periodic_dump_timer_.Start(FROM_HERE, | |
| 450 TimeDelta::FromMilliseconds(timer_period_ms), | |
| 451 base::Bind(&RequestPeriodicGlobalDump)); | |
| 434 } | 452 } |
| 435 | 453 |
| 436 void MemoryDumpManager::OnTraceLogDisabled() { | 454 void MemoryDumpManager::OnTraceLogDisabled() { |
| 437 AutoLock lock(lock_); | 455 AutoLock lock(lock_); |
| 438 periodic_dump_timer_.Stop(); | 456 periodic_dump_timer_.Stop(); |
| 439 subtle::NoBarrier_Store(&memory_tracing_enabled_, 0); | 457 subtle::NoBarrier_Store(&memory_tracing_enabled_, 0); |
| 440 session_state_ = nullptr; | 458 session_state_ = nullptr; |
| 441 } | 459 } |
| 442 | 460 |
| 443 uint64 MemoryDumpManager::GetTracingProcessId() const { | 461 uint64 MemoryDumpManager::GetTracingProcessId() const { |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 473 next_dump_provider(next_dump_provider), | 491 next_dump_provider(next_dump_provider), |
| 474 callback(callback), | 492 callback(callback), |
| 475 task_runner(MessageLoop::current()->task_runner()) { | 493 task_runner(MessageLoop::current()->task_runner()) { |
| 476 } | 494 } |
| 477 | 495 |
| 478 MemoryDumpManager::ProcessMemoryDumpAsyncState::~ProcessMemoryDumpAsyncState() { | 496 MemoryDumpManager::ProcessMemoryDumpAsyncState::~ProcessMemoryDumpAsyncState() { |
| 479 } | 497 } |
| 480 | 498 |
| 481 } // namespace trace_event | 499 } // namespace trace_event |
| 482 } // namespace base | 500 } // namespace base |
| OLD | NEW |