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: | |
tonyg
2014/09/29 16:45:21
Are there cases when this is expected? If not, per
phoglund_chromium
2014/09/30 13:37:48
Yes, the list will be empty if a page didn't end u
| |
60 return | |
61 | |
62 reports = json.loads(self._all_reports) | |
63 num_peer_connections = len(reports) | |
64 for i in xrange(num_peer_connections): | |
phoglund_chromium
2014/09/12 08:26:07
This is arguably complex enough to warrant a unit
tonyg
2014/09/29 16:45:22
Better written as:
for i, peer_connection in enume
tonyg
2014/09/29 16:45:22
Definitely. The main value is that without a unitt
phoglund_chromium
2014/09/30 13:37:48
Hm. I don't think I should play an actual WebRTC s
phoglund_chromium
2014/09/30 13:37:48
Done.
| |
65 time_series = SortStatsIntoTimeSeries(reports[i]) | |
66 | |
67 for stat_name, values in time_series.iteritems(): | |
68 trace_name = 'pc_%d_%s' % (i, camel_case.ToUnderscore(stat_name)) | |
tonyg
2014/09/29 16:45:21
What is "pc_"? I recommend a more friendly name he
phoglund_chromium
2014/09/30 13:37:48
Done.
| |
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 |