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

Side by Side Diff: chrome/test/functional/perf.py

Issue 10825025: Make it easy to use Web Page Replay with non-page_cycler tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rename PageCyclerWebPageReplay to shorter PageCyclerReplay. Created 8 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """Basic pyauto performance tests. 6 """Basic pyauto performance tests.
7 7
8 For tests that need to be run for multiple iterations (e.g., so that average 8 For tests that need to be run for multiple iterations (e.g., so that average
9 and standard deviation values can be reported), the default number of iterations 9 and standard deviation values can be reported), the default number of iterations
10 run for each of these tests is specified by |_DEFAULT_NUM_ITERATIONS|. 10 run for each of these tests is specified by |_DEFAULT_NUM_ITERATIONS|.
(...skipping 1720 matching lines...) Expand 10 before | Expand all | Expand 10 after
1731 class PopularSitesScrollTest(BaseScrollTest): 1731 class PopularSitesScrollTest(BaseScrollTest):
1732 """Measures scrolling performance on recorded versions of popular sites.""" 1732 """Measures scrolling performance on recorded versions of popular sites."""
1733 1733
1734 def ExtraChromeFlags(self): 1734 def ExtraChromeFlags(self):
1735 """Ensures Chrome is launched with custom flags. 1735 """Ensures Chrome is launched with custom flags.
1736 1736
1737 Returns: 1737 Returns:
1738 A list of extra flags to pass to Chrome when it is launched. 1738 A list of extra flags to pass to Chrome when it is launched.
1739 """ 1739 """
1740 return super(PopularSitesScrollTest, 1740 return super(PopularSitesScrollTest,
1741 self).ExtraChromeFlags() + WebPageReplay.CHROME_FLAGS 1741 self).ExtraChromeFlags() + PageCyclerReplay.CHROME_FLAGS
1742 1742
1743 def _GetUrlList(self, test_name): 1743 def _GetUrlList(self, test_name):
1744 """Returns list of recorded sites.""" 1744 """Returns list of recorded sites."""
1745 with open(WebPageReplay.Path('page_sets', test_name=test_name)) as f: 1745 sites_path = PageCyclerReplay.Path('page_sets', test_name=test_name)
1746 with open(sites_path) as f:
1746 sites_text = f.read() 1747 sites_text = f.read()
1747 js = """ 1748 js = """
1748 %s 1749 %s
1749 window.domAutomationController.send(JSON.stringify(pageSets)); 1750 window.domAutomationController.send(JSON.stringify(pageSets));
1750 """ % sites_text 1751 """ % sites_text
1751 page_sets = eval(self.ExecuteJavascript(js)) 1752 page_sets = eval(self.ExecuteJavascript(js))
1752 return list(itertools.chain(*page_sets))[1:] # Skip first. 1753 return list(itertools.chain(*page_sets))[1:] # Skip first.
1753 1754
1754 def _PrintScrollResults(self, results): 1755 def _PrintScrollResults(self, results):
1755 self._PrintSummaryResults( 1756 self._PrintSummaryResults(
(...skipping 11 matching lines...) Expand all
1767 [r.repeat_frame_times.GetPercentBelow60Fps() for r in results], 1768 [r.repeat_frame_times.GetPercentBelow60Fps() for r in results],
1768 'percent', 'PercentBelow60FPS') 1769 'percent', 'PercentBelow60FPS')
1769 self._PrintSummaryResults( 1770 self._PrintSummaryResults(
1770 'first_paint_time', [r.first_paint_time for r in results], 1771 'first_paint_time', [r.first_paint_time for r in results],
1771 'ms', 'FirstPaintTime') 1772 'ms', 'FirstPaintTime')
1772 1773
1773 def test2012Q3(self): 1774 def test2012Q3(self):
1774 test_name = '2012Q3' 1775 test_name = '2012Q3'
1775 urls = self._GetUrlList(test_name) 1776 urls = self._GetUrlList(test_name)
1776 results = [] 1777 results = []
1777 with WebPageReplay().GetReplayServer(test_name): 1778 with PageCyclerReplay.ReplayServer(test_name):
fdeng1 2012/07/26 20:51:19 I think change it to PageCyclerReplay()?
slamm_google 2012/07/26 23:46:59 Thanks for catching that. I changed ReplayServer t
1778 for iteration in range(self._num_iterations): 1779 for iteration in range(self._num_iterations):
1779 for url in urls: 1780 for url in urls:
1780 result = self.RunSingleInvocation(url) 1781 result = self.RunSingleInvocation(url)
1781 fps = result.initial_frame_times.GetFps() 1782 fps = result.initial_frame_times.GetFps()
1782 assert fps, '%s did not scroll' % url 1783 assert fps, '%s did not scroll' % url
1783 logging.info('Iteration %d of %d: %f fps', iteration, 1784 logging.info('Iteration %d of %d: %f fps', iteration,
1784 self._num_iterations, fps) 1785 self._num_iterations, fps)
1785 results.append(result) 1786 results.append(result)
1786 self._PrintScrollResults(results) 1787 self._PrintScrollResults(results)
1787 1788
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after
2168 def testIntl2File(self): 2169 def testIntl2File(self):
2169 self.RunPageCyclerTest('intl2', 'Intl2File') 2170 self.RunPageCyclerTest('intl2', 'Intl2File')
2170 2171
2171 def testMozFile(self): 2172 def testMozFile(self):
2172 self.RunPageCyclerTest('moz', 'MozFile') 2173 self.RunPageCyclerTest('moz', 'MozFile')
2173 2174
2174 def testMoz2File(self): 2175 def testMoz2File(self):
2175 self.RunPageCyclerTest('moz2', 'Moz2File') 2176 self.RunPageCyclerTest('moz2', 'Moz2File')
2176 2177
2177 2178
2178 class WebPageReplay(object): 2179 class PageCyclerReplay(object):
2179 """Run page cycler tests with network simulation via Web Page Replay. 2180 """Run page cycler tests with network simulation via Web Page Replay.
2180 2181
2181 Web Page Replay is a proxy that can record and "replay" web pages with 2182 Web Page Replay is a proxy that can record and "replay" web pages with
2182 simulated network characteristics -- without having to edit the pages 2183 simulated network characteristics -- without having to edit the pages
2183 by hand. With WPR, tests can use "real" web content, and catch 2184 by hand. With WPR, tests can use "real" web content, and catch
2184 performance issues that may result from introducing network delays and 2185 performance issues that may result from introducing network delays and
2185 bandwidth throttling. 2186 bandwidth throttling.
2186
2187 Environment Variables:
2188 WPR_RECORD: if set, puts Web Page Replay in record mode instead of replay.
2189 WPR_REPLAY_DIR: path to alternate Web Page Replay source (for development).
2190 WPR_ARCHIVE_PATH: path to alternate archive file (e.g. '/tmp/foo.wpr').
2191 """ 2187 """
2192 _PATHS = { 2188 _PATHS = {
2193 'archive': 'src/data/page_cycler/webpagereplay/{test_name}.wpr', 2189 'archive': 'src/data/page_cycler/webpagereplay/{test_name}.wpr',
2194 'page_sets': 'src/tools/page_cycler/webpagereplay/tests/{test_name}.js', 2190 'page_sets': 'src/tools/page_cycler/webpagereplay/tests/{test_name}.js',
2195 'start_page': 'src/tools/page_cycler/webpagereplay/start.html', 2191 'start_page': 'src/tools/page_cycler/webpagereplay/start.html',
2196 'extension': 'src/tools/page_cycler/webpagereplay/extension', 2192 'extension': 'src/tools/page_cycler/webpagereplay/extension',
2197 'replay': 'src/third_party/webpagereplay',
2198 'logs': 'src/webpagereplay_logs',
2199 } 2193 }
2200 2194
2201 _BASE_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), 2195 CHROME_FLAGS = webpagereplay.CHROME_FLAGS + [
2202 '..', '..', '..', '..'))
2203 CHROME_FLAGS = [
2204 '--host-resolver-rules=MAP * %s' % webpagereplay.REPLAY_HOST,
2205 '--testing-fixed-http-port=%s' % webpagereplay.HTTP_PORT,
2206 '--testing-fixed-https-port=%s' % webpagereplay.HTTPS_PORT,
2207 '--log-level=0', 2196 '--log-level=0',
2208 '--disable-background-networking', 2197 '--disable-background-networking',
2209 '--enable-experimental-extension-apis', 2198 '--enable-experimental-extension-apis',
2210 '--enable-logging', 2199 '--enable-logging',
2211 '--enable-stats-table', 2200 '--enable-stats-table',
2212 '--enable-benchmarking', 2201 '--enable-benchmarking',
2213 '--ignore-certificate-errors',
2214 '--metrics-recording-only', 2202 '--metrics-recording-only',
2215 '--activate-on-launch', 2203 '--activate-on-launch',
2216 '--no-first-run', 2204 '--no-first-run',
2217 '--no-proxy-server', 2205 '--no-proxy-server',
2218 ] 2206 ]
2219 2207
2220 @classmethod 2208 @classmethod
2221 def Path(cls, key, **kwargs): 2209 def Path(cls, key, **kwargs):
2222 """Provide paths for tests using Web Page Replay.""" 2210 return webpagereplay.FormatChromiumPath(cls._PATHS[key], **kwargs)
2223 chromium_path = cls._PATHS[key].format(**kwargs)
2224 return os.path.join(cls._BASE_DIR, *chromium_path.split('/'))
2225 2211
2226 def _ArchivePath(self, test_name): 2212 def ReplayServer(self, test_name):
2227 archive_path = self.archive_path or self.Path('archive', 2213 archive_path = self.Path('archive', test_name=test_name)
2228 test_name=test_name) 2214 return webpagereplay.ReplayServer(archive_path)
2229 if self.is_record_mode:
2230 archive_dir = os.path.dirname(archive_path)
2231 assert os.path.exists(archive_dir), \
2232 'Archive directory does not exist: %s' % archive_dir
2233 else:
2234 assert os.path.exists(archive_path), \
2235 'Archive file path does not exist: %s' % archive_path
2236 return archive_path
2237
2238 def __init__(self):
2239 self.archive_path = os.environ.get('WPR_ARCHIVE_PATH')
2240 self.replay_dir = os.environ.get('WPR_REPLAY_DIR', self.Path('replay'))
2241 self.is_record_mode = 'WPR_RECORD' in os.environ
2242 if self.is_record_mode:
2243 self._num_iterations = 1
2244
2245 def GetReplayServer(self, test_name):
2246 replay_options = []
2247 replay_options.append('--no-dns_forwarding')
2248 if self.is_record_mode:
2249 replay_options.append('--record')
2250 return webpagereplay.ReplayServer(
2251 self.replay_dir,
2252 self._ArchivePath(test_name),
2253 self.Path('logs'),
2254 replay_options)
2255 2215
2256 2216
2257 class PageCyclerNetSimTest(BasePageCyclerTest): 2217 class PageCyclerNetSimTest(BasePageCyclerTest):
2258 """Tests to run Web Page Replay backed page cycler tests.""" 2218 """Tests to run Web Page Replay backed page cycler tests."""
2259 MAX_ITERATION_SECONDS = 180 2219 MAX_ITERATION_SECONDS = 180
2260 2220
2261 def ExtraChromeFlags(self): 2221 def ExtraChromeFlags(self):
2262 """Ensures Chrome is launched with custom flags. 2222 """Ensures Chrome is launched with custom flags.
2263 2223
2264 Returns: 2224 Returns:
2265 A list of extra flags to pass to Chrome when it is launched. 2225 A list of extra flags to pass to Chrome when it is launched.
2266 """ 2226 """
2267 flags = super(PageCyclerNetSimTest, self).ExtraChromeFlags() 2227 flags = super(PageCyclerNetSimTest, self).ExtraChromeFlags()
2268 flags.append('--load-extension=%s' % WebPageReplay.Path('extension')) 2228 flags.append('--load-extension=%s' %
2269 flags.extend(WebPageReplay.CHROME_FLAGS) 2229 PageCyclerReplay.Path('extension'))
2230 flags.extend(PageCyclerReplay.CHROME_FLAGS)
2270 return flags 2231 return flags
2271 2232
2272 def StartUrl(self, test_name, iterations): 2233 def StartUrl(self, test_name, iterations):
2234 start_path = PageCyclerReplay.Path('start_page')
2273 start_url = 'file://%s?test=%s&iterations=%d' % ( 2235 start_url = 'file://%s?test=%s&iterations=%d' % (
2274 WebPageReplay.Path('start_page'), test_name, iterations) 2236 start_path, test_name, iterations)
2275 if self.use_auto: 2237 if self.use_auto:
2276 start_url += '&auto=1' 2238 start_url += '&auto=1'
2277 return start_url 2239 return start_url
2278 2240
2279 def RunPageCyclerTest(self, test_name, description): 2241 def RunPageCyclerTest(self, test_name, description):
2280 """Runs the specified PageCycler test. 2242 """Runs the specified PageCycler test.
2281 2243
2282 Args: 2244 Args:
2283 test_name: name for archive (.wpr) and config (.js) files. 2245 test_name: name for archive (.wpr) and config (.js) files.
2284 description: a string description for the test 2246 description: a string description for the test
2285 """ 2247 """
2286 with WebPageReplay().GetReplayServer(test_name): 2248 with PageCyclerReplay.ReplayServer(test_name) as replay_server:
fdeng1 2012/07/26 20:51:19 ->PageCyclerReplay()
2249 if replay_server.is_record_mode:
2250 self._num_iterations = 1
fdeng1 2012/07/26 20:51:19 I haven't figure out why, but it complains replay_
slamm_google 2012/07/26 23:46:59 Not sure about the None error. Try it again with R
fdeng1 2012/07/27 00:45:10 I am still have the same trouble after patching th
2287 super_self = super(PageCyclerNetSimTest, self) 2251 super_self = super(PageCyclerNetSimTest, self)
2288 super_self.RunPageCyclerTest(test_name, description) 2252 super_self.RunPageCyclerTest(test_name, description)
2289 2253
2290 def test2012Q2(self): 2254 def test2012Q2(self):
2291 self.RunPageCyclerTest('2012Q2', '2012Q2') 2255 self.RunPageCyclerTest('2012Q2', '2012Q2')
2292 2256
2293 2257
2294 class MemoryTest(BasePerfTest): 2258 class MemoryTest(BasePerfTest):
2295 """Tests to measure memory consumption under different usage scenarios.""" 2259 """Tests to measure memory consumption under different usage scenarios."""
2296 2260
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
2624 """Identifies the port number to which the server is currently bound. 2588 """Identifies the port number to which the server is currently bound.
2625 2589
2626 Returns: 2590 Returns:
2627 The numeric port number to which the server is currently bound. 2591 The numeric port number to which the server is currently bound.
2628 """ 2592 """
2629 return self._server.server_address[1] 2593 return self._server.server_address[1]
2630 2594
2631 2595
2632 if __name__ == '__main__': 2596 if __name__ == '__main__':
2633 pyauto_functional.Main() 2597 pyauto_functional.Main()
OLDNEW
« no previous file with comments | « no previous file | chrome/test/functional/webpagereplay.py » ('j') | chrome/test/functional/webpagereplay.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698