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

Side by Side Diff: tools/perf/measurements/screenshot.py

Issue 2923163007: Implemented telemetry benchmark that loads page and outputs screenshot. (Closed)
Patch Set: Changed name to Screenshot, added logging, error handling, more descriptive comments 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.
nednguyen 2017/06/08 18:15:19 Actually this measurement & the unittest files sho
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5 import logging
6 import os
7 import py_utils
8 import time
9
10 from telemetry.page import legacy_page_test
11 from telemetry.value import scalar
12 from telemetry.util import image_util
13
14 class Screenshot(legacy_page_test.LegacyPageTest):
15 """Takes a PNG screenshot of the page."""
16
17 def __init__(self, png_outdir, wait_time=0, disable_javascript=False):
18 super(Screenshot, self).__init__()
19 self._png_outdir = png_outdir
20 self._wait_time = wait_time
21 # Javascript flag not yet implemented
22 self._disable_javascript = disable_javascript
23
24 def ValidateAndMeasurePage(self, page, tab, results):
25 if not tab.screenshot_supported:
26 raise legacy_page_test.MeasurementFailure(
27 'Screenshotting not supported on this platform')
28
29 try:
30 tab.WaitForDocumentReadyStateToBeComplete()
31 except py_utils.TimeoutException:
32 logging.info("WaitForDocumentReadyStateToBeComplete() timeout, page: %s",
33 page.display_name)
34
35 time.sleep(self._wait_time)
36
37 if not os.path.exists(self._png_outdir):
38 logging.info("Creating directory %s", self._png_outdir)
39 try:
40 os.makedirs(self._png_outdir)
41 except OSError:
42 logging.info("Directory %s could not be created", self._png_outdir)
43 raise
44
45 outpath = os.path.abspath(
46 os.path.join(self._png_outdir, page.file_safe_name)) + '.png'
47 # Replace win32 path separator char '\' with '\\'.
48 outpath = outpath.replace('\\', '\\\\')
49
50 screenshot = tab.Screenshot()
wkorman 2017/06/08 17:57:53 Add logging.info before this call to note we're st
51
52 last_mod_time = 0
53 if os.path.exists(outpath):
54 last_mod_time = os.path.getmtime(outpath)
55
56 # TODO(lchoi): Add logging to image_util.py and/or augment error handling of
57 # image_util.WritePngFile
58 image_util.WritePngFile(screenshot, outpath)
wkorman 2017/06/08 17:57:52 Add logging.info message before call to WritePngFi
59
wkorman 2017/06/08 17:57:53 And one more logging.info after we wrote it to mak
60 saved_picture_count = 0
61 if os.path.exists(outpath) and os.path.getmtime(outpath) > last_mod_time:
62 saved_picture_count = 1
63 results.AddValue(scalar.ScalarValue(
64 results.current_page, 'saved_picture_count', 'count',
65 saved_picture_count))
66
67
68
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698