Chromium Code Reviews| Index: chrome/browser/metrics/perf_provider_chromeos.cc |
| diff --git a/chrome/browser/metrics/perf_provider_chromeos.cc b/chrome/browser/metrics/perf_provider_chromeos.cc |
| index 72bf423077d56459d7769b1bbbee2b0a13fd5c2b..1ca0ccf9afede4cb7b420de86cbf5962d57e0f90 100644 |
| --- a/chrome/browser/metrics/perf_provider_chromeos.cc |
| +++ b/chrome/browser/metrics/perf_provider_chromeos.cc |
| @@ -54,6 +54,16 @@ const int kRestoreSessionSamplingFactor = 10; |
| // much time between collections. The current value is 30 seconds. |
| const int kMinIntervalBetweenSessionRestoreCollectionsMs = 30 * 1000; |
| +// If collecting after a resume, add a random delay before collecting. The delay |
| +// should be randomly selected between 0 and this value. Currently the value is |
| +// equal to 5 seconds. |
| +const int kMaxResumeCollectionDelayMs = 5 * 1000; |
| + |
| +// If collecting after a session restore, add a random delay before collecting. |
| +// The delay should be randomly selected between 0 and this value. Currently the |
| +// value is equal to 10 seconds. |
| +const int kMaxRestoreSessionCollectionDelayMs = 10 * 1000; |
| + |
| // Enumeration representing success and various failure modes for collecting and |
| // sending perf data. |
| enum GetPerfDataOutcome { |
| @@ -185,19 +195,23 @@ void PerfProvider::SuspendDone(const base::TimeDelta& sleep_duration) { |
| if (!IsNormalUserLoggedIn()) |
| return; |
| + // Do not collect if there is an existing collection scheduled. |
| + if (resume_timer_.IsRunning()) |
| + return; |
| + |
| // Collect a profile only 1/|kResumeSamplingFactor| of the time, to avoid |
| // collecting too much data. |
| if (base::RandGenerator(kResumeSamplingFactor) != 0) |
| return; |
| - // Fill out a SampledProfile protobuf that will contain the collected data. |
| - scoped_ptr<SampledProfile> sampled_profile(new SampledProfile); |
| - sampled_profile->set_trigger_event(SampledProfile::RESUME_FROM_SUSPEND); |
| - sampled_profile->set_suspend_duration_ms(sleep_duration.InMilliseconds()); |
| - // TODO(sque): Vary the time after resume at which to collect a profile. |
| - // http://crbug.com/358778. |
| - sampled_profile->set_ms_after_resume(0); |
| - CollectIfNecessary(sampled_profile.Pass()); |
| + // Randomly pick a delay before doing the collection. |
| + uint64 collection_delay_ms = base::RandGenerator(kMaxResumeCollectionDelayMs); |
| + resume_timer_.Start(FROM_HERE, |
| + base::TimeDelta::FromMilliseconds(collection_delay_ms), |
| + base::Bind(&PerfProvider::DoResumeCollection, |
| + weak_factory_.GetWeakPtr(), |
| + sleep_duration.InMilliseconds(), |
| + collection_delay_ms)); |
| } |
| void PerfProvider::Observe(int type, |
| @@ -206,6 +220,10 @@ void PerfProvider::Observe(int type, |
| // Only handle session restore notifications. |
| DCHECK_EQ(type, chrome::NOTIFICATION_SESSION_RESTORE_DONE); |
| + // Do not collect if there is an existing collection scheduled. |
| + if (restore_session_timer_.IsRunning()) |
| + return; |
| + |
| // Collect a profile only 1/|kRestoreSessionSamplingFactor| of the time, to |
| // avoid collecting too much data and potentially causing UI latency. |
| if (base::RandGenerator(kRestoreSessionSamplingFactor) != 0) |
| @@ -223,16 +241,15 @@ void PerfProvider::Observe(int type, |
| return; |
| } |
| - // Fill out a SampledProfile protobuf that will contain the collected data. |
| - scoped_ptr<SampledProfile> sampled_profile(new SampledProfile); |
| - sampled_profile->set_trigger_event(SampledProfile::RESTORE_SESSION); |
| - // TODO(sque): Vary the time after restore at which to collect a profile, |
| - // and find a way to determine the number of tabs restored. |
| - // http://crbug.com/358778. |
| - sampled_profile->set_ms_after_restore(0); |
| - |
| - CollectIfNecessary(sampled_profile.Pass()); |
| - last_session_restore_collection_time_ = base::TimeTicks::Now(); |
| + // Randomly pick a delay before doing the collection. |
| + uint64 collection_delay_ms = |
| + base::RandGenerator(kMaxRestoreSessionCollectionDelayMs); |
| + restore_session_timer_.Start( |
| + FROM_HERE, |
| + base::TimeDelta::FromMilliseconds(collection_delay_ms), |
| + base::Bind(&PerfProvider::DoRestoreSessionCollection, |
| + weak_factory_.GetWeakPtr(), |
| + collection_delay_ms)); |
| } |
| void PerfProvider::OnUserLoggedIn() { |
| @@ -242,12 +259,12 @@ void PerfProvider::OnUserLoggedIn() { |
| void PerfProvider::Deactivate() { |
| // Stop the timer, but leave |cached_perf_data_| intact. |
| - timer_.Stop(); |
| + interval_timer_.Stop(); |
|
Ilya Sherman
2014/07/03 00:12:47
Should this stop the other timers as well? In fac
Simon Que
2014/07/07 19:45:26
Done. I think the three timers are needed so that
Ilya Sherman
2014/07/08 00:06:40
Why do the timers need to run independently?
|
| } |
| void PerfProvider::ScheduleCollection() { |
| DCHECK(CalledOnValidThread()); |
| - if (timer_.IsRunning()) |
| + if (interval_timer_.IsRunning()) |
| return; |
| // Pick a random time in the current interval. |
| @@ -262,8 +279,8 @@ void PerfProvider::ScheduleCollection() { |
| if (scheduled_time < now) |
| scheduled_time = now; |
| - timer_.Start(FROM_HERE, scheduled_time - now, this, |
| - &PerfProvider::DoPeriodicCollection); |
| + interval_timer_.Start(FROM_HERE, scheduled_time - now, this, |
| + &PerfProvider::DoPeriodicCollection); |
| // Update the profiling interval tracker to the start of the next interval. |
| next_profiling_interval_start_ += |
| @@ -316,6 +333,27 @@ void PerfProvider::DoPeriodicCollection() { |
| ScheduleCollection(); |
| } |
| +void PerfProvider::DoResumeCollection(uint64 sleep_duration_ms, |
| + uint64 time_after_resume_ms) { |
| + // Fill out a SampledProfile protobuf that will contain the collected data. |
| + scoped_ptr<SampledProfile> sampled_profile(new SampledProfile); |
| + sampled_profile->set_trigger_event(SampledProfile::RESUME_FROM_SUSPEND); |
| + sampled_profile->set_suspend_duration_ms(sleep_duration_ms); |
| + sampled_profile->set_ms_after_resume(time_after_resume_ms); |
| + |
| + CollectIfNecessary(sampled_profile.Pass()); |
| +} |
| + |
| +void PerfProvider::DoRestoreSessionCollection(uint64 time_after_restore_ms) { |
| + // Fill out a SampledProfile protobuf that will contain the collected data. |
| + scoped_ptr<SampledProfile> sampled_profile(new SampledProfile); |
| + sampled_profile->set_trigger_event(SampledProfile::RESTORE_SESSION); |
| + sampled_profile->set_ms_after_restore(time_after_restore_ms); |
| + |
| + CollectIfNecessary(sampled_profile.Pass()); |
| + last_session_restore_collection_time_ = base::TimeTicks::Now(); |
| +} |
| + |
| void PerfProvider::ParseProtoIfValid( |
| scoped_ptr<WindowedIncognitoObserver> incognito_observer, |
| scoped_ptr<SampledProfile> sampled_profile, |