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

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

Issue 2923163007: Implemented telemetry benchmark that loads page and outputs screenshot. (Closed)
Patch Set: 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/measurements/pixel_diff.py
diff --git a/tools/perf/measurements/pixel_diff.py b/tools/perf/measurements/pixel_diff.py
new file mode 100644
index 0000000000000000000000000000000000000000..ab907d02ae40d442a661ddc02cb26942018a8d9b
--- /dev/null
+++ b/tools/perf/measurements/pixel_diff.py
@@ -0,0 +1,55 @@
+# 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 os
wkorman 2017/06/07 20:15:11 +1 space above
+import time
+import py_utils
+
+from telemetry.page import legacy_page_test
+from telemetry.value import scalar
+from telemetry.util import image_util
+
+class PixelDiff(legacy_page_test.LegacyPageTest):
wkorman 2017/06/07 20:15:11 Add doc comment describing purpose. See power.py w
rmistry 2017/06/08 13:08:56 I agree that 'screenshot' might be a better name h
+
+ def __init__(self, png_outdir, wait_time=0, disable_javascript=False):
+ super(PixelDiff, self).__init__()
+ self._png_outdir = png_outdir
+ self._wait_time = wait_time
+ self._disable_javascript = disable_javascript
wkorman 2017/06/07 20:15:11 Same as previous: remove for now or comment to not
+
+ def ValidateAndMeasurePage(self, page, tab, results):
wkorman 2017/06/07 20:15:11 Do we have sufficient useful log output when we ru
+ if not tab.screenshot_supported:
+ raise legacy_page_test.MeasurementFailure(
+ 'Screenshotting not supported on this platform')
+
+ try:
+ tab.WaitForDocumentReadyStateToBeComplete()
+ except py_utils.TimeoutException:
+ pass
wkorman 2017/06/07 20:15:11 I see this is what rasterize_and_record_micro does
nednguyen 2017/06/07 20:32:12 I think if we timeout here, it's better to report
rmistry 2017/06/08 13:08:56 Agreed, we should report a descriptive error. In C
+ time.sleep(self._wait_time)
+
+ if not os.path.exists(self._png_outdir):
+ os.makedirs(self._png_outdir)
wkorman 2017/06/07 20:15:11 If we fail to makedir (and probably some other os
rmistry 2017/06/08 13:08:56 I think it's ok to propagate the exception in case
+
+ 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()
wkorman 2017/06/07 20:15:12 This can raise a few exceptions, should we catch a
rmistry 2017/06/08 13:08:56 Hopefully the exception from Screenshot() will be
+
+ last_mod_time = 0
+ if os.path.exists(outpath):
+ last_mod_time = os.path.getmtime(outpath)
+
+ image_util.WritePngFile(screenshot, outpath)
wkorman 2017/06/07 20:15:11 Error handling -- it looks like this can throw som
+
+ saved_picture_count = 0
+ if os.path.exists(outpath) and os.path.getmtime(outpath) > last_mod_time:
+ saved_picture_count = 1
+ results.AddValue(scalar.ScalarValue(
+ results.current_page, 'saved_picture_count', 'count',
+ saved_picture_count))
+
+
+

Powered by Google App Engine
This is Rietveld 408576698