| OLD | NEW |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import json | 5 import json |
| 6 import logging |
| 7 import re |
| 6 | 8 |
| 7 from metrics import Metric | 9 from metrics import Metric |
| 8 from telemetry.core import camel_case | 10 from telemetry.core import camel_case |
| 9 from telemetry.value import list_of_scalar_values | 11 from telemetry.value import list_of_scalar_values |
| 10 | 12 |
| 11 INTERESTING_METRICS = { | 13 INTERESTING_METRICS = { |
| 12 'packetsReceived': { | 14 'packetsReceived': { |
| 13 'units': 'packets', | 15 'units': 'packets', |
| 14 'description': 'Packets received by the peer connection', | 16 'description': 'Packets received by the peer connection', |
| 15 }, | 17 }, |
| 16 'packetsSent': { | 18 'packetsSent': { |
| 17 'units': 'packets', | 19 'units': 'packets', |
| 18 'description': 'Packets sent by the peer connection', | 20 'description': 'Packets sent by the peer connection', |
| 19 }, | 21 }, |
| 20 'googDecodeMs': { | 22 'googDecodeMs': { |
| 21 'units': 'ms', | 23 'units': 'ms', |
| 22 'description': 'Time spent decoding.', | 24 'description': 'Time spent decoding.', |
| 23 }, | 25 }, |
| 24 'googMaxDecodeMs': { | 26 'googMaxDecodeMs': { |
| 25 'units': 'ms', | 27 'units': 'ms', |
| 26 'description': 'Maximum time spent decoding one frame.', | 28 'description': 'Maximum time spent decoding one frame.', |
| 27 }, | 29 }, |
| 28 # TODO(phoglund): Add much more interesting metrics. | 30 # TODO(phoglund): Add much more interesting metrics. |
| 29 } | 31 } |
| 30 | 32 |
| 33 |
| 34 def GetReportKind(report): |
| 35 if 'audioInputLevel' in report or 'audioOutputLevel' in report: |
| 36 return 'audio' |
| 37 if 'googFrameRateSent' in report or 'googFrameRateReceived' in report: |
| 38 return 'video' |
| 39 |
| 40 logging.error('Did not recognize report batch: %s.', report.keys()) |
| 41 return 'unknown' |
| 42 |
| 43 |
| 44 def DistinguishAudioAndVideo(report, stat_name): |
| 45 return GetReportKind(report) + '_' + stat_name |
| 46 |
| 47 |
| 48 def StripAudioVideoDistinction(stat_name): |
| 49 return re.sub('^(audio|video)_', '', stat_name) |
| 50 |
| 51 |
| 31 def SortStatsIntoTimeSeries(report_batches): | 52 def SortStatsIntoTimeSeries(report_batches): |
| 32 time_series = {} | 53 time_series = {} |
| 33 for report_batch in report_batches: | 54 for report_batch in report_batches: |
| 34 for report in report_batch: | 55 for report in report_batch: |
| 35 for stat_name, value in report.iteritems(): | 56 for stat_name, value in report.iteritems(): |
| 36 if stat_name not in INTERESTING_METRICS: | 57 if stat_name not in INTERESTING_METRICS: |
| 37 continue | 58 continue |
| 38 time_series.setdefault(stat_name, []).append(float(value)) | 59 full_stat_name = DistinguishAudioAndVideo(report, stat_name) |
| 60 time_series.setdefault(full_stat_name, []).append(float(value)) |
| 39 | 61 |
| 40 return time_series | 62 return time_series |
| 41 | 63 |
| 42 | 64 |
| 43 class WebRtcStatisticsMetric(Metric): | 65 class WebRtcStatisticsMetric(Metric): |
| 44 """Makes it possible to measure stats from peer connections.""" | 66 """Makes it possible to measure stats from peer connections.""" |
| 45 | 67 |
| 46 def __init__(self): | 68 def __init__(self): |
| 47 super(WebRtcStatisticsMetric, self).__init__() | 69 super(WebRtcStatisticsMetric, self).__init__() |
| 48 self._all_reports = None | 70 self._all_reports = None |
| (...skipping 10 matching lines...) Expand all Loading... |
| 59 if not self._all_reports: | 81 if not self._all_reports: |
| 60 return | 82 return |
| 61 | 83 |
| 62 reports = json.loads(self._all_reports) | 84 reports = json.loads(self._all_reports) |
| 63 for i, report in enumerate(reports): | 85 for i, report in enumerate(reports): |
| 64 time_series = SortStatsIntoTimeSeries(report) | 86 time_series = SortStatsIntoTimeSeries(report) |
| 65 | 87 |
| 66 for stat_name, values in time_series.iteritems(): | 88 for stat_name, values in time_series.iteritems(): |
| 67 stat_name_underscored = camel_case.ToUnderscore(stat_name) | 89 stat_name_underscored = camel_case.ToUnderscore(stat_name) |
| 68 trace_name = 'peer_connection_%d_%s' % (i, stat_name_underscored) | 90 trace_name = 'peer_connection_%d_%s' % (i, stat_name_underscored) |
| 91 general_name = StripAudioVideoDistinction(stat_name) |
| 69 results.AddValue(list_of_scalar_values.ListOfScalarValues( | 92 results.AddValue(list_of_scalar_values.ListOfScalarValues( |
| 70 results.current_page, trace_name, | 93 results.current_page, trace_name, |
| 71 INTERESTING_METRICS[stat_name]['units'], values, | 94 INTERESTING_METRICS[general_name]['units'], values, |
| 72 description=INTERESTING_METRICS[stat_name]['description'], | 95 description=INTERESTING_METRICS[general_name]['description'], |
| 73 important=False)) | 96 important=False)) |
| OLD | NEW |