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

Unified Diff: chrome/app/client_util.cc

Issue 23534009: Re-enable pre-read experiment as a finch field trial. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 4 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 | « no previous file | chrome/browser/chrome_browser_main.cc » ('j') | chrome/browser/chrome_browser_main.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/app/client_util.cc
diff --git a/chrome/app/client_util.cc b/chrome/app/client_util.cc
index 0d1c52cb3a433cdd80f85c38e5d36d5856891d6c..411ca6b4d24195796324481fc321ac39fec99eec 100644
--- a/chrome/app/client_util.cc
+++ b/chrome/app/client_util.cc
@@ -11,6 +11,8 @@
#include "base/file_version_info.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
+#include "base/rand_util.h" // For PreRead experiment.
+#include "base/sha1.h" // For PreRead experiment.
#include "base/strings/string16.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
@@ -37,6 +39,89 @@ typedef int (*DLL_MAIN)(HINSTANCE, sandbox::SandboxInterfaceInfo*);
typedef void (*RelaunchChromeBrowserWithNewCommandLineIfNeededFunc)();
+bool PreReadExpirementHasExpired() {
+ static const int kPreReadExpiryYear = 2014;
+ static const int kPreReadExpiryMonth = 7;
+ static const int kPreReadExpiryDay = 1;
+ static const char kBuildTimeStr[] = __DATE__ " " __TIME__;
+
+ // Get the timestamp of the build.
+ base::Time build_time;
+ bool result = base::Time::FromString(kBuildTimeStr, &build_time);
+ DCHECK(result);
+
+ // Get the timestamp at which the experiment expires.
+ base::Time::Exploded exploded = {0};
+ exploded.year = kPreReadExpiryYear;
+ exploded.month = kPreReadExpiryMonth;
+ exploded.day_of_month = kPreReadExpiryDay;
+ base::Time expiration_time = base::Time::FromLocalExploded(exploded);
+
+ // Return true if the experiment is expired.
+ return (build_time > expiration_time);
+}
+
+uint8 GetPreReadPercentage() {
+ // By default use the old behaviour: read 100%.
+ const uint8 kDefaultPercentage = 100;
+ COMPILE_ASSERT(kDefaultPercentage <= 100, default_percentage_too_large);
+ COMPILE_ASSERT(kDefaultPercentage % 5 == 0, default_percentage_not_mult_5);
+
+ scoped_ptr<base::Environment> env(base::Environment::Create());
+ env->SetVar(chrome::kPreReadEnvironmentVariable,
+ base::StringPrintf("%d%%-Default", kDefaultPercentage));
+
+ // If the expirement has expired use the default pre-read level.
+ if (PreReadExpirementHasExpired())
+ return kDefaultPercentage;
+
+ // If this user isn't reporting metrics, use the default pre-read leve.
Alexei Svitkine (slow) 2013/08/28 17:30:50 The general rule is to avoid giving different beha
Roger McFarlane (Chromium) 2013/08/29 15:28:37 Fair enough. I copied this "opt-out" logic from t
+ base::string16 metrics_id;
+ if (!GoogleUpdateSettings::GetMetricsId(&metrics_id) || metrics_id.empty())
+ return kDefaultPercentage;
+
+ // Otherwise, use the metrics id as the basis for deriving what level or
+ // pre-read to do. To interpret the metrics id as a random number we hash
+ // it and intepret the first 8 bytes of it as a unit-interval representing
+ // die-toss for being in the experiment population and the second 8 bytes
+ // as the die-toss for the experiment group.
+ unsigned char sha1_hash[base::kSHA1Length];
+ base::SHA1HashBytes(
+ reinterpret_cast<const unsigned char*>(metrics_id.c_str()),
Alexei Svitkine (slow) 2013/08/28 17:30:50 Do the results need to be persistent? i.e. does t
Roger McFarlane (Chromium) 2013/08/29 15:28:37 Yes, they need to be persistent. The OS pre-fetch
+ metrics_id.size() * sizeof(metrics_id[0]),
+ sha1_hash);
+ COMPILE_ASSERT(2 * sizeof(uint64) < sizeof(sha1_hash), need_more_data);
+ const uint64* population_bits = reinterpret_cast<uint64*>(&sha1_hash[0]);
+ const uint64* group_bits = population_bits + 1;
+
+ // We limit experiment populations to 1% of the Stable and 10% of the Beta
+ // and Dev channels.
+ double population = base::BitsToOpenEndedUnitInterval(*population_bits);
+ const string16 channel(GoogleUpdateSettings::GetChromeChannel(
+ GoogleUpdateSettings::IsSystemInstall()));
+ if ((channel == installer::kChromeChannelStable && population > 0.01) ||
+ ((channel == installer::kChromeChannelBeta ||
+ channel == installer::kChromeChannelDev) && population > 0.10)) {
+ return kDefaultPercentage;
+ }
+
+ // We divide the experiment population into groups pre-reading at 5 percent
+ // increments. This is 21 groups of 5 -- to include the range [100, 105) --
+ // rounded down to the nearest 5.
+ double group = base::BitsToOpenEndedUnitInterval(*group_bits);
+ uint8 percentage = static_cast<uint8>(group * 21.0) * 5;
+ DCHECK_GE(100, percentage);
+ DCHECK_EQ(0, percentage % 5);
+
+ const char* format_str =
+ (percentage == kDefaultPercentage) ? "%d%%-Control" : "%d%%";
+
+ env->SetVar(chrome::kPreReadEnvironmentVariable,
+ base::StringPrintf(format_str, percentage));
+
+ return percentage;
+}
+
// Expects that |dir| has a trailing backslash. |dir| is modified so it
// contains the full path that was tried. Caller must check for the return
// value not being null to determine if this path contains a valid dll.
@@ -57,9 +142,9 @@ HMODULE LoadChromeWithDirectory(string16* dir) {
// performs slightly better than 100%. On XP, pre-read is generally a
// performance loss.
if (!cmd_line.HasSwitch(switches::kProcessType)) {
- const size_t kStepSize = 1024 * 1024;
- uint8 percent = base::win::GetVersion() > base::win::VERSION_XP ? 25 : 0;
- ImagePreReader::PartialPreReadImage(dir->c_str(), percent, kStepSize);
+ static const size_t kStepSize = 1024 * 1024;
+ uint8 percentage = GetPreReadPercentage();
+ ImagePreReader::PartialPreReadImage(dir->c_str(), percentage, kStepSize);
}
#endif
« no previous file with comments | « no previous file | chrome/browser/chrome_browser_main.cc » ('j') | chrome/browser/chrome_browser_main.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698