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

Unified Diff: chrome/browser/metrics/perf_provider_chromeos.cc

Issue 364913007: metrics: Add random delays to perf collection (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Schedule next interval collection if collection never takes place Created 6 years, 5 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 | « chrome/browser/metrics/perf_provider_chromeos.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..e5245bf0a4b62b0f624fdf2e7bc5382da25f94a7 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 {
@@ -190,14 +200,20 @@ void PerfProvider::SuspendDone(const base::TimeDelta& sleep_duration) {
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());
+ // Override any existing profiling.
+ if (timer_.IsRunning())
+ timer_.Stop();
+
+ // Randomly pick a delay before doing the collection.
+ base::TimeDelta collection_delay =
+ base::TimeDelta::FromMilliseconds(
+ base::RandGenerator(kMaxResumeCollectionDelayMs));
+ timer_.Start(FROM_HERE,
+ collection_delay,
+ base::Bind(&PerfProvider::CollectPerfDataAfterResume,
+ weak_factory_.GetWeakPtr(),
+ sleep_duration,
+ collection_delay));
}
void PerfProvider::Observe(int type,
@@ -206,6 +222,10 @@ void PerfProvider::Observe(int type,
// Only handle session restore notifications.
DCHECK_EQ(type, chrome::NOTIFICATION_SESSION_RESTORE_DONE);
+ // Do not collect a profile unless logged in as a normal user.
+ if (!IsNormalUserLoggedIn())
+ 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,21 +243,25 @@ 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);
+ // Stop any existing scheduled collection.
+ if (timer_.IsRunning())
+ timer_.Stop();
- CollectIfNecessary(sampled_profile.Pass());
- last_session_restore_collection_time_ = base::TimeTicks::Now();
+ // Randomly pick a delay before doing the collection.
+ base::TimeDelta collection_delay =
+ base::TimeDelta::FromMilliseconds(
+ base::RandGenerator(kMaxRestoreSessionCollectionDelayMs));
+ timer_.Start(
+ FROM_HERE,
+ collection_delay,
+ base::Bind(&PerfProvider::CollectPerfDataAfterSessionRestore,
+ weak_factory_.GetWeakPtr(),
+ collection_delay));
}
void PerfProvider::OnUserLoggedIn() {
login_time_ = base::TimeTicks::Now();
- ScheduleCollection();
+ ScheduleIntervalCollection();
}
void PerfProvider::Deactivate() {
@@ -245,7 +269,7 @@ void PerfProvider::Deactivate() {
timer_.Stop();
}
-void PerfProvider::ScheduleCollection() {
+void PerfProvider::ScheduleIntervalCollection() {
DCHECK(CalledOnValidThread());
if (timer_.IsRunning())
return;
@@ -282,6 +306,8 @@ void PerfProvider::CollectIfNecessary(
}
if (cached_perf_data_size >= kCachedPerfDataProtobufSizeThreshold) {
AddToPerfHistogram(NOT_READY_TO_COLLECT);
+ // Schedule the next interval-based perf collection.
+ ScheduleIntervalCollection();
Ilya Sherman 2014/07/16 22:01:19 Why not just call this at the beginning of Collect
Simon Que 2014/07/16 22:26:54 Done.
return;
}
@@ -289,6 +315,8 @@ void PerfProvider::CollectIfNecessary(
// incognito session active (or gets spawned during the collection).
if (BrowserList::IsOffTheRecordSessionActive()) {
AddToPerfHistogram(INCOGNITO_ACTIVE);
+ // Schedule the next interval-based perf collection.
+ ScheduleIntervalCollection();
return;
}
@@ -313,7 +341,29 @@ void PerfProvider::DoPeriodicCollection() {
sampled_profile->set_trigger_event(SampledProfile::PERIODIC_COLLECTION);
CollectIfNecessary(sampled_profile.Pass());
- ScheduleCollection();
+}
+
+void PerfProvider::CollectPerfDataAfterResume(
+ const base::TimeDelta& sleep_duration,
+ const base::TimeDelta& time_after_resume) {
+ // 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());
+ sampled_profile->set_ms_after_resume(time_after_resume.InMilliseconds());
+
+ CollectIfNecessary(sampled_profile.Pass());
+}
+
+void PerfProvider::CollectPerfDataAfterSessionRestore(
+ const base::TimeDelta& time_after_restore) {
+ // 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.InMilliseconds());
+
+ CollectIfNecessary(sampled_profile.Pass());
+ last_session_restore_collection_time_ = base::TimeTicks::Now();
}
void PerfProvider::ParseProtoIfValid(
@@ -322,6 +372,12 @@ void PerfProvider::ParseProtoIfValid(
const std::vector<uint8>& data) {
DCHECK(CalledOnValidThread());
+ // Schedule another interval collection. This call makes sense regardless of
+ // whether or not the current collection was interval-triggered. If it had
+ // been another type of trigger event, the interval timer would have been
+ // halted, so it makes sense to reschedule a new interval collection.
+ ScheduleIntervalCollection();
+
if (incognito_observer->incognito_launched()) {
AddToPerfHistogram(INCOGNITO_LAUNCHED);
return;
« no previous file with comments | « chrome/browser/metrics/perf_provider_chromeos.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698