Chromium Code Reviews| 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..f0461cca1646b5b2f881855ef85833a665fbddaa |
| --- /dev/null |
| +++ b/chrome/test/media_router/telemetry/benchmarks/media_router_cpu_memory_metric.py |
| @@ -0,0 +1,48 @@ |
| +# 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 |
| + |
| + |
| +UNITS = {'privateMemory': 'MB', |
| + 'cpu': ''} |
|
mark a. foltz
2016/04/13 20:20:03
Can you define units for CPU? Is it a utilization
Lei Lei
2016/04/14 01:55:12
It is a utilization percentage, I renamed the metr
|
| + |
| + |
| +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 results_json: |
|
mark a. foltz
2016/04/13 20:20:03
Slight preference for early return, to reduce inde
Lei Lei
2016/04/14 01:55:12
Done.
|
| + perf_results = json.loads(results_json) |
| + for (metric, metric_results) in perf_results.iteritems(): |
| + units = UNITS.get(metric) |
|
mark a. foltz
2016/04/13 20:20:03
This can be put into L47.
Lei Lei
2016/04/14 01:55:13
Done.
|
| + for (process, process_results) in metric_results.iteritems(): |
| + if len(process_results) > 0: |
|
mark a. foltz
2016/04/13 20:20:03
if not process_results:
continue
Lei Lei
2016/04/14 01:55:13
Done.
|
| + 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' % (process, metric), units, |
| + avg_result)) |