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

Side by Side Diff: tools/perf/metrics/network.py

Issue 22539003: [Telemetry] Report network metrics for the page cycler. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 7 years, 4 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 unified diff | Download patch
« no previous file with comments | « tools/perf/measurements/page_cycler.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 # Copyright 2013 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
9 _COUNTER_TO_RESULTS = {
10 'tcp.read_bytes': ('tcp_read_bytes', 'bytes'),
11 'tcp.write_bytes': ('tcp_write_bytes', 'bytes'),
12 'HttpNetworkTransaction.Count': ('num_requests', 'count'),
13 'tcp.connect': ('num_connects', 'count'),
14 'spdy.sessions': ('num_spdy_sessions', 'count'),
15 }
16
17 class NetworkMetric(Metric):
18 """A metric for network information."""
19
20 def __init__(self):
21 super(NetworkMetric, self).__init__()
22 self._results = None
23
24 def _GetCounters(self, tab):
25 return tab.EvaluateJavaScript("""
26 (function(counters) {
27 var results = {};
28 if (!window.chrome || !window.chrome.benchmarking)
29 return results;
30 for (var i = 0; i < counters.length; i++)
31 results[counters[i]] = chrome.benchmarking.counter(counters[i]);
32 return results;
33 })(%s);
34 """ % json.dumps(_COUNTER_TO_RESULTS.keys()))
35
36 def Start(self, page, tab):
37 assert not self._results, 'Must AddResults() before calling Start() again.'
38 self._results = self._GetCounters(tab)
39
40 def Stop(self, page, tab):
41 assert self._results, 'Must Start() before Stop().'
42 results = self._GetCounters(tab)
43 for counter in self._results:
44 self._results[counter] = results[counter] - self._results[counter]
45
46 def AddResults(self, tab, results):
47 assert self._results, 'Must Start() and Stop() before AddResults().'
48 for counter, trace_unit in _COUNTER_TO_RESULTS.iteritems():
49 if counter not in self._results:
50 continue
51 results.Add(trace_unit[0], trace_unit[1], self._results[counter],
52 data_type='unimportant')
53 self._results = None
OLDNEW
« no previous file with comments | « tools/perf/measurements/page_cycler.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698