Extend capability of run-benchmark script to support mobile device
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 19 Jun 2015 02:32:40 +0000 (02:32 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 19 Jun 2015 02:32:40 +0000 (02:32 +0000)
https://bugs.webkit.org/show_bug.cgi?id=146125

Patch by Dewei Zhu <dewei_zhu@apple.com> on 2015-06-18
Reviewed by Ryosuke Niwa.

Extend capability of run-benchmark to support mobile device, and move majority of run-benchmark script code to
benchmark_runner directory, and make run-benchmark a wrapping script. Also correct a typo.

* Scripts/run-benchmark:
(main): Deleted.
* Scripts/webkitpy/benchmark_runner/benchmark_runner.py:
(BenchmarkRunner.__init__):
(BenchmarkRunner.execute):
* Scripts/webkitpy/benchmark_runner/browser_driver/browser_driver.py:
(BrowserDriver.prepareEnv):
* Scripts/webkitpy/benchmark_runner/browser_driver/osx_browser_driver.py:
(OSXBrowserDriver.prepareEnv):
* Scripts/webkitpy/benchmark_runner/browser_driver/osx_safari_driver.py:
(OSXSafariDriver.prepareEnv):
* Scripts/webkitpy/benchmark_runner/http_server_driver/http_server_driver.py:
(HTTPServerDriver.getReturnCode):
(HTTPServerDriver):
(HTTPServerDriver.setDeviceID):
* Scripts/webkitpy/benchmark_runner/run_benchmark.py: Copied from Tools/Scripts/run-benchmark.
(parse_args):
(start):
(main):
* Scripts/webkitpy/benchmark_runner/utils.py:
(getPathFromProjectRoot):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@185732 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Tools/ChangeLog
Tools/Scripts/run-benchmark
Tools/Scripts/webkitpy/benchmark_runner/benchmark_runner.py
Tools/Scripts/webkitpy/benchmark_runner/browser_driver/browser_driver.py
Tools/Scripts/webkitpy/benchmark_runner/browser_driver/osx_browser_driver.py
Tools/Scripts/webkitpy/benchmark_runner/browser_driver/osx_safari_driver.py
Tools/Scripts/webkitpy/benchmark_runner/http_server_driver/http_server_driver.py
Tools/Scripts/webkitpy/benchmark_runner/run_benchmark.py [new file with mode: 0755]
Tools/Scripts/webkitpy/benchmark_runner/utils.py

index 990ffcdd49d592ab1405ad64f986e8594f52677e..bc93beae12ef1e8e2565667a171744647639481b 100644 (file)
@@ -1,3 +1,35 @@
+2015-06-18  Dewei Zhu  <dewei_zhu@apple.com>
+
+        Extend capability of run-benchmark script to support mobile device
+        https://bugs.webkit.org/show_bug.cgi?id=146125
+
+        Reviewed by Ryosuke Niwa.
+
+        Extend capability of run-benchmark to support mobile device, and move majority of run-benchmark script code to
+        benchmark_runner directory, and make run-benchmark a wrapping script. Also correct a typo.
+
+        * Scripts/run-benchmark:
+        (main): Deleted.
+        * Scripts/webkitpy/benchmark_runner/benchmark_runner.py:
+        (BenchmarkRunner.__init__):
+        (BenchmarkRunner.execute):
+        * Scripts/webkitpy/benchmark_runner/browser_driver/browser_driver.py:
+        (BrowserDriver.prepareEnv):
+        * Scripts/webkitpy/benchmark_runner/browser_driver/osx_browser_driver.py:
+        (OSXBrowserDriver.prepareEnv):
+        * Scripts/webkitpy/benchmark_runner/browser_driver/osx_safari_driver.py:
+        (OSXSafariDriver.prepareEnv):
+        * Scripts/webkitpy/benchmark_runner/http_server_driver/http_server_driver.py:
+        (HTTPServerDriver.getReturnCode):
+        (HTTPServerDriver):
+        (HTTPServerDriver.setDeviceID):
+        * Scripts/webkitpy/benchmark_runner/run_benchmark.py: Copied from Tools/Scripts/run-benchmark.
+        (parse_args):
+        (start):
+        (main):
+        * Scripts/webkitpy/benchmark_runner/utils.py:
+        (getPathFromProjectRoot):
+
 2015-06-18  Jon Lee  <jonlee@apple.com>
 
         Unreviewed. Add Matt Daiter as a contributor.
index 822b159874cacbe1115f5d44f0508876286b1e4d..9aa6d3a9dfd3818ed24ce5eb65990dfb38d43b9b 100755 (executable)
@@ -1,44 +1,13 @@
 #!/usr/bin/env python
 
-import argparse
 import logging
-import platform
 import sys
 
-from webkitpy.benchmark_runner.benchmark_runner import BenchmarkRunner
-from webkitpy.benchmark_runner.browser_driver.browser_driver_factory import BrowserDriverFactory
+from webkitpy.benchmark_runner.run_benchmark import main, format_logger
 
 
 _log = logging.getLogger()
-_log.setLevel(logging.INFO)
-ch = logging.StreamHandler()
-formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
-ch.setFormatter(formatter)
-_log.addHandler(ch)
-
-
-def main():
-    parser = argparse.ArgumentParser(description='Automate the browser based performance benchmarks')
-    parser.add_argument('--output-file', dest='output', default=None)
-    parser.add_argument('--build-directory', dest='buildDir', help='Path to the browser executable. e.g. WebKitBuild/Release/')
-    parser.add_argument('--plan', dest='plan', required=True, help='Benchmark plan to run. e.g. speedometer, jetstream')
-    parser.add_argument('--platform', dest='platform', required=True, choices=BrowserDriverFactory.available_platforms())
-    # FIXME: Should we add chrome as an option? Well, chrome uses webkit in iOS.
-    parser.add_argument('--browser', dest='browser', required=True, choices=BrowserDriverFactory.available_browsers())
-    parser.add_argument('--debug', action='store_true')
-    parser.add_argument('--local-copy', dest='localCopy', help='Path to a local copy of the benchmark. e.g. PerformanceTests/SunSpider/')
-    parser.add_argument('--count', dest='countOverride', type=int, help='Number of times to run the benchmark. e.g. 5')
-    args = parser.parse_args()
-
-    if args.debug:
-        _log.setLevel(logging.DEBUG)
-    _log.debug('Initializing program with following parameters')
-    _log.debug('\toutput file name\t: %s' % args.output)
-    _log.debug('\tbuild directory\t: %s' % args.buildDir)
-    _log.debug('\tplan name\t: %s', args.plan)
-    runner = BenchmarkRunner(args.plan, args.localCopy, args.countOverride, args.buildDir, args.output, args.platform, args.browser)
-    runner.execute()
-
 
 if __name__ == '__main__':
+    format_logger(_log)
     sys.exit(main())
index bb1db611068861e4ec182b20964c17535f812e01..47e78bd5a222a70dcca00259ba49f22b618df81e 100644 (file)
@@ -25,8 +25,7 @@ _log = logging.getLogger(__name__)
 
 class BenchmarkRunner(object):
 
-    def __init__(self, planFile, localCopy, countOverride, buildDir, outputFile, platform, browser):
-        _log.info('Initializing benchmark running')
+    def __init__(self, planFile, localCopy, countOverride, buildDir, outputFile, platform, browser, httpServerDriverOverride=None, deviceID=None):
         try:
             planFile = self._findPlanFile(planFile)
             with open(planFile, 'r') as fp:
@@ -36,10 +35,14 @@ class BenchmarkRunner(object):
                     self.plan['local_copy'] = localCopy
                 if countOverride:
                     self.plan['count'] = countOverride
+                if httpServerDriverOverride:
+                    self.plan['http_server_driver'] = httpServerDriverOverride
                 self.browserDriver = BrowserDriverFactory.create([platform, browser])
                 self.httpServerDriver = HTTPServerDriverFactory.create([self.plan['http_server_driver']])
+                self.httpServerDriver.setDeviceID(deviceID)
                 self.buildDir = os.path.abspath(buildDir) if buildDir else None
                 self.outputFile = outputFile
+                self.deviceID = deviceID
         except IOError as error:
             _log.error('Can not open plan file: %s - Error %s' % (planFile, error))
             raise error
@@ -68,7 +71,7 @@ class BenchmarkRunner(object):
         for x in xrange(int(self.plan['count'])):
             _log.info('Start the iteration %d of current benchmark' % (x + 1))
             self.httpServerDriver.serve(webRoot)
-            self.browserDriver.prepareEnv()
+            self.browserDriver.prepareEnv(self.deviceID)
             url = urlparse.urljoin(self.httpServerDriver.baseUrl(), self.planName + '/' + self.plan['entry_point'])
             self.browserDriver.launchUrl(url, self.buildDir)
             result = None
index 6bef1506faf64aa01f4e4113183204182f587e3f..437a8cbcd38ae146741e94b77710530cc62e0dc8 100644 (file)
@@ -6,7 +6,7 @@ import abc
 class BrowserDriver(object):
 
     @abc.abstractmethod
-    def prepareEnv(self):
+    def prepareEnv(self, deviceID):
         pass
 
     @abc.abstractmethod
index 09c14d233584c1e4434d94dc171584b896c790be..2dc7eaae13056be9041fafcd8cf2191cbbaf67e3 100644 (file)
@@ -15,7 +15,7 @@ _log = logging.getLogger(__name__)
 class OSXBrowserDriver(BrowserDriver):
     bundleIdentifier = None
 
-    def prepareEnv(self):
+    def prepareEnv(self, deviceID):
         self.closeBrowsers()
         CGWarpMouseCursorPosition((10, 0))
 
index c4ca1a4e5822740388a6d4e9f7998ae910df6aed..97afbb31564d5f0ed67915de425376d4ba659ac4 100644 (file)
@@ -16,7 +16,7 @@ _log = logging.getLogger(__name__)
 class OSXSafariDriver(OSXBrowserDriver):
     bundleIdentifier = 'com.apple.Safari'
 
-    def prepareEnv(self):
+    def prepareEnv(self, deviceID):
         self.safariProcess = None
         super(OSXSafariDriver, self).prepareEnv()
         forceRemove(os.path.join(os.path.expanduser('~'), 'Library/Saved Application State/com.apple.Safari.savedState'))
index 97eb436119d5b0add417d95c88d94574d99aa3ab..9d29c636b960b4c8e2092822eb4a28bb47f65ef4 100644 (file)
@@ -19,3 +19,7 @@ class HTTPServerDriver(object):
     @abstractmethod
     def getReturnCode(self):
         pass
+
+    @abstractmethod
+    def setDeviceID(self, deviceID):
+        pass
diff --git a/Tools/Scripts/webkitpy/benchmark_runner/run_benchmark.py b/Tools/Scripts/webkitpy/benchmark_runner/run_benchmark.py
new file mode 100755 (executable)
index 0000000..3ad7b16
--- /dev/null
@@ -0,0 +1,55 @@
+#!/usr/bin/env python
+
+import argparse
+import logging
+import platform
+import os
+
+from benchmark_runner import BenchmarkRunner
+from browser_driver.browser_driver_factory import BrowserDriverFactory
+
+
+_log = logging.getLogger(__name__)
+
+
+def parse_args():
+    parser = argparse.ArgumentParser(description='Automate the browser based performance benchmarks')
+    parser.add_argument('--output-file', dest='output', default=None)
+    parser.add_argument('--build-directory', dest='buildDir', help='Path to the browser executable. e.g. WebKitBuild/Release/')
+    parser.add_argument('--plan', dest='plan', required=True, help='Benchmark plan to run. e.g. speedometer, jetstream')
+    parser.add_argument('--platform', dest='platform', required=True, choices=BrowserDriverFactory.available_platforms())
+    # FIXME: Should we add chrome as an option? Well, chrome uses webkit in iOS.
+    parser.add_argument('--browser', dest='browser', required=True, choices=BrowserDriverFactory.available_browsers())
+    parser.add_argument('--debug', action='store_true')
+    parser.add_argument('--local-copy', dest='localCopy', help='Path to a local copy of the benchmark. e.g. PerformanceTests/SunSpider/')
+    parser.add_argument('--count', dest='countOverride', type=int, help='Number of times to run the benchmark. e.g. 5')
+    parser.add_argument('--http-server-driver', dest='httpServerDriverOverride', default=None, help='Specify which HTTP server you wants to use')
+    parser.add_argument('--device-id', dest='device_id', default=None)
+
+    args = parser.parse_args()
+
+    if args.debug:
+        _log.setLevel(logging.DEBUG)
+    _log.debug('Initializing program with following parameters')
+    _log.debug('\toutput file name\t: %s' % args.output)
+    _log.debug('\tbuild directory\t: %s' % args.buildDir)
+    _log.debug('\tplan name\t: %s', args.plan)
+
+    return args
+
+
+def start(args):
+    runner = BenchmarkRunner(args.plan, args.localCopy, args.countOverride, args.buildDir, args.output, args.platform, args.browser, args.httpServerDriverOverride, args.device_id)
+    runner.execute()
+
+
+def format_logger(logger):
+    logger.setLevel(logging.INFO)
+    ch = logging.StreamHandler()
+    formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
+    ch.setFormatter(formatter)
+    logger.addHandler(ch)
+
+
+def main():
+    start(parse_args())
index 9bbd69d69f4648911a03fc3a8d1af0cc4c7234af..bc324e22c759d81b09c834cd6f618a8717dddeeb 100644 (file)
@@ -23,7 +23,7 @@ def loadModule(moduleDesc):
 
 
 def getPathFromProjectRoot(relativePathToProjectRoot):
-    # Choose the directory containning current file as start point,
+    # Choose the directory containing current file as start point,
     # compute relative path base on the parameter,
     # and return an absolute path
     return os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__)), relativePathToProjectRoot))