| 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 if (g_heavy_dumps_rate == 0) { |
| 55 : MemoryDumpArgs::LevelOfDetail::LOW; | 53 dump_level_of_detail = MemoryDumpArgs::LevelOfDetail::LOW; |
| 56 if (++g_periodic_dumps_count == kHeavyDumpsRate) | 54 } else { |
| 57 g_periodic_dumps_count = 0; | 55 dump_level_of_detail = g_periodic_dumps_count == 0 |
| 56 ? MemoryDumpArgs::LevelOfDetail::HIGH |
| 57 : MemoryDumpArgs::LevelOfDetail::LOW; |
| 58 |
| 59 if (++g_periodic_dumps_count == g_heavy_dumps_rate) |
| 60 g_periodic_dumps_count = 0; |
| 61 } |
| 58 | 62 |
| 59 MemoryDumpArgs dump_args = {dump_level_of_detail}; | 63 MemoryDumpArgs dump_args = {dump_level_of_detail}; |
| 60 MemoryDumpManager::GetInstance()->RequestGlobalDump( | 64 MemoryDumpManager::GetInstance()->RequestGlobalDump( |
| 61 MemoryDumpType::PERIODIC_INTERVAL, dump_args); | 65 MemoryDumpType::PERIODIC_INTERVAL, dump_args); |
| 62 } | 66 } |
| 63 | 67 |
| 64 } // namespace | 68 } // namespace |
| 65 | 69 |
| 66 // static | 70 // static |
| 67 const char* const MemoryDumpManager::kTraceCategory = | 71 const char* const MemoryDumpManager::kTraceCategory = |
| (...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 | 416 |
| 413 session_state_ = new MemoryDumpSessionState(); | 417 session_state_ = new MemoryDumpSessionState(); |
| 414 for (auto it = dump_providers_.begin(); it != dump_providers_.end(); ++it) { | 418 for (auto it = dump_providers_.begin(); it != dump_providers_.end(); ++it) { |
| 415 it->disabled = false; | 419 it->disabled = false; |
| 416 it->consecutive_failures = 0; | 420 it->consecutive_failures = 0; |
| 417 } | 421 } |
| 418 | 422 |
| 419 subtle::NoBarrier_Store(&memory_tracing_enabled_, 1); | 423 subtle::NoBarrier_Store(&memory_tracing_enabled_, 1); |
| 420 | 424 |
| 421 // TODO(primiano): This is a temporary hack to disable periodic memory dumps | 425 // TODO(primiano): This is a temporary hack to disable periodic memory dumps |
| 422 // when running memory benchmarks until they can be enabled/disabled in | 426 // when running memory benchmarks until telemetry uses TraceConfig to |
| 423 // base::trace_event::TraceConfig. See https://goo.gl/5Hj3o0. | 427 // enable/disable periodic dumps. |
| 424 // The same mechanism should be used to disable periodic dumps in tests. | 428 // The same mechanism should be used to disable periodic dumps in tests. |
| 425 if (delegate_->IsCoordinatorProcess() && | 429 if (!delegate_->IsCoordinatorProcess() || |
| 426 !CommandLine::ForCurrentProcess()->HasSwitch( | 430 CommandLine::ForCurrentProcess()->HasSwitch( |
| 427 "enable-memory-benchmarking") && | 431 "enable-memory-benchmarking") || |
| 428 !disable_periodic_dumps_for_testing_) { | 432 disable_periodic_dumps_for_testing_) { |
| 429 g_periodic_dumps_count = 0; | 433 return; |
| 430 periodic_dump_timer_.Start(FROM_HERE, | |
| 431 TimeDelta::FromMilliseconds(kDumpIntervalMs), | |
| 432 base::Bind(&RequestPeriodicGlobalDump)); | |
| 433 } | 434 } |
| 435 |
| 436 // Enable periodic dumps. At the moment the periodic support is limited to at |
| 437 // most one low-detail periodic dump and at most one high-detail periodic |
| 438 // dump. If both are specified the high-detail period must be an integer |
| 439 // multiple of the low-level one. |
| 440 g_periodic_dumps_count = 0; |
| 441 const TraceConfig trace_config = |
| 442 TraceLog::GetInstance()->GetCurrentTraceConfig(); |
| 443 const TraceConfig::MemoryDumpConfig& config_list = |
| 444 trace_config.memory_dump_config(); |
| 445 if (config_list.empty()) |
| 446 return; |
| 447 |
| 448 uint32 min_timer_period_ms = std::numeric_limits<uint32>::max(); |
| 449 uint32 heavy_dump_period_ms = 0; |
| 450 DCHECK_LE(config_list.size(), 2u); |
| 451 for (const TraceConfig::MemoryDumpTriggerConfig& config : config_list) { |
| 452 DCHECK(config.periodic_interval_ms); |
| 453 if (config.level_of_detail == MemoryDumpArgs::LevelOfDetail::HIGH) |
| 454 heavy_dump_period_ms = config.periodic_interval_ms; |
| 455 min_timer_period_ms = |
| 456 std::min(min_timer_period_ms, config.periodic_interval_ms); |
| 457 } |
| 458 DCHECK_EQ(0u, heavy_dump_period_ms % min_timer_period_ms); |
| 459 g_heavy_dumps_rate = heavy_dump_period_ms / min_timer_period_ms; |
| 460 |
| 461 periodic_dump_timer_.Start(FROM_HERE, |
| 462 TimeDelta::FromMilliseconds(min_timer_period_ms), |
| 463 base::Bind(&RequestPeriodicGlobalDump)); |
| 434 } | 464 } |
| 435 | 465 |
| 436 void MemoryDumpManager::OnTraceLogDisabled() { | 466 void MemoryDumpManager::OnTraceLogDisabled() { |
| 437 AutoLock lock(lock_); | 467 AutoLock lock(lock_); |
| 438 periodic_dump_timer_.Stop(); | 468 periodic_dump_timer_.Stop(); |
| 439 subtle::NoBarrier_Store(&memory_tracing_enabled_, 0); | 469 subtle::NoBarrier_Store(&memory_tracing_enabled_, 0); |
| 440 session_state_ = nullptr; | 470 session_state_ = nullptr; |
| 441 } | 471 } |
| 442 | 472 |
| 443 uint64 MemoryDumpManager::GetTracingProcessId() const { | 473 uint64 MemoryDumpManager::GetTracingProcessId() const { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 473 next_dump_provider(next_dump_provider), | 503 next_dump_provider(next_dump_provider), |
| 474 callback(callback), | 504 callback(callback), |
| 475 task_runner(MessageLoop::current()->task_runner()) { | 505 task_runner(MessageLoop::current()->task_runner()) { |
| 476 } | 506 } |
| 477 | 507 |
| 478 MemoryDumpManager::ProcessMemoryDumpAsyncState::~ProcessMemoryDumpAsyncState() { | 508 MemoryDumpManager::ProcessMemoryDumpAsyncState::~ProcessMemoryDumpAsyncState() { |
| 479 } | 509 } |
| 480 | 510 |
| 481 } // namespace trace_event | 511 } // namespace trace_event |
| 482 } // namespace base | 512 } // namespace base |
| OLD | NEW |