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

Unified Diff: base/trace_event/memory_dump_scheduler.cc

Issue 2778313002: [memory-infra] Move periodic timer to dump thread
Patch Set: nits. Created 3 years, 9 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/trace_event/memory_dump_scheduler.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/trace_event/memory_dump_scheduler.cc
diff --git a/base/trace_event/memory_dump_scheduler.cc b/base/trace_event/memory_dump_scheduler.cc
index 66ea6c9f1aeb5dd98b8af1ac43d11a26b0d025be..9f34f948394900fc3079cfd278231a7f6b3f6ccc 100644
--- a/base/trace_event/memory_dump_scheduler.cc
+++ b/base/trace_event/memory_dump_scheduler.cc
@@ -22,6 +22,9 @@ uint32_t g_polling_interval_ms_for_testing = 0;
} // namespace
// static
+bool MemoryDumpScheduler::periodic_timer_disabled_for_testing_ = false;
+
+// static
MemoryDumpScheduler* MemoryDumpScheduler::GetInstance() {
static MemoryDumpScheduler* instance = new MemoryDumpScheduler();
return instance;
@@ -88,8 +91,17 @@ void MemoryDumpScheduler::EnablePeriodicTriggerIfNeeded() {
periodic_state_->min_timer_period_ms;
periodic_state_->heavy_dumps_rate = periodic_state_->heavy_dump_period_ms /
periodic_state_->min_timer_period_ms;
-
periodic_state_->dump_count = 0;
+ periodic_state_->is_enabled_for_testing = true;
+
+ if (periodic_timer_disabled_for_testing_)
+ return;
+ polling_task_runner_->PostTask(
+ FROM_HERE, Bind(&MemoryDumpScheduler::EnablePeriodicTimerOnPollingThread,
+ Unretained(this)));
+}
+
+void MemoryDumpScheduler::EnablePeriodicTimerOnPollingThread() {
periodic_state_->timer.Start(
FROM_HERE,
TimeDelta::FromMilliseconds(periodic_state_->min_timer_period_ms),
@@ -127,23 +139,22 @@ void MemoryDumpScheduler::NotifyDumpTriggered() {
}
void MemoryDumpScheduler::DisableAllTriggers() {
- if (periodic_state_) {
- if (periodic_state_->timer.IsRunning())
- periodic_state_->timer.Stop();
- periodic_state_.reset();
- }
-
if (polling_task_runner_) {
- DCHECK(polling_state_);
polling_task_runner_->PostTask(
- FROM_HERE, Bind(&MemoryDumpScheduler::DisablePollingOnPollingThread,
+ FROM_HERE, Bind(&MemoryDumpScheduler::DisableTriggersOnPollingThread,
Unretained(this)));
polling_task_runner_ = nullptr;
}
is_setup_ = false;
}
-void MemoryDumpScheduler::DisablePollingOnPollingThread() {
+void MemoryDumpScheduler::DisableTriggersOnPollingThread() {
+ if (periodic_state_) {
+ if (periodic_state_->timer.IsRunning())
+ periodic_state_->timer.Stop();
+ periodic_state_.reset();
+ }
+
polling_state_->current_state = PollingTriggerState::DISABLED;
polling_state_.reset();
}
@@ -153,11 +164,19 @@ void MemoryDumpScheduler::SetPollingIntervalForTesting(uint32_t interval) {
g_polling_interval_ms_for_testing = interval;
}
+void MemoryDumpScheduler::DisablePeriodicTimerForTesting(bool disable) {
+ periodic_timer_disabled_for_testing_ = disable;
+}
+
bool MemoryDumpScheduler::IsPeriodicTimerRunningForTesting() {
- return periodic_state_->timer.IsRunning();
+ return periodic_state_->is_enabled_for_testing;
}
void MemoryDumpScheduler::RequestPeriodicGlobalDump() {
+ // In case it's called after timer stopped.
+ if (!periodic_state_)
+ return;
+
MemoryDumpLevelOfDetail level_of_detail = MemoryDumpLevelOfDetail::BACKGROUND;
if (periodic_state_->light_dumps_rate > 0 &&
periodic_state_->dump_count % periodic_state_->light_dumps_rate == 0)
@@ -171,7 +190,7 @@ void MemoryDumpScheduler::RequestPeriodicGlobalDump() {
}
void MemoryDumpScheduler::PollMemoryOnPollingThread() {
- if (polling_state_->current_state != PollingTriggerState::ENABLED)
+ if (!polling_state_)
return;
uint64_t polled_memory = 0;
@@ -273,7 +292,8 @@ MemoryDumpScheduler::PeriodicTriggerState::PeriodicTriggerState()
light_dumps_rate(0),
heavy_dumps_rate(0),
light_dump_period_ms(0),
- heavy_dump_period_ms(0) {}
+ heavy_dump_period_ms(0),
+ is_enabled_for_testing(false) {}
MemoryDumpScheduler::PeriodicTriggerState::~PeriodicTriggerState() {
DCHECK(!timer.IsRunning());
« no previous file with comments | « base/trace_event/memory_dump_scheduler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698