diff options
Diffstat (limited to 'tools/perf/metrics/media.py')
-rw-r--r-- | tools/perf/metrics/media.py | 57 |
1 files changed, 30 insertions, 27 deletions
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') + |