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

Side by Side 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: fix comment and rebase Created 7 years, 3 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 unified diff | Download patch
« no previous file with comments | « base/metrics/histogram.h ('k') | chrome/app/image_pre_reader_win.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <windows.h> 5 #include <windows.h>
6 #include <shlwapi.h> 6 #include <shlwapi.h>
7 7
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/debug/trace_event.h" 9 #include "base/debug/trace_event.h"
10 #include "base/environment.h" 10 #include "base/environment.h"
11 #include "base/file_version_info.h" 11 #include "base/file_version_info.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/rand_util.h" // For PreRead experiment.
15 #include "base/sha1.h" // For PreRead experiment.
14 #include "base/strings/string16.h" 16 #include "base/strings/string16.h"
15 #include "base/strings/string_util.h" 17 #include "base/strings/string_util.h"
16 #include "base/strings/stringprintf.h" 18 #include "base/strings/stringprintf.h"
17 #include "base/strings/utf_string_conversions.h" 19 #include "base/strings/utf_string_conversions.h"
18 #include "base/version.h" 20 #include "base/version.h"
19 #include "base/win/windows_version.h" 21 #include "base/win/windows_version.h"
20 #include "chrome/app/breakpad_win.h" 22 #include "chrome/app/breakpad_win.h"
21 #include "chrome/app/client_util.h" 23 #include "chrome/app/client_util.h"
22 #include "chrome/app/image_pre_reader_win.h" 24 #include "chrome/app/image_pre_reader_win.h"
23 #include "chrome/common/chrome_constants.h" 25 #include "chrome/common/chrome_constants.h"
24 #include "chrome/common/chrome_result_codes.h" 26 #include "chrome/common/chrome_result_codes.h"
25 #include "chrome/common/chrome_switches.h" 27 #include "chrome/common/chrome_switches.h"
26 #include "chrome/common/env_vars.h" 28 #include "chrome/common/env_vars.h"
27 #include "chrome/installer/util/browser_distribution.h" 29 #include "chrome/installer/util/browser_distribution.h"
28 #include "chrome/installer/util/channel_info.h" 30 #include "chrome/installer/util/channel_info.h"
29 #include "chrome/installer/util/google_update_constants.h" 31 #include "chrome/installer/util/google_update_constants.h"
30 #include "chrome/installer/util/google_update_settings.h" 32 #include "chrome/installer/util/google_update_settings.h"
31 #include "chrome/installer/util/install_util.h" 33 #include "chrome/installer/util/install_util.h"
32 #include "chrome/installer/util/util_constants.h" 34 #include "chrome/installer/util/util_constants.h"
33 35
34 namespace { 36 namespace {
35 // The entry point signature of chrome.dll. 37 // The entry point signature of chrome.dll.
36 typedef int (*DLL_MAIN)(HINSTANCE, sandbox::SandboxInterfaceInfo*); 38 typedef int (*DLL_MAIN)(HINSTANCE, sandbox::SandboxInterfaceInfo*);
37 39
38 typedef void (*RelaunchChromeBrowserWithNewCommandLineIfNeededFunc)(); 40 typedef void (*RelaunchChromeBrowserWithNewCommandLineIfNeededFunc)();
39 41
42 // Returns true if the build date for this module precedes the expiry date
43 // for the pre-read experiment.
44 bool PreReadExperimentIsActive() {
45 const int kPreReadExpiryYear = 2014;
46 const int kPreReadExpiryMonth = 7;
47 const int kPreReadExpiryDay = 1;
48 const char kBuildTimeStr[] = __DATE__ " " __TIME__;
49
50 // Get the timestamp of the build.
51 base::Time build_time;
52 bool result = base::Time::FromString(kBuildTimeStr, &build_time);
53 DCHECK(result);
54
55 // Get the timestamp at which the experiment expires.
56 base::Time::Exploded exploded = {0};
57 exploded.year = kPreReadExpiryYear;
58 exploded.month = kPreReadExpiryMonth;
59 exploded.day_of_month = kPreReadExpiryDay;
60 base::Time expiration_time = base::Time::FromLocalExploded(exploded);
61
62 // Return true if the build time predates the expiration time..
63 return build_time < expiration_time;
64 }
65
66 // Get random unit values, i.e., in the range (0, 1), denoting a die-toss for
67 // being in an experiment population and experimental group thereof.
68 void GetPreReadPopulationAndGroup(double* population, double* group) {
69 // By default we use the metrics id for the user as stable pseudo-random
70 // input to a hash.
71 base::string16 metrics_id;
72 GoogleUpdateSettings::GetMetricsId(&metrics_id);
73
74 // If this user has not metrics id, we fall back to a purely random value
75 // per browser session.
76 const size_t kLength = 16;
77 std::string random_value(metrics_id.empty() ? base::RandBytesAsString(kLength)
78 : base::WideToUTF8(metrics_id));
79
80 // To interpret the value as a random number we hash it and read the first 8
81 // bytes of the hash as a unit-interval representing a die-toss for being in
82 // the experiment population and the second 8 bytes as a die-toss for being
83 // in various experiment groups.
84 unsigned char sha1_hash[base::kSHA1Length];
85 base::SHA1HashBytes(
86 reinterpret_cast<const unsigned char*>(random_value.c_str()),
87 random_value.size() * sizeof(random_value[0]),
88 sha1_hash);
89 COMPILE_ASSERT(2 * sizeof(uint64) < sizeof(sha1_hash), need_more_data);
90 const uint64* random_bits = reinterpret_cast<uint64*>(&sha1_hash[0]);
91
92 // Convert the bits into unit-intervals and return.
93 *population = base::BitsToOpenEndedUnitInterval(random_bits[0]);
94 *group = base::BitsToOpenEndedUnitInterval(random_bits[1]);
95 }
96
97 // Gets the amount of pre-read to use as well as the experiment group in which
98 // the user falls.
99 size_t InitPreReadPercentage() {
100 // By default use the old behaviour: read 100%.
101 const int kDefaultPercentage = 100;
102 const char kDefaultFormatStr[] = "%d-pct-default";
103 const char kControlFormatStr[] = "%d-pct-control";
104 const char kGroupFormatStr[] = "%d-pct";
105
106 COMPILE_ASSERT(kDefaultPercentage <= 100, default_percentage_too_large);
107 COMPILE_ASSERT(kDefaultPercentage % 5 == 0, default_percentage_not_mult_5);
108
109 // Roll the dice to determine if this user is in the experiment and if so,
110 // in which experimental group.
111 double population = 0.0;
112 double group = 0.0;
113 GetPreReadPopulationAndGroup(&population, &group);
114
115 // We limit experiment populations to 1% of the Stable and 10% of each of
116 // the other channels.
117 const string16 channel(GoogleUpdateSettings::GetChromeChannel(
118 GoogleUpdateSettings::IsSystemInstall()));
119 double threshold = (channel == installer::kChromeChannelStable) ? 0.01 : 0.10;
120
121 // If the experiment has expired use the default pre-read level. Otherwise,
122 // those not in the experiment population also use the default pre-read level.
123 size_t value = kDefaultPercentage;
124 const char* format_str = kDefaultFormatStr;
125 if (PreReadExperimentIsActive() && (population <= threshold)) {
126 // We divide the experiment population into groups pre-reading at 5 percent
127 // increments in the range [0, 100].
128 value = static_cast<size_t>(group * 21.0) * 5;
129 DCHECK_LE(value, 100u);
130 DCHECK_EQ(0u, value % 5);
131 format_str =
132 (value == kDefaultPercentage) ? kControlFormatStr : kGroupFormatStr;
133 }
134
135 // Generate the group name corresponding to this percentage value.
136 std::string group_name;
137 base::SStringPrintf(&group_name, format_str, value);
138
139 // Persist the group name to the environment so that it can be used for
140 // reporting.
141 scoped_ptr<base::Environment> env(base::Environment::Create());
142 env->SetVar(chrome::kPreReadEnvironmentVariable, group_name);
143
144 // Return the percentage value to be used.
145 return value;
146 }
147
40 // Expects that |dir| has a trailing backslash. |dir| is modified so it 148 // Expects that |dir| has a trailing backslash. |dir| is modified so it
41 // contains the full path that was tried. Caller must check for the return 149 // contains the full path that was tried. Caller must check for the return
42 // value not being null to determine if this path contains a valid dll. 150 // value not being null to determine if this path contains a valid dll.
43 HMODULE LoadChromeWithDirectory(string16* dir) { 151 HMODULE LoadChromeWithDirectory(string16* dir) {
44 ::SetCurrentDirectoryW(dir->c_str()); 152 ::SetCurrentDirectoryW(dir->c_str());
45 const CommandLine& cmd_line = *CommandLine::ForCurrentProcess(); 153 const CommandLine& cmd_line = *CommandLine::ForCurrentProcess();
46 #if !defined(CHROME_MULTIPLE_DLL) 154 #if !defined(CHROME_MULTIPLE_DLL)
47 const wchar_t* dll_name = installer::kChromeDll; 155 const wchar_t* dll_name = installer::kChromeDll;
48 #else 156 #else
49 const wchar_t* dll_name = cmd_line.HasSwitch(switches::kProcessType) ? 157 const wchar_t* dll_name = cmd_line.HasSwitch(switches::kProcessType) ?
50 installer::kChromeChildDll : installer::kChromeDll; 158 installer::kChromeChildDll : installer::kChromeDll;
51 #endif 159 #endif
52 dir->append(dll_name); 160 dir->append(dll_name);
53 161
54 #if !defined(WIN_DISABLE_PREREAD) 162 #if !defined(WIN_DISABLE_PREREAD)
55 // On Win7 with Syzygy, pre-read is a win. There've very little difference 163 // We pre-read the binary to warm the memory caches (fewer hard faults to
56 // between 25% and 100%. For cold starts, with or without prefetch 25% 164 // page parts of the binary in).
57 // performs slightly better than 100%. On XP, pre-read is generally a
58 // performance loss.
59 if (!cmd_line.HasSwitch(switches::kProcessType)) { 165 if (!cmd_line.HasSwitch(switches::kProcessType)) {
60 const size_t kStepSize = 1024 * 1024; 166 const size_t kStepSize = 1024 * 1024;
61 // Pre-read 100% of the binary. This was the fallback behaviour for an 167 size_t percentage = InitPreReadPercentage();
62 // expired pre-read experiment as well as the standard behaviour before 168 ImagePreReader::PartialPreReadImage(dir->c_str(), percentage, kStepSize);
63 // the pre-read experiment. Performance regressed when the experiment
64 // (and fallback to 100%) was removed. See http://crbug/245435
65 // TODO(rogerm): Revive the pre-read experiment under finch.
66 uint8 percent = 100;
67 ImagePreReader::PartialPreReadImage(dir->c_str(), percent, kStepSize);
68 } 169 }
69 #endif 170 #endif
70 171
71 return ::LoadLibraryExW(dir->c_str(), NULL, 172 return ::LoadLibraryExW(dir->c_str(), NULL,
72 LOAD_WITH_ALTERED_SEARCH_PATH); 173 LOAD_WITH_ALTERED_SEARCH_PATH);
73 } 174 }
74 175
75 void RecordDidRun(const string16& dll_path) { 176 void RecordDidRun(const string16& dll_path) {
76 bool system_level = !InstallUtil::IsPerUserInstall(dll_path.c_str()); 177 bool system_level = !InstallUtil::IsPerUserInstall(dll_path.c_str());
77 GoogleUpdateSettings::UpdateDidRunState(true, system_level); 178 GoogleUpdateSettings::UpdateDidRunState(true, system_level);
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 } 344 }
244 }; 345 };
245 346
246 MainDllLoader* MakeMainDllLoader() { 347 MainDllLoader* MakeMainDllLoader() {
247 #if defined(GOOGLE_CHROME_BUILD) 348 #if defined(GOOGLE_CHROME_BUILD)
248 return new ChromeDllLoader(); 349 return new ChromeDllLoader();
249 #else 350 #else
250 return new ChromiumDllLoader(); 351 return new ChromiumDllLoader();
251 #endif 352 #endif
252 } 353 }
OLDNEW
« no previous file with comments | « base/metrics/histogram.h ('k') | chrome/app/image_pre_reader_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698