Add ability to ignore process prewarming for launch time benchmark
[WebKit-https.git] / PerformanceTests / LaunchTime / launch_time.py
index c637103..53a5a3b 100644 (file)
@@ -41,28 +41,20 @@ class DefaultLaunchTimeHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
         </html>
         '''
 
-    def get_blank_page(self):
-        return '''<!DOCTYPE html>
-        <html>
-          <head>
-            <title>Launch Time Benchmark</title>
-            <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-          </head>
-        </html>'''
-
-    def on_receive_stop_time(self, time):
+    def on_receive_stop_signal(self, data):
         pass
 
     def do_HEAD(self):
         self.send_response(200)
-        self.send_header('Content-type', 'text/hetml')
+        self.send_header('Content-type', 'text/html')
         self.end_headers()
 
     def do_GET(self):
         self.send_response(200)
         self.send_header('Content-type', 'text/html')
         self.end_headers()
-        self.wfile.write(self.get_blank_page() if self.path == '/blank' else self.get_test_page())
+        if not self.path.startswith('/blank'):
+            self.wfile.write(self.get_test_page())
         self.wfile.close()
 
     def do_POST(self):
@@ -73,9 +65,7 @@ class DefaultLaunchTimeHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
         self.wfile.close()
 
         data_string = self.rfile.read(int(self.headers['Content-Length']))
-        time = float(data_string)
-
-        self.on_receive_stop_time(time)
+        self.on_receive_stop_signal(data_string)
 
     def log_message(self, format, *args):
         pass
@@ -177,7 +167,8 @@ class LaunchTimeBenchmark:
     def _standard_deviation(self, results, mean=None):
         if mean is None:
             mean = sum(results) / float(len(results))
-        variance = sum((x - mean) ** 2 for x in results) / float(len(results) - 1)
+        divisor = float(len(results) - 1) if len(results) > 1 else float(len(results))
+        variance = sum((x - mean) ** 2 for x in results) / divisor
         return sqrt(variance)
 
     def _compute_results(self, results):
@@ -197,9 +188,13 @@ class LaunchTimeBenchmark:
         for i in range(self.iteration_groups):
             yield self.wait_time_low + increment_per_group * i
 
-    def open_tab(self):
-        call(['open', '-a', self._browser_bundle_path,
-            'http://localhost:{}/{}'.format(self._port, self._open_count)])
+    def open_tab(self, blank=False):
+        if blank:
+            call(['open', '-a', self._browser_bundle_path,
+                'http://localhost:{}/blank/{}'.format(self._port, self._open_count)])
+        else:
+            call(['open', '-a', self._browser_bundle_path,
+                'http://localhost:{}/{}'.format(self._port, self._open_count)])
         self._open_count += 1
 
     def launch_browser(self):
@@ -273,8 +268,8 @@ class LaunchTimeBenchmark:
                         results_by_iteration_number[i].append(result_in_ms)
                     except KeyboardInterrupt:
                         raise KeyboardInterrupt
-                    except:
-                        self._exit_due_to_exception('(Test {} failed)\n'.format(i + 1 if self._verbose else i))
+                    except Exception as error:
+                        self._exit_due_to_exception('(Test {} failed) {}: {}\n'.format(i + 1 if self._verbose else i, type(error).__name__, error))
                 if not self._verbose:
                     print ''