OLD | NEW |
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
9 #include "base/process_util.h" | 9 #include "base/process_util.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
11 #include "chrome/browser/net/url_fixer_upper.h" | 11 #include "chrome/browser/net/url_fixer_upper.h" |
12 #include "chrome/common/chrome_constants.h" | 12 #include "chrome/common/chrome_constants.h" |
13 #include "chrome/common/chrome_paths.h" | 13 #include "chrome/common/chrome_paths.h" |
14 #include "chrome/common/chrome_switches.h" | 14 #include "chrome/common/chrome_switches.h" |
15 #include "chrome/test/automation/tab_proxy.h" | 15 #include "chrome/test/automation/tab_proxy.h" |
16 #include "chrome/test/automation/window_proxy.h" | 16 #include "chrome/test/automation/window_proxy.h" |
17 #include "chrome/test/chrome_process_util.h" | 17 #include "chrome/test/chrome_process_util.h" |
18 #include "chrome/test/ui/ui_test.h" | 18 #include "chrome/test/ui/ui_test.h" |
19 #include "chrome/test/perf/mem_usage.h" | |
20 #include "googleurl/src/gurl.h" | 19 #include "googleurl/src/gurl.h" |
21 #include "net/base/net_util.h" | 20 #include "net/base/net_util.h" |
22 | 21 |
23 #ifndef NDEBUG | 22 #ifndef NDEBUG |
24 #define TEST_ITERATIONS "2" | 23 #define TEST_ITERATIONS "2" |
25 #else | 24 #else |
26 #define TEST_ITERATIONS "10" | 25 #define TEST_ITERATIONS "10" |
27 #endif | 26 #endif |
28 | 27 |
29 // URL at which data files may be found for HTTP tests. The document root of | 28 // URL at which data files may be found for HTTP tests. The document root of |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 | 76 |
78 std::string cookie; | 77 std::string cookie; |
79 ASSERT_TRUE(tab->GetCookieByName(test_url, "__pc_pages", &cookie)); | 78 ASSERT_TRUE(tab->GetCookieByName(test_url, "__pc_pages", &cookie)); |
80 pages->assign(UTF8ToWide(cookie)); | 79 pages->assign(UTF8ToWide(cookie)); |
81 ASSERT_FALSE(pages->empty()); | 80 ASSERT_FALSE(pages->empty()); |
82 ASSERT_TRUE(tab->GetCookieByName(test_url, "__pc_timings", &cookie)); | 81 ASSERT_TRUE(tab->GetCookieByName(test_url, "__pc_timings", &cookie)); |
83 timings->assign(cookie); | 82 timings->assign(cookie); |
84 ASSERT_FALSE(timings->empty()); | 83 ASSERT_FALSE(timings->empty()); |
85 } | 84 } |
86 | 85 |
87 #if defined(OS_WIN) | |
88 // TODO(port): Port chrome_process_util and remove windowsisms. | |
89 void PrintIOPerfInfo(const char* test_name) { | 86 void PrintIOPerfInfo(const char* test_name) { |
90 FilePath data_dir; | 87 FilePath data_dir; |
91 PathService::Get(chrome::DIR_USER_DATA, &data_dir); | 88 PathService::Get(chrome::DIR_USER_DATA, &data_dir); |
92 int browser_process_pid = ChromeBrowserProcessId(data_dir); | 89 int browser_process_pid = ChromeBrowserProcessId(data_dir); |
93 ChromeProcessList chrome_processes(GetRunningChromeProcesses(data_dir)); | 90 ChromeProcessList chrome_processes(GetRunningChromeProcesses(data_dir)); |
94 | 91 |
95 ChromeProcessList::const_iterator it; | 92 ChromeProcessList::const_iterator it; |
96 for (it = chrome_processes.begin(); it != chrome_processes.end(); ++it) { | 93 for (it = chrome_processes.begin(); it != chrome_processes.end(); ++it) { |
97 base::ProcessHandle process_handle; | 94 base::ProcessHandle process_handle; |
98 if (!base::OpenProcessHandle(*it, &process_handle)) { | 95 if (!base::OpenProcessHandle(*it, &process_handle)) { |
99 NOTREACHED(); | 96 NOTREACHED(); |
100 } | 97 } |
101 | 98 |
102 scoped_ptr<base::ProcessMetrics> process_metrics; | 99 scoped_ptr<base::ProcessMetrics> process_metrics; |
103 IO_COUNTERS io_counters; | |
104 process_metrics.reset( | 100 process_metrics.reset( |
105 base::ProcessMetrics::CreateProcessMetrics(process_handle)); | 101 base::ProcessMetrics::CreateProcessMetrics(process_handle)); |
106 ZeroMemory(&io_counters, sizeof(io_counters)); | 102 IoCounters io_counters; |
| 103 memset(&io_counters, 0, sizeof(io_counters)); |
107 | 104 |
108 if (process_metrics.get()->GetIOCounters(&io_counters)) { | 105 if (process_metrics.get()->GetIOCounters(&io_counters)) { |
109 // Print out IO performance. We assume that the values can be | 106 // Print out IO performance. We assume that the values can be |
110 // converted to size_t (they're reported as ULONGLONG, 64-bit numbers). | 107 // converted to size_t (they're reported as ULONGLONG, 64-bit numbers). |
111 std::string chrome_name = (*it == browser_process_pid) ? "_b" : "_r"; | 108 std::string chrome_name = (*it == browser_process_pid) ? "_b" : "_r"; |
112 | 109 |
113 PrintResult("read_op", chrome_name, | 110 PrintResult("read_op", chrome_name, |
114 "r_op" + chrome_name + test_name, | 111 "r_op" + chrome_name + test_name, |
115 static_cast<size_t>(io_counters.ReadOperationCount), "", | 112 static_cast<size_t>(io_counters.ReadOperationCount), "", |
116 false /* not important */); | 113 false /* not important */); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 } | 153 } |
157 | 154 |
158 void PrintMemoryUsageInfo(const char* test_name) { | 155 void PrintMemoryUsageInfo(const char* test_name) { |
159 FilePath data_dir; | 156 FilePath data_dir; |
160 PathService::Get(chrome::DIR_USER_DATA, &data_dir); | 157 PathService::Get(chrome::DIR_USER_DATA, &data_dir); |
161 int browser_process_pid = ChromeBrowserProcessId(data_dir); | 158 int browser_process_pid = ChromeBrowserProcessId(data_dir); |
162 ChromeProcessList chrome_processes(GetRunningChromeProcesses(data_dir)); | 159 ChromeProcessList chrome_processes(GetRunningChromeProcesses(data_dir)); |
163 | 160 |
164 ChromeProcessList::const_iterator it; | 161 ChromeProcessList::const_iterator it; |
165 for (it = chrome_processes.begin(); it != chrome_processes.end(); ++it) { | 162 for (it = chrome_processes.begin(); it != chrome_processes.end(); ++it) { |
166 size_t peak_virtual_size; | 163 base::ProcessHandle process_handle; |
167 size_t current_virtual_size; | 164 if (!base::OpenProcessHandle(*it, &process_handle)) { |
168 size_t peak_working_set_size; | 165 NOTREACHED(); |
169 size_t current_working_set_size; | 166 } |
170 if (GetMemoryInfo(*it, &peak_virtual_size, ¤t_virtual_size, | |
171 &peak_working_set_size, ¤t_working_set_size)) { | |
172 std::string chrome_name = (*it == browser_process_pid) ? "_b" : "_r"; | |
173 | 167 |
174 std::string trace_name(test_name); | 168 scoped_ptr<base::ProcessMetrics> process_metrics; |
175 PrintResult("vm_peak", chrome_name, | 169 process_metrics.reset( |
176 "vm_pk" + chrome_name + trace_name, | 170 base::ProcessMetrics::CreateProcessMetrics(process_handle)); |
177 peak_virtual_size, "bytes", | 171 |
178 true /* important */); | 172 std::string chrome_name = (*it == browser_process_pid) ? "_b" : "_r"; |
179 PrintResult("vm_final", chrome_name, | 173 |
180 "vm_f" + chrome_name + trace_name, | 174 std::string trace_name(test_name); |
181 current_virtual_size, "bytes", | 175 #if defined(OS_WIN) |
182 false /* not important */); | 176 PrintResult("vm_peak", chrome_name, |
183 PrintResult("ws_peak", chrome_name, | 177 "vm_pk" + chrome_name + trace_name, |
184 "ws_pk" + chrome_name + trace_name, | 178 process_metrics->GetPeakPagefileUsage(), "bytes", |
185 peak_working_set_size, "bytes", | 179 true /* important */); |
186 true /* important */); | 180 PrintResult("vm_final", chrome_name, |
187 PrintResult("ws_final", chrome_name, | 181 "vm_f" + chrome_name + trace_name, |
188 "ws_pk" + chrome_name + trace_name, | 182 process_metrics->GetPagefileUsage(), "bytes", |
189 current_working_set_size, "bytes", | 183 false /* not important */); |
190 false /* not important */); | 184 PrintResult("ws_peak", chrome_name, |
191 } | 185 "ws_pk" + chrome_name + trace_name, |
| 186 process_metrics->GetPeakWorkingSetSize(), "bytes", |
| 187 true /* important */); |
| 188 PrintResult("ws_final", chrome_name, |
| 189 "ws_f" + chrome_name + trace_name, |
| 190 process_metrics->GetWorkingSetSize(), "bytes", |
| 191 false /* not important */); |
| 192 #elif defined(OS_LINUX) |
| 193 PrintResult("vm_size_final", chrome_name, |
| 194 "vm_size_f" + chrome_name + trace_name, |
| 195 process_metrics->GetPagefileUsage(), "bytes", |
| 196 true /* important */); |
| 197 PrintResult("vm_rss_final", chrome_name, |
| 198 "vm_rss_f" + chrome_name + trace_name, |
| 199 process_metrics->GetWorkingSetSize(), "bytes", |
| 200 true /* important */); |
| 201 #else |
| 202 NOTIMPLEMENTED(); |
| 203 #endif |
| 204 base::CloseProcessHandle(process_handle); |
192 } | 205 } |
193 } | 206 } |
194 #endif // defined(OS_WIN) | |
195 | 207 |
196 // When use_http is true, the test name passed here will be used directly in | 208 // When use_http is true, the test name passed here will be used directly in |
197 // the path to the test data, so it must be safe for use in a URL without | 209 // the path to the test data, so it must be safe for use in a URL without |
198 // escaping. (No pound (#), question mark (?), semicolon (;), non-ASCII, or | 210 // escaping. (No pound (#), question mark (?), semicolon (;), non-ASCII, or |
199 // other funny stuff.) | 211 // other funny stuff.) |
200 void RunTest(const char* name, bool use_http) { | 212 void RunTest(const char* name, bool use_http) { |
201 std::wstring pages; | 213 std::wstring pages; |
202 std::string timings; | 214 std::string timings; |
203 RunPageCycler(name, &pages, &timings, use_http); | 215 RunPageCycler(name, &pages, &timings, use_http); |
204 if (timings.empty()) | 216 if (timings.empty()) |
205 return; | 217 return; |
206 | 218 |
207 #if defined(OS_WIN) | |
208 // TODO(port): Enable when Print{MemoryUsage,IOPerf}Info are ported. | |
209 PrintMemoryUsageInfo(""); | 219 PrintMemoryUsageInfo(""); |
210 PrintIOPerfInfo(""); | 220 PrintIOPerfInfo(""); |
211 #endif // defined(OS_WIN) | |
212 | 221 |
213 wprintf(L"\nPages: [%ls]\n", pages.c_str()); | 222 wprintf(L"\nPages: [%ls]\n", pages.c_str()); |
214 PrintResultList("times", "", "t", timings, "ms", | 223 PrintResultList("times", "", "t", timings, "ms", |
215 true /* important */); | 224 true /* important */); |
216 } | 225 } |
217 }; | 226 }; |
218 | 227 |
219 class PageCyclerReferenceTest : public PageCyclerTest { | 228 class PageCyclerReferenceTest : public PageCyclerTest { |
220 public: | 229 public: |
221 // override the browser directory that is used by UITest::SetUp to cause it | 230 // override the browser directory that is used by UITest::SetUp to cause it |
222 // to use the reference build instead. | 231 // to use the reference build instead. |
223 void SetUp() { | 232 void SetUp() { |
224 FilePath dir; | 233 FilePath dir; |
225 PathService::Get(chrome::DIR_TEST_TOOLS, &dir); | 234 PathService::Get(chrome::DIR_TEST_TOOLS, &dir); |
226 dir = dir.AppendASCII("reference_build"); | 235 dir = dir.AppendASCII("reference_build"); |
| 236 #if defined(OS_WIN) |
227 dir = dir.AppendASCII("chrome"); | 237 dir = dir.AppendASCII("chrome"); |
| 238 #elif defined(OS_LINUX) |
| 239 dir = dir.AppendASCII("chrome_linux"); |
| 240 #elif defined(OS_MACOSX) |
| 241 dir = dir.AppendASCII("chrome_mac"); |
| 242 #endif |
228 browser_directory_ = dir; | 243 browser_directory_ = dir; |
229 UITest::SetUp(); | 244 UITest::SetUp(); |
230 } | 245 } |
231 | 246 |
232 void RunTest(const char* name, bool use_http) { | 247 void RunTest(const char* name, bool use_http) { |
233 std::wstring pages; | 248 std::wstring pages; |
234 std::string timings; | 249 std::string timings; |
235 RunPageCycler(name, &pages, &timings, use_http); | 250 RunPageCycler(name, &pages, &timings, use_http); |
236 if (timings.empty()) | 251 if (timings.empty()) |
237 return; | 252 return; |
238 | 253 |
239 #if defined(OS_WIN) | |
240 // TODO(port): Enable when Print{MemoryUsage,IOPerf}Info are ported. | |
241 PrintMemoryUsageInfo("_ref"); | 254 PrintMemoryUsageInfo("_ref"); |
242 PrintIOPerfInfo("_ref"); | 255 PrintIOPerfInfo("_ref"); |
243 #endif // defined(OS_WIN) | |
244 | 256 |
245 PrintResultList("times", "", "t_ref", timings, "ms", | 257 PrintResultList("times", "", "t_ref", timings, "ms", |
246 true /* important */); | 258 true /* important */); |
247 } | 259 } |
248 }; | 260 }; |
249 | 261 |
250 | 262 |
251 // file-URL tests | 263 // file-URL tests |
252 TEST_F(PageCyclerTest, MozFile) { | 264 TEST_F(PageCyclerTest, MozFile) { |
253 RunTest("moz", false); | 265 RunTest("moz", false); |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
340 RunTest("bloat", true); | 352 RunTest("bloat", true); |
341 } | 353 } |
342 | 354 |
343 #if !defined(OS_MACOSX) | 355 #if !defined(OS_MACOSX) |
344 TEST_F(PageCyclerReferenceTest, BloatHttp) { | 356 TEST_F(PageCyclerReferenceTest, BloatHttp) { |
345 RunTest("bloat", true); | 357 RunTest("bloat", true); |
346 } | 358 } |
347 #endif | 359 #endif |
348 | 360 |
349 } // namespace | 361 } // namespace |
OLD | NEW |