Add errors to run-benchmark exception handling.
authorslewis@apple.com <slewis@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 5 Jun 2015 09:11:21 +0000 (09:11 +0000)
committerslewis@apple.com <slewis@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 5 Jun 2015 09:11:21 +0000 (09:11 +0000)
Reviewed by Ryosuke Niwa.

* Scripts/run-benchmark:
(main):
* Scripts/webkitpy/benchmark_runner/benchmark_builder/generic_benchmark_builder.py:
(GenericBenchmarkBuilder.prepare):
(GenericBenchmarkBuilder._runCreateScript):
(GenericBenchmarkBuilder._applyPatch):
(GenericBenchmarkBuilder.clean):
* Scripts/webkitpy/benchmark_runner/benchmark_runner.py:
(BenchmarkRunner.__init__):
(BenchmarkRunner.execute):
(BenchmarkRunner):
(BenchmarkRunner.cleanup):
* Scripts/webkitpy/benchmark_runner/generic_factory.py:
(GenericFactory.iterateGetItem):
(GenericFactory.create):
* Scripts/webkitpy/benchmark_runner/utils.py:
(loadModule):
(loadJSONFromFile):
(forceRemove):

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

Tools/ChangeLog
Tools/Scripts/run-benchmark
Tools/Scripts/webkitpy/benchmark_runner/benchmark_builder/generic_benchmark_builder.py
Tools/Scripts/webkitpy/benchmark_runner/benchmark_runner.py
Tools/Scripts/webkitpy/benchmark_runner/generic_factory.py
Tools/Scripts/webkitpy/benchmark_runner/utils.py

index 9bb1e31..219a4ae 100644 (file)
@@ -1,5 +1,32 @@
 2015-06-05  Stephanie Lewis  <slewis@apple.com>
 
+
+        Add errors to run-benchmark exception handling.
+
+        Reviewed by Ryosuke Niwa.
+
+        * Scripts/run-benchmark:
+        (main):
+        * Scripts/webkitpy/benchmark_runner/benchmark_builder/generic_benchmark_builder.py:
+        (GenericBenchmarkBuilder.prepare):
+        (GenericBenchmarkBuilder._runCreateScript):
+        (GenericBenchmarkBuilder._applyPatch):
+        (GenericBenchmarkBuilder.clean):
+        * Scripts/webkitpy/benchmark_runner/benchmark_runner.py:
+        (BenchmarkRunner.__init__):
+        (BenchmarkRunner.execute):
+        (BenchmarkRunner):
+        (BenchmarkRunner.cleanup):
+        * Scripts/webkitpy/benchmark_runner/generic_factory.py:
+        (GenericFactory.iterateGetItem):
+        (GenericFactory.create):
+        * Scripts/webkitpy/benchmark_runner/utils.py:
+        (loadModule):
+        (loadJSONFromFile):
+        (forceRemove):
+
+2015-06-05  Stephanie Lewis  <slewis@apple.com>
+
         Streamline run-benchmark browser
 
         Reviewed by Ryosuke Niwa.
index 16255da..ef7979b 100755 (executable)
@@ -36,8 +36,11 @@ def main():
     _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)
-    return runner.execute()
+    try:
+        runner = BenchmarkRunner(args.plan, args.localCopy, args.countOverride, args.buildDir, args.output, args.platform, args.browser)
+        runner.execute()
+    except Exception as error:
+        sys.exit("Error occurred running the benchmark: %s" % error)
 
 
 if __name__ == '__main__':
index 010cd99..f10251e 100644 (file)
@@ -31,7 +31,7 @@ class GenericBenchmarkBuilder(object):
             if createScript:
                 self._runCreateScript(createScript)
             return self._applyPatch(patch)
-        except:
+        except Exception:
             self.clean()
             raise
 
@@ -42,7 +42,7 @@ class GenericBenchmarkBuilder(object):
         errorCode = subprocess.call(createScript)
         os.chdir(oldWorkingDirectory)
         if errorCode:
-            raise Exception('Cannot create the benchmark', errorCode)
+            raise Exception('Cannot create the benchmark - Error: %s' % errorCode)
 
     def _copyBenchmarkToTempDir(self, benchmarkPath):
         shutil.copytree(getPathFromProjectRoot(benchmarkPath), self.dest)
@@ -70,10 +70,10 @@ class GenericBenchmarkBuilder(object):
         errorCode = subprocess.call(['patch', '-p1', '-f', '-i', getPathFromProjectRoot(patch)])
         os.chdir(oldWorkingDirectory)
         if errorCode:
-            raise Exception('Cannot apply patch, will skip current benchmarkPath')
+            raise Exception('Cannot apply patch, will skip current benchmarkPath - Error: %s' % errorCode)
         return self.webRoot
 
     def clean(self):
-        _log.info('Cleanning Benchmark')
+        _log.info('Cleaning Benchmark')
         if self.webRoot:
             forceRemove(self.webRoot)
index 81a5632..7a3af6d 100644 (file)
@@ -5,6 +5,7 @@ import logging
 import shutil
 import signal
 import subprocess
+import sys
 import tempfile
 import time
 import types
@@ -39,12 +40,12 @@ class BenchmarkRunner(object):
                 self.httpServerDriver = HTTPServerDriverFactory.create([self.plan['http_server_driver']])
                 self.buildDir = os.path.abspath(buildDir) if buildDir else None
                 self.outputFile = outputFile
-        except IOError:
-            _log.error('Can not open plan file: %s' % planFile)
-            raise
-        except ValueError:
-            _log.error('Plan file:%s may not follow JSON format' % planFile)
-            raise
+        except IOError as error:
+            _log.error('Can not open plan file: %s - Error %s' % planFile, error)
+            raise error
+        except ValueError as error:
+            _log.error('Plan file: %s may not follow JSON format - Error %s' % planFile, error)
+            raise error
 
     def _findPlanFile(self, planFile):
         if not os.path.exists(planFile):
@@ -61,13 +62,13 @@ class BenchmarkRunner(object):
         _log.info('Start to execute the plan')
         _log.info('Start a new benchmark')
         results = []
-        benchmarkBuilder = BenchmarkBuilderFactory.create([self.plan['benchmark_builder']])
+        self.benchmarkBuilder = BenchmarkBuilderFactory.create([self.plan['benchmark_builder']])
 
         if not self.plan.get('local_copy') and not self.plan.get('remote_archive'):
             _log.error('Either local_copy or remote_archive must be specified in the plan')
-            return 2
+            sys.exit(2)
 
-        webRoot = benchmarkBuilder.prepare(self.planName, self.plan.get('local_copy'), self.plan.get('remote_archive'),
+        webRoot = self.benchmarkBuilder.prepare(self.planName, self.plan.get('local_copy'), self.plan.get('remote_archive'),
             self.plan.get('benchmark_patch'), self.plan.get('create_script'))
         for x in xrange(int(self.plan['count'])):
             _log.info('Start the iteration %d of current benchmark' % (x + 1))
@@ -77,24 +78,30 @@ class BenchmarkRunner(object):
             self.browserDriver.launchUrl(url, self.buildDir)
             try:
                 with timeout(self.plan['timeout']):
-                    result = json.loads(self.httpServerDriver.fetchResult())
+                    result = self.httpServerDriver.fetchResult()
                 assert(not self.httpServerDriver.getReturnCode())
                 assert(result)
-                results.append(result)
-            except:
-                _log.error('No result or server crashes. Something went wrong. Will skip current benchmark.')
-                self.browserDriver.closeBrowsers()
-                self.httpServerDriver.killServer()
-                benchmarkBuilder.clean()
-                return 1
+                results.append(json.loads(result))
+            except Exception as error:
+                _log.error('No result or the server crashed. Something went wrong. Will skip current benchmark.\nError: %s, Server return code: %d, result: %s' % (error, not self.httpServerDriver.getReturnCode(), result))
+                self.cleanup()
+                sys.exit(1)
             finally:
                 self.browserDriver.closeBrowsers()
                 _log.info('End of %d iteration of current benchmark' % (x + 1))
         results = self.wrap(results)
         self.dump(results, self.outputFile if self.outputFile else self.plan['output_file'])
         self.show_results(results)
-        benchmarkBuilder.clean()
-        return 0
+        self.benchmarkBuilder.clean()
+        sys.exit()
+
+    def cleanup(self):
+        if self.browserDriver:
+            self.browserDriver.closeBrowsers()
+        if self.httpServerDriver:
+            self.httpServerDriver.killServer()
+        if self.benchmarkBuilder:
+            self.benchmarkBuilder.clean()
 
     @classmethod
     def dump(cls, results, outputFile):
@@ -102,8 +109,8 @@ class BenchmarkRunner(object):
         try:
             with open(outputFile, 'w') as fp:
                 json.dump(results, fp)
-        except IOError:
-            _log.error('Cannot open output file: %s' % outputFile)
+        except IOError as error:
+            _log.error('Cannot open output file: %s - Error: %s' % outputFile, error)
             _log.error('Results are:\n %s', json.dumps(results))
 
     @classmethod
index d710d4a..cebecb4 100644 (file)
@@ -27,5 +27,5 @@ class GenericFactory(object):
     def create(cls, descriptions):
         try:
             return loadModule(cls.iterateGetItem(cls.products, descriptions))()
-        except:
+        except Exception:
             raise
index d8d055c..9bbd69d 100644 (file)
@@ -18,8 +18,8 @@ def loadModule(moduleDesc):
     try:
         ret = getattr(__import__(moduleDesc['filePath'], globals(), locals(), moduleDesc['moduleName'], -1), moduleDesc['moduleName'])
         return ret
-    except Exception as e:
-        raise ModuleNotFoundError('Module (%s) with path(%s) is not found' % (moduleDesc['moduleName'], moduleDesc['filePath']))
+    except Exception as error:
+        raise ModuleNotFoundError('Error loading module (%s) with path(%s): {%s}' % (moduleDesc['moduleName'], moduleDesc['filePath'], error))
 
 
 def getPathFromProjectRoot(relativePathToProjectRoot):
@@ -34,15 +34,16 @@ def loadJSONFromFile(filePath):
         jsonObject = json.load(open(filePath, 'r'))
         assert(jsonObject)
         return jsonObject
-    except:
-        raise Exception("Invalid json format or empty json was found in %s" % (filePath))
+    except Exception as error:
+        raise Exception("Invalid json format or empty json was found in %s - Error: %s" % (filePath, error))
 
 
 def forceRemove(path):
     try:
         shutil.rmtree(path)
-    except:
+    except Exception as error:
         # Directory/file does not exist or privilege issue, just ignore it
+        _log.info("Error removing %s: %s" % (path, error))
         pass
 
 # Borrow this code from