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

Unified Diff: tools/perf/measurements/screenshot.py

Issue 271733008: telemetry: add screenshot measurement (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Handle browsers/platforms that don't support screenshotting. Created 6 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
« no previous file with comments | « no previous file | tools/perf/measurements/screenshot_unittest.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/perf/measurements/screenshot.py
diff --git a/tools/perf/measurements/screenshot.py b/tools/perf/measurements/screenshot.py
new file mode 100644
index 0000000000000000000000000000000000000000..1459bcecea642d258c154ba6f64b33efa10e9f4b
--- /dev/null
+++ b/tools/perf/measurements/screenshot.py
@@ -0,0 +1,48 @@
+# Copyright 2014 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 os
+
+from telemetry.page import page_measurement
+from telemetry.page import page_test
+
+
+class Screenshot(page_measurement.PageMeasurement):
+ def __init__(self):
+ super(Screenshot, self).__init__(
+ action_name_to_run = 'RunPrepareForScreenshot',
+ is_action_name_to_run_optional=True)
+
+ @classmethod
+ def AddCommandLineArgs(cls, parser):
+ parser.add_option('--png-outdir',
+ help='Output directory for the PNG files')
+
+ @classmethod
+ def ProcessCommandLineArgs(cls, parser, args):
+ if not args.png_outdir:
+ parser.error('Please specify --png-outdir')
+ cls._png_outdir = args.png_outdir
+
+ def MeasurePage(self, page, tab, results):
+ if not tab.screenshot_supported:
+ raise page_test.TestNotSupportedOnPlatformFailure(
+ 'Browser does not support screenshotting')
+
+ tab.WaitForDocumentReadyStateToBeComplete()
+ screenshot = tab.Screenshot(60)
+
+ outpath = os.path.abspath(
+ os.path.join(self._png_outdir, page.file_safe_name)) + '.png'
+
+ if os.path.exists(outpath):
+ previous_mtime = os.path.getmtime(outpath)
+ else:
+ previous_mtime = -1
+
+ screenshot.WritePngFile(outpath)
+
+ saved_picture_count = 0
+ if os.path.exists(outpath) and os.path.getmtime(outpath) > previous_mtime:
+ saved_picture_count = 1
+ results.Add('saved_picture_count', 'count', saved_picture_count)
« no previous file with comments | « no previous file | tools/perf/measurements/screenshot_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698