Index: chrome/test/functional/perf.py |
diff --git a/chrome/test/functional/perf.py b/chrome/test/functional/perf.py |
index 0cef99b467b98ed5d39c6af874c99fff730f7b62..91b83599fa65be5c9035a3e32467e1c1f08d77ec 100755 |
--- a/chrome/test/functional/perf.py |
+++ b/chrome/test/functional/perf.py |
@@ -1728,9 +1728,127 @@ class BaseScrollTest(BasePerfTest): |
'FPS', graph_name) |
fdeng1
2012/07/24 00:05:50
I restructured the old WebPageReplay to allow diff
|
+class BaseWebPageReplay(object): |
+ """Run tests with network simulation via Web Page Replay. |
+ |
+ Web Page Replay is a proxy that can record and "replay" web pages with |
+ simulated network characteristics -- without having to edit the pages |
+ by hand. With WPR, tests can use "real" web content, and catch |
+ performance issues that may result from introducing network delays and |
+ bandwidth throttling. |
+ |
+ This class provides a minimum set of settings for running a tests with |
dennis_jeffrey
2012/07/24 00:39:35
'a tests' --> 'tests'
fdeng1
2012/07/24 04:30:05
Done.
|
+ Web Page Replay. |
+ |
+ Environment Variables: |
+ WPR_RECORD: if set, puts Web Page Replay in record mode instead of replay. |
+ WPR_REPLAY_DIR: path to alternate Web Page Replay source (for development). |
+ WPR_ARCHIVE_PATH: path to alternate archive file (e.g. '/tmp/foo.wpr'). |
+ """ |
+ _BASE_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), |
+ '..', '..', '..', '..')) |
+ |
+ def Path(self, key, **kwargs): |
+ """Provide paths for tests using Web Page Replay.""" |
+ chromium_path = self._paths[key].format(**kwargs) |
+ return os.path.join(self._BASE_DIR, *chromium_path.split('/')) |
+ |
+ def _ArchivePath(self, test_name): |
+ archive_path = self.archive_path or self.Path('archive', |
+ test_name=test_name) |
+ |
+ if self.is_record_mode: |
+ archive_dir = os.path.dirname(archive_path) |
+ assert os.path.exists(archive_dir), \ |
+ 'Archive directory does not exist: %s' % archive_dir |
+ else: |
+ assert os.path.exists(archive_path), \ |
+ 'Archive file path does not exist: %s' % archive_path |
+ return archive_path |
+ |
+ def __init__(self): |
+ # Initialize Web Page Replay related Paths |
dennis_jeffrey
2012/07/24 00:39:35
'Paths' --> 'paths.'
fdeng1
2012/07/24 04:30:05
Done.
|
+ self._paths = { |
+ 'archive': os.path.join(os.getcwd(), '{test_name}.wpr'), |
+ 'replay': 'src/third_party/webpagereplay', |
+ 'logs': 'src/webpagereplay_logs', |
+ } |
+ |
+ #Initialize extra flags for chrome. |
dennis_jeffrey
2012/07/24 00:39:35
add a space after #
fdeng1
2012/07/24 04:30:05
Done.
|
+ self.chrome_flags = [ |
+ ('--host-resolver-rules=MAP * %s,EXCLUDE localhost' % |
+ webpagereplay.REPLAY_HOST), |
+ '--testing-fixed-http-port=%s' % webpagereplay.HTTP_PORT, |
+ '--testing-fixed-https-port=%s' % webpagereplay.HTTPS_PORT, |
+ '--ignore-certificate-errors', |
+ ] |
+ |
+ # Initialize Web Page Replay flags. |
+ self._replay_flags = ['--no-dns_forwarding'] |
+ |
+ self.archive_path = os.environ.get('WPR_ARCHIVE_PATH') |
+ self.replay_dir = os.environ.get('WPR_REPLAY_DIR', self.Path('replay')) |
+ self.is_record_mode = 'WPR_RECORD' in os.environ |
+ if self.is_record_mode: |
+ self._num_iterations = 1 |
+ |
+ def GetReplayServer(self, test_name): |
+ """Create a replay server. |
+ |
+ Args: |
+ test_name: the name of the test which is starting the server. |
+ Returns: |
dennis_jeffrey
2012/07/24 00:39:35
Add a blank line above this line
fdeng1
2012/07/24 04:30:05
Done.
|
+ a replay server. |
dennis_jeffrey
2012/07/24 00:39:35
capitalize the first letter in the sentence: 'a' -
fdeng1
2012/07/24 04:30:05
Done.
|
+ """ |
+ replay_flags = self._replay_flags |
+ if self.is_record_mode: |
+ replay_flags += ['--record'] |
+ |
+ return webpagereplay.ReplayServer( |
+ self.replay_dir, |
+ self._ArchivePath(test_name), |
+ self.Path('logs'), |
+ replay_flags) |
+ |
+ |
+class PerfWebPageReplay(BaseWebPageReplay): |
+ """Run page cycler and scroll tests with network simulation. |
+ |
+ This class allows customized settings for page cycler and scroll tests. |
+ """ |
+ |
+ def __init__(self): |
+ # Call parent __init__ |
+ super(PerfWebPageReplay, self).__init__() |
+ |
+ # Extra paths for Web Page Replay |
+ extra_paths = { |
+ 'archive': 'src/data/page_cycler/webpagereplay/{test_name}.wpr', |
+ 'page_sets': 'src/tools/page_cycler/webpagereplay/tests/{test_name}.js', |
+ 'start_page': 'src/tools/page_cycler/webpagereplay/start.html', |
+ 'extension': 'src/tools/page_cycler/webpagereplay/extension', |
+ } |
+ self._paths.update(extra_paths) |
+ |
+ # Extra chrome flags |
+ extra_chrome_flags = [ |
+ '--log-level=0', |
+ '--disable-background-networking', |
+ '--enable-experimental-extension-apis', |
+ ' --enable-logging', |
+ '--enable-stats-table', |
+ '--enable-benchmarking', |
+ '--metrics-recording-only', |
+ '--activate-on-launch', |
fdeng1
2012/07/24 00:05:50
This is the original settings from the old WebPage
|
+ ] |
+ self.chrome_flags.extend(extra_chrome_flags) |
+ |
+ |
class PopularSitesScrollTest(BaseScrollTest): |
"""Measures scrolling performance on recorded versions of popular sites.""" |
+ web_page_replay = PerfWebPageReplay() |
fdeng1
2012/07/24 00:05:50
Is it a good idea to use a class field to store th
dennis_jeffrey
2012/07/24 00:39:35
I think this is ok. We could prefix the variable
fdeng1
2012/07/24 04:30:05
Done.
|
+ |
def ExtraChromeFlags(self): |
"""Ensures Chrome is launched with custom flags. |
@@ -1738,11 +1856,12 @@ class PopularSitesScrollTest(BaseScrollTest): |
A list of extra flags to pass to Chrome when it is launched. |
""" |
return super(PopularSitesScrollTest, |
- self).ExtraChromeFlags() + WebPageReplay.CHROME_FLAGS |
+ self).ExtraChromeFlags() + self.web_page_replay.chrome_flags |
def _GetUrlList(self, test_name): |
"""Returns list of recorded sites.""" |
- with open(WebPageReplay.Path('page_sets', test_name=test_name)) as f: |
+ with open( |
+ self.web_page_replay.Path('page_sets', test_name=test_name)) as f: |
sites_text = f.read() |
js = """ |
%s |
@@ -1774,7 +1893,7 @@ class PopularSitesScrollTest(BaseScrollTest): |
test_name = '2012Q3' |
urls = self._GetUrlList(test_name) |
results = [] |
- with WebPageReplay().GetReplayServer(test_name): |
+ with self.web_page_replay.GetReplayServer(test_name): |
for iteration in range(self._num_iterations): |
for url in urls: |
result = self.RunSingleInvocation(url) |
@@ -2175,88 +2294,10 @@ class PageCyclerTest(BasePageCyclerTest): |
self.RunPageCyclerTest('moz2', 'Moz2File') |
-class WebPageReplay(object): |
- """Run page cycler tests with network simulation via Web Page Replay. |
- |
- Web Page Replay is a proxy that can record and "replay" web pages with |
- simulated network characteristics -- without having to edit the pages |
- by hand. With WPR, tests can use "real" web content, and catch |
- performance issues that may result from introducing network delays and |
- bandwidth throttling. |
- |
- Environment Variables: |
- WPR_RECORD: if set, puts Web Page Replay in record mode instead of replay. |
- WPR_REPLAY_DIR: path to alternate Web Page Replay source (for development). |
- WPR_ARCHIVE_PATH: path to alternate archive file (e.g. '/tmp/foo.wpr'). |
- """ |
- _PATHS = { |
- 'archive': 'src/data/page_cycler/webpagereplay/{test_name}.wpr', |
- 'page_sets': 'src/tools/page_cycler/webpagereplay/tests/{test_name}.js', |
- 'start_page': 'src/tools/page_cycler/webpagereplay/start.html', |
- 'extension': 'src/tools/page_cycler/webpagereplay/extension', |
- 'replay': 'src/third_party/webpagereplay', |
- 'logs': 'src/webpagereplay_logs', |
- } |
- |
- _BASE_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), |
- '..', '..', '..', '..')) |
- CHROME_FLAGS = [ |
- '--host-resolver-rules=MAP * %s' % webpagereplay.REPLAY_HOST, |
- '--testing-fixed-http-port=%s' % webpagereplay.HTTP_PORT, |
- '--testing-fixed-https-port=%s' % webpagereplay.HTTPS_PORT, |
- '--log-level=0', |
- '--disable-background-networking', |
- '--enable-experimental-extension-apis', |
- '--enable-logging', |
- '--enable-stats-table', |
- '--enable-benchmarking', |
- '--ignore-certificate-errors', |
- '--metrics-recording-only', |
- '--activate-on-launch', |
- '--no-first-run', |
- '--no-proxy-server', |
- ] |
- |
- @classmethod |
- def Path(cls, key, **kwargs): |
- """Provide paths for tests using Web Page Replay.""" |
- chromium_path = cls._PATHS[key].format(**kwargs) |
- return os.path.join(cls._BASE_DIR, *chromium_path.split('/')) |
- |
- def _ArchivePath(self, test_name): |
- archive_path = self.archive_path or self.Path('archive', |
- test_name=test_name) |
- if self.is_record_mode: |
- archive_dir = os.path.dirname(archive_path) |
- assert os.path.exists(archive_dir), \ |
- 'Archive directory does not exist: %s' % archive_dir |
- else: |
- assert os.path.exists(archive_path), \ |
- 'Archive file path does not exist: %s' % archive_path |
- return archive_path |
- |
- def __init__(self): |
- self.archive_path = os.environ.get('WPR_ARCHIVE_PATH') |
- self.replay_dir = os.environ.get('WPR_REPLAY_DIR', self.Path('replay')) |
- self.is_record_mode = 'WPR_RECORD' in os.environ |
- if self.is_record_mode: |
- self._num_iterations = 1 |
- |
- def GetReplayServer(self, test_name): |
- replay_options = [] |
- replay_options.append('--no-dns_forwarding') |
- if self.is_record_mode: |
- replay_options.append('--record') |
- return webpagereplay.ReplayServer( |
- self.replay_dir, |
- self._ArchivePath(test_name), |
- self.Path('logs'), |
- replay_options) |
- |
- |
class PageCyclerNetSimTest(BasePageCyclerTest): |
"""Tests to run Web Page Replay backed page cycler tests.""" |
MAX_ITERATION_SECONDS = 180 |
+ web_page_replay = PerfWebPageReplay() |
def ExtraChromeFlags(self): |
"""Ensures Chrome is launched with custom flags. |
@@ -2265,13 +2306,13 @@ class PageCyclerNetSimTest(BasePageCyclerTest): |
A list of extra flags to pass to Chrome when it is launched. |
""" |
flags = super(PageCyclerNetSimTest, self).ExtraChromeFlags() |
- flags.append('--load-extension=%s' % WebPageReplay.Path('extension')) |
- flags.extend(WebPageReplay.CHROME_FLAGS) |
+ flags.append('--load-extension=%s' % self.web_page_replay.Path('extension')) |
+ flags.extend(self.web_page_replay.chrome_flags) |
return flags |
def StartUrl(self, test_name, iterations): |
start_url = 'file://%s?test=%s&iterations=%d' % ( |
- WebPageReplay.Path('start_page'), test_name, iterations) |
+ self.web_page_replay.Path('start_page'), test_name, iterations) |
if self.use_auto: |
start_url += '&auto=1' |
return start_url |
@@ -2283,7 +2324,7 @@ class PageCyclerNetSimTest(BasePageCyclerTest): |
test_name: name for archive (.wpr) and config (.js) files. |
description: a string description for the test |
""" |
- with WebPageReplay().GetReplayServer(test_name): |
+ with self.web_page_replay.GetReplayServer(test_name): |
super_self = super(PageCyclerNetSimTest, self) |
super_self.RunPageCyclerTest(test_name, description) |