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

Unified Diff: tools/perf/perf_tools/media_metrics.py

Issue 16854013: Telemetry media_measurement plus play action and tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Split measurement JS from action JS. Wrap JS access in Py class. Add more unit tests. Created 7 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 side-by-side diff with in-line comments
Download patch
Index: tools/perf/perf_tools/media_metrics.py
diff --git a/tools/perf/perf_tools/media_metrics.py b/tools/perf/perf_tools/media_metrics.py
new file mode 100644
index 0000000000000000000000000000000000000000..6652d2191be9d98c2f8453a2ce63baa75abf973a
--- /dev/null
+++ b/tools/perf/perf_tools/media_metrics.py
@@ -0,0 +1,91 @@
+# Copyright (c) 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
+
+
+class MediaMetrics(object):
+ def __init__(self, tab):
+ # Measurement class and media actions class can both load media_metrics.js.
nduca 2013/07/09 23:07:19 is this comment still true?
shadi 2013/07/11 00:49:13 Oops, removed.
+ deps_found = tab.EvaluateJavaScript('window.__mediaRecorders != undefined')
+ if not deps_found:
+ with open(
+ os.path.join(os.path.dirname(__file__), 'media_metrics.js')) as f:
+ js = f.read()
+ tab.ExecuteJavaScript(js)
+ self.tab = tab
+
nduca 2013/07/09 23:07:19 you should have a Start/Stop/Add in style of memor
+ def ReportCollectedMetrics(self, results):
nduca 2013/07/09 23:07:19 your naming shoudl conform to memory_metrics.py
shadi 2013/07/11 00:49:13 Done.
+ """Reports all recorded metrics as Telemetry perf results.
+
+ Metrics are recorded for each media element in the page. Each metric result
+ has media info + metric values as a map, for example:
+ Media metric = {
+ 'info': {
+ 'src': 'file.webm',
+ 'id': 'video1',
+ ...
+ },
+ 'metrics': {
+ 'ttp': [120, 'ms'],
+ 'decoded_bytes': [13233, 'bytes'],
+ ...
+ }
+ }
+ """
+ media_metrics = self.tab.EvaluateJavaScript('window.__getAllMetrics()')
+ for media_metric in media_metrics:
+ AddResult(media_metric, results)
+
+
+def AddResult(media_metric, results):
+ """Adds the media metric result to global results, needed for graphing."""
+ info = media_metric['info']
+ metrics = media_metric['metrics']
+ for metric in metrics:
nduca 2013/07/09 23:07:19 i'd love this to be a bit more strongly typed. Whe
shadi 2013/07/11 00:49:13 The idea is that we don't know how many metrics ha
+ value, units = GetValueUnit(metrics[metric])
+ if not units:
+ logging.error('Missing units value for media metric %s.', metric)
+ continue
+ trace = GetTraceName(info)
+ results.Add(trace, units, value, chart_name=metric, data_type='default')
+
+
+def GetValueUnit(metric):
+ """Returns a (value, units) pair stored in a metric if available."""
+ if isinstance(metric, (list, tuple)):
nduca 2013/07/09 23:07:19 per note above, rather this wasn't here and you ha
shadi 2013/07/11 00:49:13 See earlier comment.
+ if len(metric) > 1:
+ return (metric[0], metric[1])
+ else:
+ return (metric[0], None)
+ return (metric, None)
+
+
+def GetTraceName(info):
nduca 2013/07/09 23:07:19 per note above, rather this wasn't here and you ha
shadi 2013/07/11 00:49:13 See earlier comment.
+ """Returns a media trace name based on the metric info map.
+
+ In order, returns the first available:
+ - 'id' key value.
+ - file name based on 'src' key value.
+ - the first key value available.
+ - 'no_trace'.
+ """
+ if 'id' in info:
+ return info['id']
+ elif 'src' in info:
+ # Return only file name in src.
+ src = info['src']
+ return src[src.rfind('/') + 1:]
+ else:
+ for key in info:
+ return info[key]
+ return 'no_trace'

Powered by Google App Engine
This is Rietveld 408576698