Chromium Code Reviews| 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..3c348959e0dab5a868841195ff1ec80cc2446018 |
| --- /dev/null |
| +++ b/tools/perf/measurements/screenshot.py |
| @@ -0,0 +1,68 @@ |
| +# Copyright 2017 The Chromium Authors. All rights reserved. |
|
nednguyen
2017/06/08 18:15:19
Actually this measurement & the unittest files sho
|
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| + |
| +import logging |
| +import os |
| +import py_utils |
| +import time |
| + |
| +from telemetry.page import legacy_page_test |
| +from telemetry.value import scalar |
| +from telemetry.util import image_util |
| + |
| +class Screenshot(legacy_page_test.LegacyPageTest): |
| + """Takes a PNG screenshot of the page.""" |
| + |
| + def __init__(self, png_outdir, wait_time=0, disable_javascript=False): |
| + super(Screenshot, self).__init__() |
| + self._png_outdir = png_outdir |
| + self._wait_time = wait_time |
| + # Javascript flag not yet implemented |
| + self._disable_javascript = disable_javascript |
| + |
| + def ValidateAndMeasurePage(self, page, tab, results): |
| + if not tab.screenshot_supported: |
| + raise legacy_page_test.MeasurementFailure( |
| + 'Screenshotting not supported on this platform') |
| + |
| + try: |
| + tab.WaitForDocumentReadyStateToBeComplete() |
| + except py_utils.TimeoutException: |
| + logging.info("WaitForDocumentReadyStateToBeComplete() timeout, page: %s", |
| + page.display_name) |
| + |
| + time.sleep(self._wait_time) |
| + |
| + if not os.path.exists(self._png_outdir): |
| + logging.info("Creating directory %s", self._png_outdir) |
| + try: |
| + os.makedirs(self._png_outdir) |
| + except OSError: |
| + logging.info("Directory %s could not be created", self._png_outdir) |
| + raise |
| + |
| + 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/08 17:57:53
Add logging.info before this call to note we're st
|
| + |
| + last_mod_time = 0 |
| + if os.path.exists(outpath): |
| + last_mod_time = os.path.getmtime(outpath) |
| + |
| + # TODO(lchoi): Add logging to image_util.py and/or augment error handling of |
| + # image_util.WritePngFile |
| + image_util.WritePngFile(screenshot, outpath) |
|
wkorman
2017/06/08 17:57:52
Add logging.info message before call to WritePngFi
|
| + |
|
wkorman
2017/06/08 17:57:53
And one more logging.info after we wrote it to mak
|
| + 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)) |
| + |
| + |
| + |