diff options
author | qyearsley@chromium.org <qyearsley@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-08-06 23:08:50 +0000 |
---|---|---|
committer | qyearsley@chromium.org <qyearsley@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-08-06 23:08:50 +0000 |
commit | cff0989e82707de328120cf8317840e163ae6d9e (patch) | |
tree | 8853db87df92bf7f56567baf1dc19c695aca4890 /tools/perf | |
parent | 3a11167afea92d8de845a75ffe4b1db175978780 (diff) | |
download | chromium_src-cff0989e82707de328120cf8317840e163ae6d9e.zip chromium_src-cff0989e82707de328120cf8317840e163ae6d9e.tar.gz chromium_src-cff0989e82707de328120cf8317840e163ae6d9e.tar.bz2 |
Make MediaMetric a subclass of Metric
BUG=
Review URL: https://chromiumcodereview.appspot.com/22298004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@216015 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools/perf')
-rw-r--r-- | tools/perf/measurements/media.py | 23 | ||||
-rw-r--r-- | tools/perf/metrics/media.py | 57 |
2 files changed, 40 insertions, 40 deletions
diff --git a/tools/perf/measurements/media.py b/tools/perf/measurements/media.py index 5ac2048..4d2ffcf 100644 --- a/tools/perf/measurements/media.py +++ b/tools/perf/measurements/media.py @@ -2,22 +2,18 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. -"""Media measurement class gathers media related metrics on a page set. - -Media metrics recorded are controlled by metrics/media.js. At the end of the -test each metrics for every media element in the page are reported. -""" -import metrics.media - +from metrics import media from telemetry.page import page_measurement - class Media(page_measurement.PageMeasurement): - """Provide general video and audio metrics.""" + """The MediaMeasurement class gathers media-related metrics on a page set. + Media metrics recorded are controlled by metrics/media.js. At the end of the + test each metric for every media element in the page are reported. + """ def __init__(self): super(Media, self).__init__('media_metrics') - self.metrics = None + self._media_metric = None def results_are_the_same_on_every_page(self): """Results can vary from page to page based on media events taking place.""" @@ -25,9 +21,10 @@ class Media(page_measurement.PageMeasurement): def DidNavigateToPage(self, page, tab): """Override to do operations right after the page is navigated.""" - self.metrics = metrics.media.MediaMetrics(tab) - self.metrics.Start() + self._media_metric = media.MediaMetric(tab) + self._media_metric.Start(page, tab) def MeasurePage(self, page, tab, results): """Measure the page's performance.""" - self.metrics.StopAndGetResults(results) + self._media_metric.Stop(page, tab) + self._media_metric.AddResults(tab, results) diff --git a/tools/perf/metrics/media.py b/tools/perf/metrics/media.py index 3f3df23..282c9bd 100644 --- a/tools/perf/metrics/media.py +++ b/tools/perf/metrics/media.py @@ -1,37 +1,39 @@ # Copyright 2013 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. - -"""Media Metrics class injects and calls JS responsible for recording metrics. - -Default media metrics are collected for every media element in the page, such as -decoded_frame_count, dropped_frame_count, decoded_video_bytes, and -decoded_audio_bytes. -""" - import logging import os +from metrics import Metric -class MediaMetrics(object): +class MediaMetric(Metric): + """MediaMetric class injects and calls JS responsible for recording metrics. + + Default media metrics are collected for every media element in the page, + such as decoded_frame_count, dropped_frame_count, decoded_video_bytes, and + decoded_audio_bytes. + """ def __init__(self, tab): - with open( - os.path.join(os.path.dirname(__file__), 'media.js')) as f: + super(MediaMetric, self).__init__() + with open(os.path.join(os.path.dirname(__file__), 'media.js')) as f: js = f.read() tab.ExecuteJavaScript(js) - self.tab = tab + self._results = None - def Start(self): + def Start(self, page, tab): """Create the media metrics for all media elements in the document.""" - self.tab.ExecuteJavaScript('window.__createMediaMetricsForDocument()') + tab.ExecuteJavaScript('window.__createMediaMetricsForDocument()') + + def Stop(self, page, tab): + self._results = tab.EvaluateJavaScript('window.__getAllMetrics()') - def StopAndGetResults(self, results): + def AddResults(self, tab, results): """Reports all recorded metrics as Telemetry perf results.""" - media_metrics = self.tab.EvaluateJavaScript('window.__getAllMetrics()') - for media_metric in media_metrics: - self.AddResultsForMediaElement(media_metric, results) + assert self._results + for media_metric in self._results: + self._AddResultsForMediaElement(media_metric, results) - def AddResultsForMediaElement(self, media_metric, results): + def _AddResultsForMediaElement(self, media_metric, results): """Reports metrics for one media element. Media metrics contain an ID identifying the media element and values: @@ -44,7 +46,7 @@ class MediaMetrics(object): } } """ - def AddResults(metric, unit): + def AddOneResult(metric, unit): metrics = media_metric['metrics'] for m in metrics: if m.startswith(metric): @@ -56,10 +58,11 @@ class MediaMetrics(object): if not trace: logging.error('Metrics ID is missing in results.') return - AddResults('decoded_audio_bytes', 'bytes') - AddResults('decoded_video_bytes', 'bytes') - AddResults('decoded_frame_count', 'frames') - AddResults('dropped_frame_count', 'frames') - AddResults('playback_time', 'sec') - AddResults('seek', 'sec') - AddResults('time_to_play', 'sec') + AddOneResult('decoded_audio_bytes', 'bytes') + AddOneResult('decoded_video_bytes', 'bytes') + AddOneResult('decoded_frame_count', 'frames') + AddOneResult('dropped_frame_count', 'frames') + AddOneResult('playback_time', 'sec') + AddOneResult('seek', 'sec') + AddOneResult('time_to_play', 'sec') + |