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

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

Issue 2923163007: Implemented telemetry benchmark that loads page and outputs screenshot. (Closed)
Patch Set: Removed mtime, saved_picture_count, javascript flag, Edited unittest 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..15fc0c061194df37802b77098579c2fb61733e04
--- /dev/null
+++ b/tools/perf/contrib/cluster_telemetry/screenshot.py
@@ -0,0 +1,54 @@
+# 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",
+ 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)
+ 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", outpath)
wkorman 2017/06/08 23:14:41 For nednguyen@: I asked Lawrence to add this and t
nednguyen 2017/06/09 00:08:22 I see. If this take long time when you run it loca
+ image_util.WritePngFile(screenshot, outpath)
+ logging.info("PNG file written successfully")

Powered by Google App Engine
This is Rietveld 408576698