OLD | NEW |
---|---|
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 "base/environment.h" | 5 #include "base/environment.h" |
6 #include "base/file_util.h" | 6 #include "base/file_util.h" |
7 #include "base/path_service.h" | 7 #include "base/path_service.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "base/stringprintf.h" | 9 #include "base/stringprintf.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
11 #include "base/strings/string_split.h" | 11 #include "base/strings/string_split.h" |
12 #include "base/sys_info.h" | 12 #include "base/sys_info.h" |
13 #include "base/test/test_file_util.h" | 13 #include "base/test/test_file_util.h" |
14 #include "base/test/test_timeouts.h" | 14 #include "base/test/test_timeouts.h" |
15 #include "base/time.h" | 15 #include "base/time.h" |
16 #include "base/utf_string_conversions.h" | 16 #include "base/utf_string_conversions.h" |
17 #include "chrome/common/chrome_constants.h" | 17 #include "chrome/common/chrome_constants.h" |
18 #include "chrome/common/chrome_paths.h" | 18 #include "chrome/common/chrome_paths.h" |
19 #include "chrome/common/chrome_switches.h" | 19 #include "chrome/common/chrome_switches.h" |
20 #include "chrome/common/env_vars.h" | 20 #include "chrome/common/env_vars.h" |
21 #include "chrome/test/automation/automation_proxy.h" | 21 #include "chrome/test/automation/automation_proxy.h" |
22 #include "chrome/test/base/test_switches.h" | 22 #include "chrome/test/base/test_switches.h" |
23 #include "chrome/test/base/testing_profile.h" | 23 #include "chrome/test/base/testing_profile.h" |
24 #include "chrome/test/base/ui_test_utils.h" | 24 #include "chrome/test/base/ui_test_utils.h" |
25 #include "chrome/test/perf/perf_test.h" | 25 #include "chrome/test/perf/perf_test.h" |
26 #include "chrome/test/ui/ui_perf_test.h" | 26 #include "chrome/test/ui/ui_perf_test.h" |
27 #include "content/public/common/content_switches.h" | |
27 #include "net/base/net_util.h" | 28 #include "net/base/net_util.h" |
28 | 29 |
29 using base::TimeDelta; | 30 using base::TimeDelta; |
30 using base::TimeTicks; | 31 using base::TimeTicks; |
31 | 32 |
32 namespace { | 33 namespace { |
33 | 34 |
34 class StartupTest : public UIPerfTest { | 35 class StartupTest : public UIPerfTest { |
35 public: | 36 public: |
36 StartupTest() { | 37 StartupTest() : tracing_enabled_(false) { |
37 show_window_ = true; | 38 show_window_ = true; |
38 } | 39 } |
39 virtual void SetUp() { | 40 virtual void SetUp() { |
40 collect_profiling_stats_ = false; | 41 collect_profiling_stats_ = false; |
41 } | 42 } |
42 virtual void TearDown() {} | 43 virtual void TearDown() {} |
43 | 44 |
44 enum TestColdness { | 45 enum TestColdness { |
45 WARM, | 46 WARM, |
46 COLD | 47 COLD |
(...skipping 17 matching lines...) Expand all Loading... | |
64 // Setup the command line arguments to capture profiling data for tasks. | 65 // Setup the command line arguments to capture profiling data for tasks. |
65 void SetUpWithProfiling() { | 66 void SetUpWithProfiling() { |
66 profiling_file_ = ui_test_utils::GetTestFilePath( | 67 profiling_file_ = ui_test_utils::GetTestFilePath( |
67 base::FilePath(base::FilePath::kCurrentDirectory), | 68 base::FilePath(base::FilePath::kCurrentDirectory), |
68 base::FilePath(FILE_PATH_LITERAL("task_profile.json"))); | 69 base::FilePath(FILE_PATH_LITERAL("task_profile.json"))); |
69 launch_arguments_.AppendSwitchPath(switches::kProfilingOutputFile, | 70 launch_arguments_.AppendSwitchPath(switches::kProfilingOutputFile, |
70 profiling_file_); | 71 profiling_file_); |
71 collect_profiling_stats_ = true; | 72 collect_profiling_stats_ = true; |
72 } | 73 } |
73 | 74 |
75 // Set the command line arguments to enable tracing. | |
76 void SetUpWithTracing(std::string trace_file_prefix) { | |
77 tracing_enabled_ = true; | |
78 trace_file_prefix_ = trace_file_prefix; | |
79 launch_arguments_.AppendSwitch(switches::kTraceStartup); | |
80 launch_arguments_.AppendSwitchASCII(switches::kTraceStartupDuration, | |
81 "1"); | |
82 } | |
83 | |
84 // Pause after running a test with tracing, to wait for the trace to | |
85 // be written. | |
86 void PauseForTracing() { | |
87 if (tracing_enabled_) { | |
88 #if defined(OS_MACOSX) | |
89 sleep(1); | |
Zhenyao Mo
2013/03/15 02:51:47
are you sure you want 1 ms? (sleep is ms instead
ccameron
2013/03/15 07:56:21
This one behaves as seconds (I tested it)
http://l
| |
90 #else | |
91 NOTREACHED(); | |
92 #endif | |
93 } | |
94 } | |
95 | |
96 // Set the command line arguments to use force-compositing-mode. | |
97 void SetUpWithForceCompositingMode() { | |
98 launch_arguments_.AppendSwitch(switches::kForceCompositingMode); | |
99 } | |
100 | |
74 // Load a complex html file on startup represented by |which_tab|. | 101 // Load a complex html file on startup represented by |which_tab|. |
75 void SetUpWithComplexFileURL(unsigned int which_tab) { | 102 void SetUpWithComplexFileURL(unsigned int which_tab) { |
76 const char* const kTestPageCyclerDomains[] = { | 103 const char* const kTestPageCyclerDomains[] = { |
77 "www.google.com", "www.nytimes.com", | 104 "www.google.com", "www.nytimes.com", |
78 "www.yahoo.com", "espn.go.com", "www.amazon.com" | 105 "www.yahoo.com", "espn.go.com", "www.amazon.com" |
79 }; | 106 }; |
80 unsigned int which_el = which_tab % arraysize(kTestPageCyclerDomains); | 107 unsigned int which_el = which_tab % arraysize(kTestPageCyclerDomains); |
81 const char* this_domain = kTestPageCyclerDomains[which_el]; | 108 const char* this_domain = kTestPageCyclerDomains[which_el]; |
82 | 109 |
83 base::FilePath page_cycler_path; | 110 base::FilePath page_cycler_path; |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
184 | 211 |
185 struct TimingInfo { | 212 struct TimingInfo { |
186 TimeDelta end_to_end; | 213 TimeDelta end_to_end; |
187 float first_start_ms; | 214 float first_start_ms; |
188 float last_stop_ms; | 215 float last_stop_ms; |
189 float first_stop_ms; | 216 float first_stop_ms; |
190 float nth_tab_stop_ms; | 217 float nth_tab_stop_ms; |
191 }; | 218 }; |
192 TimingInfo timings[kNumCyclesMax]; | 219 TimingInfo timings[kNumCyclesMax]; |
193 | 220 |
221 CommandLine launch_arguments_without_trace_file(launch_arguments_); | |
194 for (int i = 0; i < numCycles; ++i) { | 222 for (int i = 0; i < numCycles; ++i) { |
223 if (tracing_enabled_) { | |
224 std::stringstream tracing_enabled_file; | |
225 tracing_enabled_file << trace_file_prefix_ << i; | |
226 launch_arguments_ = launch_arguments_without_trace_file; | |
227 launch_arguments_.AppendSwitchASCII(switches::kTraceStartupFile, | |
228 tracing_enabled_file.str()); | |
229 } | |
195 if (test_cold == COLD) { | 230 if (test_cold == COLD) { |
196 base::FilePath dir_app; | 231 base::FilePath dir_app; |
197 ASSERT_TRUE(PathService::Get(chrome::DIR_APP, &dir_app)); | 232 ASSERT_TRUE(PathService::Get(chrome::DIR_APP, &dir_app)); |
198 | 233 |
199 base::FilePath chrome_exe(dir_app.Append(GetExecutablePath())); | 234 base::FilePath chrome_exe(dir_app.Append(GetExecutablePath())); |
200 ASSERT_TRUE(EvictFileFromSystemCacheWrapper(chrome_exe)); | 235 ASSERT_TRUE(EvictFileFromSystemCacheWrapper(chrome_exe)); |
201 #if defined(OS_WIN) | 236 #if defined(OS_WIN) |
202 // chrome.dll is windows specific. | 237 // chrome.dll is windows specific. |
203 base::FilePath chrome_dll( | 238 base::FilePath chrome_dll( |
204 dir_app.Append(FILE_PATH_LITERAL("chrome.dll"))); | 239 dir_app.Append(FILE_PATH_LITERAL("chrome.dll"))); |
(...skipping 23 matching lines...) Expand all Loading... | |
228 timings[i].last_stop_ms = max_stop; | 263 timings[i].last_stop_ms = max_stop; |
229 timings[i].first_stop_ms = times[0]; | 264 timings[i].first_stop_ms = times[0]; |
230 timings[i].nth_tab_stop_ms = times[nth_timed_tab]; | 265 timings[i].nth_tab_stop_ms = times[nth_timed_tab]; |
231 } else { | 266 } else { |
232 // Browser might not support initial load times. | 267 // Browser might not support initial load times. |
233 // Only use end-to-end time for this test. | 268 // Only use end-to-end time for this test. |
234 num_tabs = 0; | 269 num_tabs = 0; |
235 } | 270 } |
236 } | 271 } |
237 timings[i].end_to_end = end_time - browser_launch_time(); | 272 timings[i].end_to_end = end_time - browser_launch_time(); |
273 PauseForTracing(); | |
238 UITest::TearDown(); | 274 UITest::TearDown(); |
239 | 275 |
240 if (i == 0) { | 276 if (i == 0) { |
241 // Re-use the profile data after first run so that the noise from | 277 // Re-use the profile data after first run so that the noise from |
242 // creating databases doesn't impact all the runs. | 278 // creating databases doesn't impact all the runs. |
243 clear_profile_ = false; | 279 clear_profile_ = false; |
244 // Clear template_user_data_ so we don't try to copy it over each time | 280 // Clear template_user_data_ so we don't try to copy it over each time |
245 // through. | 281 // through. |
246 set_template_user_data(base::FilePath()); | 282 set_template_user_data(base::FilePath()); |
247 } | 283 } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
290 for (int i = 0; i < numCycles; ++i) | 326 for (int i = 0; i < numCycles; ++i) |
291 base::StringAppendF(×, "%.2f,", timings[i].last_stop_ms); | 327 base::StringAppendF(×, "%.2f,", timings[i].last_stop_ms); |
292 perf_test::PrintResultList(graph, "", name.c_str(), times, "ms", | 328 perf_test::PrintResultList(graph, "", name.c_str(), times, "ms", |
293 important); | 329 important); |
294 } | 330 } |
295 } | 331 } |
296 } | 332 } |
297 | 333 |
298 base::FilePath profiling_file_; | 334 base::FilePath profiling_file_; |
299 bool collect_profiling_stats_; | 335 bool collect_profiling_stats_; |
336 bool tracing_enabled_; | |
337 std::string trace_file_prefix_; | |
300 }; | 338 }; |
301 | 339 |
302 TEST_F(StartupTest, PerfWarm) { | 340 TEST_F(StartupTest, PerfWarm) { |
303 RunStartupTest("warm", "t", WARM, IMPORTANT, | 341 RunStartupTest("warm", "t", WARM, IMPORTANT, |
304 UITestBase::DEFAULT_THEME, 0, 0); | 342 UITestBase::DEFAULT_THEME, 0, 0); |
305 } | 343 } |
306 | 344 |
307 TEST_F(StartupTest, PerfReferenceWarm) { | 345 TEST_F(StartupTest, PerfReferenceWarm) { |
308 UseReferenceBuild(); | 346 UseReferenceBuild(); |
309 RunStartupTest("warm", "t_ref", WARM, IMPORTANT, | 347 RunStartupTest("warm", "t_ref", WARM, IMPORTANT, |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
462 UITestBase::COMPLEX_THEME, 0, 0); | 500 UITestBase::COMPLEX_THEME, 0, 0); |
463 } | 501 } |
464 | 502 |
465 TEST_F(StartupTest, ProfilingScript1) { | 503 TEST_F(StartupTest, ProfilingScript1) { |
466 SetUpWithFileURL(); | 504 SetUpWithFileURL(); |
467 SetUpWithProfiling(); | 505 SetUpWithProfiling(); |
468 RunStartupTest("warm", "profiling_scripts1", WARM, NOT_IMPORTANT, | 506 RunStartupTest("warm", "profiling_scripts1", WARM, NOT_IMPORTANT, |
469 UITestBase::DEFAULT_THEME, 1, 0); | 507 UITestBase::DEFAULT_THEME, 1, 0); |
470 } | 508 } |
471 | 509 |
510 #if defined(OS_MACOSX) | |
511 TEST_F(StartupTest, TracedProfilingScript1) { | |
512 SetUpWithFileURL(); | |
513 SetUpWithProfiling(); | |
514 SetUpWithTracing("startup_trace_sw_"); | |
515 RunStartupTest("warm", "traced_profiling_scripts1", WARM, NOT_IMPORTANT, | |
516 UITestBase::DEFAULT_THEME, 1, 0); | |
517 } | |
518 | |
519 TEST_F(StartupTest, TracedProfilingScript1FCM) { | |
520 SetUpWithFileURL(); | |
521 SetUpWithProfiling(); | |
522 SetUpWithForceCompositingMode(); | |
523 SetUpWithTracing("startup_trace_fcm_"); | |
524 RunStartupTest("warm", "traced_profiling_scripts1_fcm", WARM, NOT_IMPORTANT, | |
525 UITestBase::DEFAULT_THEME, 1, 0); | |
526 } | |
527 #endif | |
528 | |
472 } // namespace | 529 } // namespace |
OLD | NEW |