Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(112)

Unified Diff: tools/perf/contrib/cluster_telemetry/screenshot.py

Issue 2923163007: Implemented telemetry benchmark that loads page and outputs screenshot. (Closed)
Patch Set: More detailed logging, unit test now returns if not Linux Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..cc25813ce1e0ce9224827b195d3a3d8c307fbe1a
--- /dev/null
+++ b/tools/perf/contrib/cluster_telemetry/screenshot.py
@@ -0,0 +1,56 @@
+# 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.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):
+ super(Screenshot, self).__init__()
+ self._png_outdir = png_outdir
+ self._wait_time = wait_time
+
+ 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",
wkorman 2017/06/09 17:59:53 This should be warning level (just replace info wi
+ page.display_name)
+ return
+
+ 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)
wkorman 2017/06/09 17:59:54 warning level
+ 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('\\', '\\\\')
+
+ screenshot = tab.Screenshot()
+
+ # TODO(lchoi): Add logging to image_util.py and/or augment error handling of
+ # image_util.WritePngFile
+ logging.info("Writing PNG file to %s. This may take awhile.", outpath)
+ start = time.time()
+ image_util.WritePngFile(screenshot, outpath)
+ logging.info("PNG file written successfully. (Took %f seconds)",
+ time.time()-start)

Powered by Google App Engine
This is Rietveld 408576698