OLD | NEW |
(Empty) | |
| 1 # Copyright 2014 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 json |
| 6 |
| 7 from metrics import Metric |
| 8 from telemetry.core import camel_case |
| 9 from telemetry.value import list_of_scalar_values |
| 10 |
| 11 INTERESTING_METRICS = { |
| 12 'packetsReceived': { |
| 13 'units': 'packets', |
| 14 'description': 'Packets received by the peer connection', |
| 15 }, |
| 16 'packetsSent': { |
| 17 'units': 'packets', |
| 18 'description': 'Packets sent by the peer connection', |
| 19 }, |
| 20 'googDecodeMs': { |
| 21 'units': 'ms', |
| 22 'description': 'Time spent decoding.', |
| 23 }, |
| 24 'googMaxDecodeMs': { |
| 25 'units': 'ms', |
| 26 'description': 'Maximum time spent decoding one frame.', |
| 27 }, |
| 28 # TODO(phoglund): Add much more interesting metrics. |
| 29 } |
| 30 |
| 31 def SortStatsIntoTimeSeries(report_batches): |
| 32 time_series = {} |
| 33 for report_batch in report_batches: |
| 34 for report in report_batch: |
| 35 for stat_name, value in report.iteritems(): |
| 36 if stat_name not in INTERESTING_METRICS: |
| 37 continue |
| 38 time_series.setdefault(stat_name, []).append(float(value)) |
| 39 |
| 40 return time_series |
| 41 |
| 42 |
| 43 class WebRtcStatisticsMetric(Metric): |
| 44 """Makes it possible to measure stats from peer connections.""" |
| 45 |
| 46 def __init__(self): |
| 47 super(WebRtcStatisticsMetric, self).__init__() |
| 48 self._all_reports = None |
| 49 |
| 50 def Start(self, page, tab): |
| 51 pass |
| 52 |
| 53 def Stop(self, page, tab): |
| 54 """Digs out stats from data populated by the javascript in webrtc_cases.""" |
| 55 self._all_reports = tab.EvaluateJavaScript( |
| 56 'JSON.stringify(window.peerConnectionReports)') |
| 57 |
| 58 def AddResults(self, tab, results): |
| 59 if not self._all_reports: |
| 60 return |
| 61 |
| 62 reports = json.loads(self._all_reports) |
| 63 for i, report in enumerate(reports): |
| 64 time_series = SortStatsIntoTimeSeries(report) |
| 65 |
| 66 for stat_name, values in time_series.iteritems(): |
| 67 stat_name_underscored = camel_case.ToUnderscore(stat_name) |
| 68 trace_name = 'peer_connection_%d_%s' % (i, stat_name_underscored) |
| 69 results.AddValue(list_of_scalar_values.ListOfScalarValues( |
| 70 results.current_page, trace_name, |
| 71 INTERESTING_METRICS[stat_name]['units'], values, |
| 72 description=INTERESTING_METRICS[stat_name]['description'], |
| 73 important=False)) |
OLD | NEW |