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 |
Primiano Tucci (use gerrit)
2015/09/03 22:44:13
sorry realized only now. Isn't this going to do al
ssid
2015/09/04 10:43:47
Done.
| |
55 : MemoryDumpArgs::LevelOfDetail::LOW; | 53 : MemoryDumpArgs::LevelOfDetail::LOW; |
56 if (++g_periodic_dumps_count == kHeavyDumpsRate) | 54 |
55 if (g_heavy_dumps_rate > 0 && ++g_periodic_dumps_count == g_heavy_dumps_rate) | |
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 // Enable periodic dumps. At the moment the periodic support is limited to at | |
432 // most one low-detail periodic dump and at most one high-detail periodic | |
433 // dump. If both are specified the high-detail period must be an integer | |
434 // multiple of the low-level one. | |
435 g_periodic_dumps_count = 0; | |
436 const TraceConfig trace_config = | |
437 TraceLog::GetInstance()->GetCurrentTraceConfig(); | |
438 const TraceConfig::MemoryDumpConfig& config_list = | |
439 trace_config.memory_dump_config(); | |
440 if (config_list.empty()) | |
441 return; | |
442 | |
443 uint32 min_timer_period_ms = std::numeric_limits<uint32>::max(); | |
444 uint32 heavy_dump_period_ms = 0; | |
445 DCHECK_LE(config_list.size(), 2u); | |
446 for (const TraceConfig::MemoryDumpTriggerConfig& config : config_list) { | |
447 DCHECK(config.periodic_interval_ms); | |
448 if (config.level_of_detail == MemoryDumpArgs::LevelOfDetail::HIGH) | |
449 heavy_dump_period_ms = config.periodic_interval_ms; | |
450 min_timer_period_ms = | |
451 std::min(min_timer_period_ms, config.periodic_interval_ms); | |
452 } | |
453 DCHECK_EQ(0u, heavy_dump_period_ms % min_timer_period_ms); | |
454 g_heavy_dumps_rate = heavy_dump_period_ms / min_timer_period_ms; | |
455 | |
456 periodic_dump_timer_.Start(FROM_HERE, | |
457 TimeDelta::FromMilliseconds(min_timer_period_ms), | |
458 base::Bind(&RequestPeriodicGlobalDump)); | |
434 } | 459 } |
435 | 460 |
436 void MemoryDumpManager::OnTraceLogDisabled() { | 461 void MemoryDumpManager::OnTraceLogDisabled() { |
437 AutoLock lock(lock_); | 462 AutoLock lock(lock_); |
438 periodic_dump_timer_.Stop(); | 463 periodic_dump_timer_.Stop(); |
439 subtle::NoBarrier_Store(&memory_tracing_enabled_, 0); | 464 subtle::NoBarrier_Store(&memory_tracing_enabled_, 0); |
440 session_state_ = nullptr; | 465 session_state_ = nullptr; |
441 } | 466 } |
442 | 467 |
443 uint64 MemoryDumpManager::GetTracingProcessId() const { | 468 uint64 MemoryDumpManager::GetTracingProcessId() const { |
(...skipping 29 matching lines...) Expand all Loading... | |
473 next_dump_provider(next_dump_provider), | 498 next_dump_provider(next_dump_provider), |
474 callback(callback), | 499 callback(callback), |
475 task_runner(MessageLoop::current()->task_runner()) { | 500 task_runner(MessageLoop::current()->task_runner()) { |
476 } | 501 } |
477 | 502 |
478 MemoryDumpManager::ProcessMemoryDumpAsyncState::~ProcessMemoryDumpAsyncState() { | 503 MemoryDumpManager::ProcessMemoryDumpAsyncState::~ProcessMemoryDumpAsyncState() { |
479 } | 504 } |
480 | 505 |
481 } // namespace trace_event | 506 } // namespace trace_event |
482 } // namespace base | 507 } // namespace base |
OLD | NEW |