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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/perf/measurements/page_cycler.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/perf/metrics/network.py
diff --git a/tools/perf/metrics/network.py b/tools/perf/metrics/network.py
new file mode 100644
index 0000000000000000000000000000000000000000..662159eec60199cbb52480af8eadad1465646e09
--- /dev/null
+++ b/tools/perf/metrics/network.py
@@ -0,0 +1,53 @@
+# Copyright 2013 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import json
+
+from metrics import Metric
+
+_COUNTER_TO_RESULTS = {
+ 'tcp.read_bytes': ('tcp_read_bytes', 'bytes'),
+ 'tcp.write_bytes': ('tcp_write_bytes', 'bytes'),
+ 'HttpNetworkTransaction.Count': ('num_requests', 'count'),
+ 'tcp.connect': ('num_connects', 'count'),
+ 'spdy.sessions': ('num_spdy_sessions', 'count'),
+ }
+
+class NetworkMetric(Metric):
+ """A metric for network information."""
+
+ def __init__(self):
+ super(NetworkMetric, self).__init__()
+ self._results = None
+
+ def _GetCounters(self, tab):
+ return tab.EvaluateJavaScript("""
+(function(counters) {
+ var results = {};
+ if (!window.chrome || !window.chrome.benchmarking)
+ return results;
+ for (var i = 0; i < counters.length; i++)
+ results[counters[i]] = chrome.benchmarking.counter(counters[i]);
+ return results;
+})(%s);
+""" % json.dumps(_COUNTER_TO_RESULTS.keys()))
+
+ def Start(self, page, tab):
+ assert not self._results, 'Must AddResults() before calling Start() again.'
+ self._results = self._GetCounters(tab)
+
+ def Stop(self, page, tab):
+ assert self._results, 'Must Start() before Stop().'
+ results = self._GetCounters(tab)
+ for counter in self._results:
+ self._results[counter] = results[counter] - self._results[counter]
+
+ def AddResults(self, tab, results):
+ assert self._results, 'Must Start() and Stop() before AddResults().'
+ for counter, trace_unit in _COUNTER_TO_RESULTS.iteritems():
+ if counter not in self._results:
+ continue
+ results.Add(trace_unit[0], trace_unit[1], self._results[counter],
+ data_type='unimportant')
+ self._results = None
« 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