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

Unified Diff: chrome/test/media_router/telemetry/benchmarks/media_router_cpu_memory_metric.py

Issue 1843063004: Add new Telemetry tests to get CPU and memory usage for idle and flinging two test scenarios. Mirro… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix GN build failure Created 4 years, 8 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
Index: chrome/test/media_router/telemetry/benchmarks/media_router_cpu_memory_metric.py
diff --git a/chrome/test/media_router/telemetry/benchmarks/media_router_cpu_memory_metric.py b/chrome/test/media_router/telemetry/benchmarks/media_router_cpu_memory_metric.py
new file mode 100644
index 0000000000000000000000000000000000000000..b7ca295cda986adfbebe03302160d2a0f4b6d940
--- /dev/null
+++ b/chrome/test/media_router/telemetry/benchmarks/media_router_cpu_memory_metric.py
@@ -0,0 +1,51 @@
+# Copyright 2016 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 logging
+import json
+
+from telemetry.core import exceptions
+from telemetry.value import scalar
+
+from metrics import Metric
+
+
+METRICS = {'privateMemory': {'units': 'MB', 'display_name': 'private_memory'},
+ 'cpu': {'units': '%', 'display_name': 'cpu_utilization'}}
+
+
+class MediaRouterCPUMemoryMetric(Metric):
+ "A metric for media router CPU/Memory usage."
+
+ def Start(self, page, tab):
+ raise NotImplementedError()
+
+ def Stop(self, page, tab):
+ raise NotImplementedError()
+
+ def AddResults(self, tab, results):
+ results_json = None
+ try:
+ results_json = tab.EvaluateJavaScript(
+ 'JSON.stringify(window.perfResults)')
+ except exceptions.EvaluateException:
+ pass
+ # This log gives the detailed information about CPU/memory usage.
+ logging.info('results_json' + ': ' + str(results_json))
+
+ if not results_json:
+ return
+ perf_results = json.loads(results_json)
+ for (metric, metric_results) in perf_results.iteritems():
+ for (process, process_results) in metric_results.iteritems():
+ if not process_results:
+ continue
+ avg_result = round(sum(process_results)/len(process_results), 4)
+ if metric == 'privateMemory':
+ avg_result = round(avg_result/(1024 * 1024), 2)
+ results.AddValue(scalar.ScalarValue(
+ results.current_page,
+ '%s.%s' % (METRICS.get(metric).get('display_name'), process),
+ METRICS.get(metric).get('units'),
+ avg_result))

Powered by Google App Engine
This is Rietveld 408576698