OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <string> | 5 #include <string> |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 base::TimeDelta::FromMilliseconds( | 203 base::TimeDelta::FromMilliseconds( |
204 base::RandGenerator(kMaxResumeCollectionDelayMs)); | 204 base::RandGenerator(kMaxResumeCollectionDelayMs)); |
205 timer_.Start(FROM_HERE, | 205 timer_.Start(FROM_HERE, |
206 collection_delay, | 206 collection_delay, |
207 base::Bind(&PerfProvider::CollectPerfDataAfterResume, | 207 base::Bind(&PerfProvider::CollectPerfDataAfterResume, |
208 weak_factory_.GetWeakPtr(), | 208 weak_factory_.GetWeakPtr(), |
209 sleep_duration, | 209 sleep_duration, |
210 collection_delay)); | 210 collection_delay)); |
211 } | 211 } |
212 | 212 |
213 void PerfProvider::OnSessionRestoreDone() { | 213 void PerfProvider::OnSessionRestoreDone(int num_tabs_restored) { |
214 // Do not collect a profile unless logged in as a normal user. | 214 // Do not collect a profile unless logged in as a normal user. |
215 if (!IsNormalUserLoggedIn()) | 215 if (!IsNormalUserLoggedIn()) |
216 return; | 216 return; |
217 | 217 |
218 // Collect a profile only 1/|kRestoreSessionSamplingFactor| of the time, to | 218 // Collect a profile only 1/|kRestoreSessionSamplingFactor| of the time, to |
219 // avoid collecting too much data and potentially causing UI latency. | 219 // avoid collecting too much data and potentially causing UI latency. |
220 if (base::RandGenerator(kRestoreSessionSamplingFactor) != 0) | 220 if (base::RandGenerator(kRestoreSessionSamplingFactor) != 0) |
221 return; | 221 return; |
222 | 222 |
223 const base::TimeDelta min_interval = | 223 const base::TimeDelta min_interval = |
(...skipping 14 matching lines...) Expand all Loading... |
238 | 238 |
239 // Randomly pick a delay before doing the collection. | 239 // Randomly pick a delay before doing the collection. |
240 base::TimeDelta collection_delay = | 240 base::TimeDelta collection_delay = |
241 base::TimeDelta::FromMilliseconds( | 241 base::TimeDelta::FromMilliseconds( |
242 base::RandGenerator(kMaxRestoreSessionCollectionDelayMs)); | 242 base::RandGenerator(kMaxRestoreSessionCollectionDelayMs)); |
243 timer_.Start( | 243 timer_.Start( |
244 FROM_HERE, | 244 FROM_HERE, |
245 collection_delay, | 245 collection_delay, |
246 base::Bind(&PerfProvider::CollectPerfDataAfterSessionRestore, | 246 base::Bind(&PerfProvider::CollectPerfDataAfterSessionRestore, |
247 weak_factory_.GetWeakPtr(), | 247 weak_factory_.GetWeakPtr(), |
248 collection_delay)); | 248 collection_delay, |
| 249 num_tabs_restored)); |
249 } | 250 } |
250 | 251 |
251 void PerfProvider::OnUserLoggedIn() { | 252 void PerfProvider::OnUserLoggedIn() { |
252 login_time_ = base::TimeTicks::Now(); | 253 login_time_ = base::TimeTicks::Now(); |
253 ScheduleIntervalCollection(); | 254 ScheduleIntervalCollection(); |
254 } | 255 } |
255 | 256 |
256 void PerfProvider::Deactivate() { | 257 void PerfProvider::Deactivate() { |
257 // Stop the timer, but leave |cached_perf_data_| intact. | 258 // Stop the timer, but leave |cached_perf_data_| intact. |
258 timer_.Stop(); | 259 timer_.Stop(); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
340 // Fill out a SampledProfile protobuf that will contain the collected data. | 341 // Fill out a SampledProfile protobuf that will contain the collected data. |
341 scoped_ptr<SampledProfile> sampled_profile(new SampledProfile); | 342 scoped_ptr<SampledProfile> sampled_profile(new SampledProfile); |
342 sampled_profile->set_trigger_event(SampledProfile::RESUME_FROM_SUSPEND); | 343 sampled_profile->set_trigger_event(SampledProfile::RESUME_FROM_SUSPEND); |
343 sampled_profile->set_suspend_duration_ms(sleep_duration.InMilliseconds()); | 344 sampled_profile->set_suspend_duration_ms(sleep_duration.InMilliseconds()); |
344 sampled_profile->set_ms_after_resume(time_after_resume.InMilliseconds()); | 345 sampled_profile->set_ms_after_resume(time_after_resume.InMilliseconds()); |
345 | 346 |
346 CollectIfNecessary(sampled_profile.Pass()); | 347 CollectIfNecessary(sampled_profile.Pass()); |
347 } | 348 } |
348 | 349 |
349 void PerfProvider::CollectPerfDataAfterSessionRestore( | 350 void PerfProvider::CollectPerfDataAfterSessionRestore( |
350 const base::TimeDelta& time_after_restore) { | 351 const base::TimeDelta& time_after_restore, |
| 352 int num_tabs_restored) { |
351 // Fill out a SampledProfile protobuf that will contain the collected data. | 353 // Fill out a SampledProfile protobuf that will contain the collected data. |
352 scoped_ptr<SampledProfile> sampled_profile(new SampledProfile); | 354 scoped_ptr<SampledProfile> sampled_profile(new SampledProfile); |
353 sampled_profile->set_trigger_event(SampledProfile::RESTORE_SESSION); | 355 sampled_profile->set_trigger_event(SampledProfile::RESTORE_SESSION); |
354 sampled_profile->set_ms_after_restore(time_after_restore.InMilliseconds()); | 356 sampled_profile->set_ms_after_restore(time_after_restore.InMilliseconds()); |
| 357 sampled_profile->set_num_tabs_restored(num_tabs_restored); |
355 | 358 |
356 CollectIfNecessary(sampled_profile.Pass()); | 359 CollectIfNecessary(sampled_profile.Pass()); |
357 last_session_restore_collection_time_ = base::TimeTicks::Now(); | 360 last_session_restore_collection_time_ = base::TimeTicks::Now(); |
358 } | 361 } |
359 | 362 |
360 void PerfProvider::ParseProtoIfValid( | 363 void PerfProvider::ParseProtoIfValid( |
361 scoped_ptr<WindowedIncognitoObserver> incognito_observer, | 364 scoped_ptr<WindowedIncognitoObserver> incognito_observer, |
362 scoped_ptr<SampledProfile> sampled_profile, | 365 scoped_ptr<SampledProfile> sampled_profile, |
363 const std::vector<uint8>& data) { | 366 const std::vector<uint8>& data) { |
364 DCHECK(CalledOnValidThread()); | 367 DCHECK(CalledOnValidThread()); |
(...skipping 22 matching lines...) Expand all Loading... |
387 DCHECK(!login_time_.is_null()); | 390 DCHECK(!login_time_.is_null()); |
388 collection_data. | 391 collection_data. |
389 set_ms_after_login((base::TimeTicks::Now() - login_time_) | 392 set_ms_after_login((base::TimeTicks::Now() - login_time_) |
390 .InMilliseconds()); | 393 .InMilliseconds()); |
391 | 394 |
392 // Finally, store the perf data itself. | 395 // Finally, store the perf data itself. |
393 collection_data.mutable_perf_data()->Swap(&perf_data_proto); | 396 collection_data.mutable_perf_data()->Swap(&perf_data_proto); |
394 } | 397 } |
395 | 398 |
396 } // namespace metrics | 399 } // namespace metrics |
OLD | NEW |