OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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_scheduler.h" | 5 #include "base/trace_event/memory_dump_scheduler.h" |
6 | 6 |
7 #include "base/process/process_metrics.h" | 7 #include "base/process/process_metrics.h" |
8 #include "base/single_thread_task_runner.h" | 8 #include "base/single_thread_task_runner.h" |
9 #include "base/threading/thread_task_runner_handle.h" | 9 #include "base/threading/thread_task_runner_handle.h" |
10 #include "base/trace_event/memory_dump_manager.h" | 10 #include "base/trace_event/memory_dump_manager.h" |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 | 98 |
99 void MemoryDumpScheduler::EnablePollingIfNeeded() { | 99 void MemoryDumpScheduler::EnablePollingIfNeeded() { |
100 DCHECK(is_setup_); | 100 DCHECK(is_setup_); |
101 if (polling_state_->current_state != PollingTriggerState::CONFIGURED) | 101 if (polling_state_->current_state != PollingTriggerState::CONFIGURED) |
102 return; | 102 return; |
103 | 103 |
104 polling_state_->current_state = PollingTriggerState::ENABLED; | 104 polling_state_->current_state = PollingTriggerState::ENABLED; |
105 polling_state_->ResetTotals(); | 105 polling_state_->ResetTotals(); |
106 | 106 |
107 polling_task_runner_->PostTask( | 107 polling_task_runner_->PostTask( |
108 FROM_HERE, | 108 FROM_HERE, BindOnce(&MemoryDumpScheduler::PollMemoryOnPollingThread, |
109 Bind(&MemoryDumpScheduler::PollMemoryOnPollingThread, Unretained(this))); | 109 Unretained(this))); |
110 } | 110 } |
111 | 111 |
112 void MemoryDumpScheduler::NotifyDumpTriggered() { | 112 void MemoryDumpScheduler::NotifyDumpTriggered() { |
113 if (polling_task_runner_ && | 113 if (polling_task_runner_ && |
114 !polling_task_runner_->RunsTasksOnCurrentThread()) { | 114 !polling_task_runner_->RunsTasksOnCurrentThread()) { |
115 polling_task_runner_->PostTask( | 115 polling_task_runner_->PostTask( |
116 FROM_HERE, | 116 FROM_HERE, |
117 Bind(&MemoryDumpScheduler::NotifyDumpTriggered, Unretained(this))); | 117 BindOnce(&MemoryDumpScheduler::NotifyDumpTriggered, Unretained(this))); |
118 return; | 118 return; |
119 } | 119 } |
120 | 120 |
121 if (!polling_state_ || | 121 if (!polling_state_ || |
122 polling_state_->current_state != PollingTriggerState::ENABLED) { | 122 polling_state_->current_state != PollingTriggerState::ENABLED) { |
123 return; | 123 return; |
124 } | 124 } |
125 | 125 |
126 polling_state_->ResetTotals(); | 126 polling_state_->ResetTotals(); |
127 } | 127 } |
128 | 128 |
129 void MemoryDumpScheduler::DisableAllTriggers() { | 129 void MemoryDumpScheduler::DisableAllTriggers() { |
130 if (periodic_state_) { | 130 if (periodic_state_) { |
131 if (periodic_state_->timer.IsRunning()) | 131 if (periodic_state_->timer.IsRunning()) |
132 periodic_state_->timer.Stop(); | 132 periodic_state_->timer.Stop(); |
133 periodic_state_.reset(); | 133 periodic_state_.reset(); |
134 } | 134 } |
135 | 135 |
136 if (polling_task_runner_) { | 136 if (polling_task_runner_) { |
137 DCHECK(polling_state_); | 137 DCHECK(polling_state_); |
138 polling_task_runner_->PostTask( | 138 polling_task_runner_->PostTask( |
139 FROM_HERE, Bind(&MemoryDumpScheduler::DisablePollingOnPollingThread, | 139 FROM_HERE, BindOnce(&MemoryDumpScheduler::DisablePollingOnPollingThread, |
140 Unretained(this))); | 140 Unretained(this))); |
141 polling_task_runner_ = nullptr; | 141 polling_task_runner_ = nullptr; |
142 } | 142 } |
143 is_setup_ = false; | 143 is_setup_ = false; |
144 } | 144 } |
145 | 145 |
146 void MemoryDumpScheduler::DisablePollingOnPollingThread() { | 146 void MemoryDumpScheduler::DisablePollingOnPollingThread() { |
147 polling_state_->current_state = PollingTriggerState::DISABLED; | 147 polling_state_->current_state = PollingTriggerState::DISABLED; |
148 polling_state_.reset(); | 148 polling_state_.reset(); |
149 } | 149 } |
150 | 150 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 TRACE_EVENT_SCOPE_PROCESS, "total_usage_MB", | 190 TRACE_EVENT_SCOPE_PROCESS, "total_usage_MB", |
191 polled_memory / 1024 / 1024); | 191 polled_memory / 1024 / 1024); |
192 | 192 |
193 mdm_->RequestGlobalDump(MemoryDumpType::PEAK_MEMORY_USAGE, | 193 mdm_->RequestGlobalDump(MemoryDumpType::PEAK_MEMORY_USAGE, |
194 polling_state_->level_of_detail); | 194 polling_state_->level_of_detail); |
195 } | 195 } |
196 | 196 |
197 // TODO(ssid): Use RequestSchedulerCallback, crbug.com/607533. | 197 // TODO(ssid): Use RequestSchedulerCallback, crbug.com/607533. |
198 ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 198 ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
199 FROM_HERE, | 199 FROM_HERE, |
200 Bind(&MemoryDumpScheduler::PollMemoryOnPollingThread, Unretained(this)), | 200 BindOnce(&MemoryDumpScheduler::PollMemoryOnPollingThread, |
| 201 Unretained(this)), |
201 TimeDelta::FromMilliseconds(polling_state_->polling_interval_ms)); | 202 TimeDelta::FromMilliseconds(polling_state_->polling_interval_ms)); |
202 } | 203 } |
203 | 204 |
204 bool MemoryDumpScheduler::ShouldTriggerDump(uint64_t current_memory_total) { | 205 bool MemoryDumpScheduler::ShouldTriggerDump(uint64_t current_memory_total) { |
205 // This function tries to detect peak memory usage as discussed in | 206 // This function tries to detect peak memory usage as discussed in |
206 // https://goo.gl/0kOU4A. | 207 // https://goo.gl/0kOU4A. |
207 | 208 |
208 if (current_memory_total == 0) | 209 if (current_memory_total == 0) |
209 return false; | 210 return false; |
210 | 211 |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 last_memory_totals_kb[last_memory_totals_kb_index] * 1024; | 320 last_memory_totals_kb[last_memory_totals_kb_index] * 1024; |
320 } | 321 } |
321 num_polls_from_last_dump = 0; | 322 num_polls_from_last_dump = 0; |
322 for (uint32_t i = 0; i < kMaxNumMemorySamples; ++i) | 323 for (uint32_t i = 0; i < kMaxNumMemorySamples; ++i) |
323 last_memory_totals_kb[i] = 0; | 324 last_memory_totals_kb[i] = 0; |
324 last_memory_totals_kb_index = 0; | 325 last_memory_totals_kb_index = 0; |
325 } | 326 } |
326 | 327 |
327 } // namespace trace_event | 328 } // namespace trace_event |
328 } // namespace base | 329 } // namespace base |
OLD | NEW |