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

Side by Side Diff: chrome/app/client_util.cc

Issue 2814019: Experimental pre-reading optimization to run on perf bots... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | 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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 "chrome/app/breakpad_win.h" 8 #include "chrome/app/breakpad_win.h"
9 #include "chrome/app/client_util.h" 9 #include "chrome/app/client_util.h"
10 #include "chrome/common/chrome_switches.h" 10 #include "chrome/common/chrome_switches.h"
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 bool EnvQueryStr(const wchar_t* key_name, std::wstring* value) { 74 bool EnvQueryStr(const wchar_t* key_name, std::wstring* value) {
75 wchar_t out[128]; 75 wchar_t out[128];
76 DWORD count = sizeof(out)/sizeof(out[0]); 76 DWORD count = sizeof(out)/sizeof(out[0]);
77 DWORD rv = ::GetEnvironmentVariableW(key_name, out, count); 77 DWORD rv = ::GetEnvironmentVariableW(key_name, out, count);
78 if ((rv == 0) || (rv >= count)) 78 if ((rv == 0) || (rv >= count))
79 return false; 79 return false;
80 *value = out; 80 *value = out;
81 return true; 81 return true;
82 } 82 }
83 83
84 bool IsRunningHeadless() {
85 return (0 != ::GetEnvironmentVariableW(L"CHROME_HEADLESS", NULL, 0));
86 }
87
84 // Expects that |dir| has a trailing backslash. |dir| is modified so it 88 // Expects that |dir| has a trailing backslash. |dir| is modified so it
85 // contains the full path that was tried. Caller must check for the return 89 // contains the full path that was tried. Caller must check for the return
86 // value not being null to dermine if this path contains a valid dll. 90 // value not being null to dermine if this path contains a valid dll.
87 HMODULE LoadChromeWithDirectory(std::wstring* dir) { 91 HMODULE LoadChromeWithDirectory(std::wstring* dir) {
88 ::SetCurrentDirectoryW(dir->c_str()); 92 ::SetCurrentDirectoryW(dir->c_str());
89 #ifdef _WIN64 93 #ifdef _WIN64
90 const CommandLine& cmd_line = *CommandLine::ForCurrentProcess(); 94 const CommandLine& cmd_line = *CommandLine::ForCurrentProcess();
91 if ((cmd_line.GetSwitchValueASCII(switches::kProcessType) == 95 if ((cmd_line.GetSwitchValueASCII(switches::kProcessType) ==
92 switches::kNaClBrokerProcess) || 96 switches::kNaClBrokerProcess) ||
93 (cmd_line.GetSwitchValueASCII(switches::kProcessType) == 97 (cmd_line.GetSwitchValueASCII(switches::kProcessType) ==
94 switches::kNaClLoaderProcess)) { 98 switches::kNaClLoaderProcess)) {
95 // Load the 64-bit DLL when running in a 64-bit process. 99 // Load the 64-bit DLL when running in a 64-bit process.
96 dir->append(installer_util::kChromeNaCl64Dll); 100 dir->append(installer_util::kChromeNaCl64Dll);
97 } else { 101 } else {
98 // Only NaCl broker and loader can be launched as Win64 processes. 102 // Only NaCl broker and loader can be launched as Win64 processes.
99 NOTREACHED(); 103 NOTREACHED();
100 return NULL; 104 return NULL;
101 } 105 }
102 #else 106 #else
103 dir->append(installer_util::kChromeDll); 107 dir->append(installer_util::kChromeDll);
104 #endif 108 #endif
109
110 // Experimental pre-reading optimization
111 // The idea is to pre read significant portion of chrome.dll in advance
112 // so that subsequent hard page faults are avoided.
113 DWORD pre_read_size_mb = 0;
114 const CommandLine& cmd_line = *CommandLine::ForCurrentProcess();
115 if (!cmd_line.HasSwitch(switches::kProcessType) &&
116 (IsRunningHeadless() || InstallUtil::IsChromeFrameProcess())) {
117 HKEY key = NULL;
118 if (::RegOpenKeyEx(HKEY_CURRENT_USER, L"Software\\Google\\ChromeFrame",
119 0, KEY_QUERY_VALUE, &key) == ERROR_SUCCESS) {
120 DWORD unused = sizeof(pre_read_size_mb);
121 RegQueryValueEx(key, L"PreRead", NULL, NULL,
122 reinterpret_cast<LPBYTE>(&pre_read_size_mb), &unused);
123 RegCloseKey(key);
124 key = NULL;
125 } else {
126 pre_read_size_mb = 16; // Read in first 16 MB by default.
127 }
128 }
129
130 if (pre_read_size_mb) {
131 HANDLE chrome_dll = CreateFile(dir->c_str(),
132 GENERIC_READ,
133 FILE_SHARE_READ | FILE_SHARE_WRITE,
134 NULL,
135 OPEN_EXISTING,
136 FILE_FLAG_SEQUENTIAL_SCAN,
137 NULL);
138 if (chrome_dll == INVALID_HANDLE_VALUE) {
139 DWORD error = GetLastError();
140 DLOG(ERROR) << __FUNCTION__ << " CreateFile( "
141 << dir->c_str() << " ) failed. Error: " << error;
142 } else {
143 const size_t kChunkSize = 1024 * 1024; // 1 MB
144 void* buffer = VirtualAlloc(NULL, kChunkSize, MEM_COMMIT, PAGE_READWRITE);
145 if (buffer) {
146 size_t read_size = pre_read_size_mb * kChunkSize;
147 DWORD read = 0;
148 while (::ReadFile(chrome_dll, buffer, kChunkSize, &read, NULL)) {
149 // nothing to do here...
150 read_size -= std::min(size_t(read), read_size);
151 if (!read || !read_size)
152 break;
153 }
154
155 VirtualFree(buffer, 0, MEM_RELEASE);
156 }
157
158 CloseHandle(chrome_dll);
159 }
160 }
161
105 return ::LoadLibraryExW(dir->c_str(), NULL, 162 return ::LoadLibraryExW(dir->c_str(), NULL,
106 LOAD_WITH_ALTERED_SEARCH_PATH); 163 LOAD_WITH_ALTERED_SEARCH_PATH);
107 } 164 }
108 165
109 // Set did_run "dr" in omaha's client state for this product. 166 // Set did_run "dr" in omaha's client state for this product.
110 bool SetDidRunState(const wchar_t* guid, const wchar_t* value) { 167 bool SetDidRunState(const wchar_t* guid, const wchar_t* value) {
111 std::wstring key_path(google_update::kRegPathClientState); 168 std::wstring key_path(google_update::kRegPathClientState);
112 key_path.append(L"\\").append(guid); 169 key_path.append(L"\\").append(guid);
113 HKEY reg_key; 170 HKEY reg_key;
114 if (::RegCreateKeyExW(HKEY_CURRENT_USER, key_path.c_str(), 0, NULL, 171 if (::RegCreateKeyExW(HKEY_CURRENT_USER, key_path.c_str(), 0, NULL,
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 } 309 }
253 }; 310 };
254 311
255 MainDllLoader* MakeMainDllLoader() { 312 MainDllLoader* MakeMainDllLoader() {
256 #if defined(GOOGLE_CHROME_BUILD) 313 #if defined(GOOGLE_CHROME_BUILD)
257 return new ChromeDllLoader(); 314 return new ChromeDllLoader();
258 #else 315 #else
259 return new ChromiumDllLoader(); 316 return new ChromiumDllLoader();
260 #endif 317 #endif
261 } 318 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698