Index: tools/perf/contrib/cluster_telemetry/screenshot.py |
diff --git a/tools/perf/contrib/cluster_telemetry/screenshot.py b/tools/perf/contrib/cluster_telemetry/screenshot.py |
new file mode 100644 |
index 0000000000000000000000000000000000000000..199418d5edb2755c1810380975fb658bb95a8427 |
--- /dev/null |
+++ b/tools/perf/contrib/cluster_telemetry/screenshot.py |
@@ -0,0 +1,71 @@ |
+# Copyright 2017 The Chromium Authors. All rights reserved. |
+# Use of this source code is governed by a BSD-style license that can be |
+# found in the LICENSE file. |
+ |
+import logging |
+import os |
+import py_utils |
+import time |
+ |
+from telemetry.page import legacy_page_test |
+from telemetry.value import scalar |
+from telemetry.util import image_util |
+ |
+class Screenshot(legacy_page_test.LegacyPageTest): |
+ """Takes a PNG screenshot of the page.""" |
+ |
+ def __init__(self, png_outdir, wait_time=0, disable_javascript=False): |
+ super(Screenshot, self).__init__() |
+ self._png_outdir = png_outdir |
+ self._wait_time = wait_time |
+ # Javascript flag not yet implemented |
nednguyen
2017/06/08 20:18:26
I suggest just leave this part out until someone i
|
+ # self._disable_javascript = disable_javascript |
+ |
+ def ValidateAndMeasurePage(self, page, tab, results): |
+ if not tab.screenshot_supported: |
+ raise legacy_page_test.MeasurementFailure( |
+ 'Screenshotting not supported on this platform') |
+ |
+ try: |
+ tab.WaitForDocumentReadyStateToBeComplete() |
+ except py_utils.TimeoutException: |
+ logging.info("WaitForDocumentReadyStateToBeComplete() timeout, page: %s", |
+ page.display_name) |
nednguyen
2017/06/08 20:18:26
if this timeout, this should return instead of kee
|
+ |
+ time.sleep(self._wait_time) |
+ |
+ if not os.path.exists(self._png_outdir): |
+ logging.info("Creating directory %s", self._png_outdir) |
+ try: |
+ os.makedirs(self._png_outdir) |
+ except OSError: |
+ logging.info("Directory %s could not be created", self._png_outdir) |
+ raise |
+ |
+ outpath = os.path.abspath( |
+ os.path.join(self._png_outdir, page.file_safe_name)) + '.png' |
+ # Replace win32 path separator char '\' with '\\'. |
+ outpath = outpath.replace('\\', '\\\\') |
+ |
+ logging.info("Taking screenshot of %s", page.display_name) |
nednguyen
2017/06/08 20:18:26
this log doesn't seem particularly useful IMO
|
+ screenshot = tab.Screenshot() |
+ |
+ last_mod_time = 0 |
+ if os.path.exists(outpath): |
+ last_mod_time = os.path.getmtime(outpath) |
+ |
+ # TODO(lchoi): Add logging to image_util.py and/or augment error handling of |
+ # image_util.WritePngFile |
+ logging.info("Writing PNG file to %s", outpath) |
+ image_util.WritePngFile(screenshot, outpath) |
+ logging.info("PNG file written successfully") |
+ |
+ saved_picture_count = 0 |
+ if os.path.exists(outpath) and os.path.getmtime(outpath) > last_mod_time: |
nednguyen
2017/06/08 20:18:25
Why we need this logic? If the pgn file are not wr
lchoi
2017/06/08 20:38:34
I see. Do you want me to remove this and everythin
nednguyen
2017/06/08 21:39:26
sgtm
|
+ saved_picture_count = 1 |
+ results.AddValue(scalar.ScalarValue( |
+ results.current_page, 'saved_picture_count', 'count', |
nednguyen
2017/06/08 20:18:26
is this saved_picture_count value used by Cluster
lchoi
2017/06/08 20:38:34
Not sure if it will be used by CT - I was just fol
nednguyen
2017/06/08 21:39:26
Yeah. Code is liability, so it's usually better to
|
+ saved_picture_count)) |
+ |
nednguyen
2017/06/08 20:18:26
style nits: remove 3 blank lines
|
+ |
+ |