| 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 | 6 import logging |
| 7 import re | 7 import re |
| 8 | 8 |
| 9 from metrics import Metric | 9 from metrics import Metric |
| 10 from telemetry.core import camel_case | 10 from telemetry.core import camel_case |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 # TODO(phoglund): Add much more interesting metrics. | 30 # TODO(phoglund): Add much more interesting metrics. |
| 31 } | 31 } |
| 32 | 32 |
| 33 | 33 |
| 34 def GetReportKind(report): | 34 def GetReportKind(report): |
| 35 if 'audioInputLevel' in report or 'audioOutputLevel' in report: | 35 if 'audioInputLevel' in report or 'audioOutputLevel' in report: |
| 36 return 'audio' | 36 return 'audio' |
| 37 if 'googFrameRateSent' in report or 'googFrameRateReceived' in report: | 37 if 'googFrameRateSent' in report or 'googFrameRateReceived' in report: |
| 38 return 'video' | 38 return 'video' |
| 39 | 39 |
| 40 logging.error('Did not recognize report batch: %s.', report.keys()) | 40 logging.debug('Did not recognize report batch: %s.', report.keys()) |
| 41 # There are other kinds of reports, such as bwestats, which we don't care |
| 42 # about here. For these cases just return 'unknown' which will ignore the |
| 43 # report |
| 41 return 'unknown' | 44 return 'unknown' |
| 42 | 45 |
| 43 | 46 |
| 44 def DistinguishAudioAndVideo(report, stat_name): | 47 def DistinguishAudioAndVideo(report, stat_name): |
| 45 return GetReportKind(report) + '_' + stat_name | 48 return GetReportKind(report) + '_' + stat_name |
| 46 | 49 |
| 47 | 50 |
| 48 def StripAudioVideoDistinction(stat_name): | 51 def StripAudioVideoDistinction(stat_name): |
| 49 return re.sub('^(audio|video)_', '', stat_name) | 52 return re.sub('^(audio|video)_', '', stat_name) |
| 50 | 53 |
| 51 | 54 |
| 52 def SortStatsIntoTimeSeries(report_batches): | 55 def SortStatsIntoTimeSeries(report_batches): |
| 53 time_series = {} | 56 time_series = {} |
| 54 for report_batch in report_batches: | 57 for report_batch in report_batches: |
| 55 for report in report_batch: | 58 for report in report_batch: |
| 56 for stat_name, value in report.iteritems(): | 59 for stat_name, value in report.iteritems(): |
| 57 if stat_name not in INTERESTING_METRICS: | 60 if stat_name not in INTERESTING_METRICS: |
| 58 continue | 61 continue |
| 62 if GetReportKind(report) == 'unknown': |
| 63 continue |
| 59 full_stat_name = DistinguishAudioAndVideo(report, stat_name) | 64 full_stat_name = DistinguishAudioAndVideo(report, stat_name) |
| 60 time_series.setdefault(full_stat_name, []).append(float(value)) | 65 time_series.setdefault(full_stat_name, []).append(float(value)) |
| 61 | 66 |
| 62 return time_series | 67 return time_series |
| 63 | 68 |
| 64 | 69 |
| 65 class WebRtcStatisticsMetric(Metric): | 70 class WebRtcStatisticsMetric(Metric): |
| 66 """Makes it possible to measure stats from peer connections.""" | 71 """Makes it possible to measure stats from peer connections.""" |
| 67 | 72 |
| 68 def __init__(self): | 73 def __init__(self): |
| (...skipping 18 matching lines...) Expand all Loading... |
| 87 | 92 |
| 88 for stat_name, values in time_series.iteritems(): | 93 for stat_name, values in time_series.iteritems(): |
| 89 stat_name_underscored = camel_case.ToUnderscore(stat_name) | 94 stat_name_underscored = camel_case.ToUnderscore(stat_name) |
| 90 trace_name = 'peer_connection_%d_%s' % (i, stat_name_underscored) | 95 trace_name = 'peer_connection_%d_%s' % (i, stat_name_underscored) |
| 91 general_name = StripAudioVideoDistinction(stat_name) | 96 general_name = StripAudioVideoDistinction(stat_name) |
| 92 results.AddValue(list_of_scalar_values.ListOfScalarValues( | 97 results.AddValue(list_of_scalar_values.ListOfScalarValues( |
| 93 results.current_page, trace_name, | 98 results.current_page, trace_name, |
| 94 INTERESTING_METRICS[general_name]['units'], values, | 99 INTERESTING_METRICS[general_name]['units'], values, |
| 95 description=INTERESTING_METRICS[general_name]['description'], | 100 description=INTERESTING_METRICS[general_name]['description'], |
| 96 important=False)) | 101 important=False)) |
| OLD | NEW |