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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 # Copyright 2017 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4 import os
wkorman 2017/06/07 20:15:11 +1 space above
5 import time
6 import py_utils
7
8 from telemetry.page import legacy_page_test
9 from telemetry.value import scalar
10 from telemetry.util import image_util
11
12 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
13
14 def __init__(self, png_outdir, wait_time=0, disable_javascript=False):
15 super(PixelDiff, self).__init__()
16 self._png_outdir = png_outdir
17 self._wait_time = wait_time
18 self._disable_javascript = disable_javascript
wkorman 2017/06/07 20:15:11 Same as previous: remove for now or comment to not
19
20 def ValidateAndMeasurePage(self, page, tab, results):
wkorman 2017/06/07 20:15:11 Do we have sufficient useful log output when we ru
21 if not tab.screenshot_supported:
22 raise legacy_page_test.MeasurementFailure(
23 'Screenshotting not supported on this platform')
24
25 try:
26 tab.WaitForDocumentReadyStateToBeComplete()
27 except py_utils.TimeoutException:
28 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
29 time.sleep(self._wait_time)
30
31 if not os.path.exists(self._png_outdir):
32 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
33
34 outpath = os.path.abspath(
35 os.path.join(self._png_outdir, page.file_safe_name)) + '.png'
36 # Replace win32 path separator char '\' with '\\'.
37 outpath = outpath.replace('\\', '\\\\')
38
39 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
40
41 last_mod_time = 0
42 if os.path.exists(outpath):
43 last_mod_time = os.path.getmtime(outpath)
44
45 image_util.WritePngFile(screenshot, outpath)
wkorman 2017/06/07 20:15:11 Error handling -- it looks like this can throw som
46
47 saved_picture_count = 0
48 if os.path.exists(outpath) and os.path.getmtime(outpath) > last_mod_time:
49 saved_picture_count = 1
50 results.AddValue(scalar.ScalarValue(
51 results.current_page, 'saved_picture_count', 'count',
52 saved_picture_count))
53
54
55
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698