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

Side by Side Diff: tools/perf/contrib/cluster_telemetry/screenshot.py

Issue 2923163007: Implemented telemetry benchmark that loads page and outputs screenshot. (Closed)
Patch Set: Moved files to tools/perf/contrib/cluster_telemetry, more logging, detecting if run on Linux in uniā€¦ 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
« no previous file with comments | « no previous file | tools/perf/contrib/cluster_telemetry/screenshot_ct.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
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
nednguyen 2017/06/08 20:18:26 I suggest just leave this part out until someone i
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)
nednguyen 2017/06/08 20:18:26 if this timeout, this should return instead of kee
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 logging.info("Taking screenshot of %s", page.display_name)
nednguyen 2017/06/08 20:18:26 this log doesn't seem particularly useful IMO
51 screenshot = tab.Screenshot()
52
53 last_mod_time = 0
54 if os.path.exists(outpath):
55 last_mod_time = os.path.getmtime(outpath)
56
57 # TODO(lchoi): Add logging to image_util.py and/or augment error handling of
58 # image_util.WritePngFile
59 logging.info("Writing PNG file to %s", outpath)
60 image_util.WritePngFile(screenshot, outpath)
61 logging.info("PNG file written successfully")
62
63 saved_picture_count = 0
64 if os.path.exists(outpath) and os.path.getmtime(outpath) > last_mod_time:
nednguyen 2017/06/08 20:18:25 Why we need this logic? If the pgn file are not wr
lchoi 2017/06/08 20:38:34 I see. Do you want me to remove this and everythin
nednguyen 2017/06/08 21:39:26 sgtm
65 saved_picture_count = 1
66 results.AddValue(scalar.ScalarValue(
67 results.current_page, 'saved_picture_count', 'count',
nednguyen 2017/06/08 20:18:26 is this saved_picture_count value used by Cluster
lchoi 2017/06/08 20:38:34 Not sure if it will be used by CT - I was just fol
nednguyen 2017/06/08 21:39:26 Yeah. Code is liability, so it's usually better to
68 saved_picture_count))
69
nednguyen 2017/06/08 20:18:26 style nits: remove 3 blank lines
70
71
OLDNEW
« no previous file with comments | « no previous file | tools/perf/contrib/cluster_telemetry/screenshot_ct.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698