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..779dab18477b9d7606aafa0c4a299b8662f08f4d |
| --- /dev/null |
| +++ b/chrome/test/media_router/telemetry/benchmarks/media_router_cpu_memory_metric.py |
| @@ -0,0 +1,47 @@ |
| +# 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 |
| + |
| + |
| +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. |
| + print 'results_json' + ': ' + str(results_json) |
|
mark a. foltz
2016/04/04 20:25:06
Is this for debugging? If so put it behind e.g. l
Lei Lei
2016/04/13 00:22:43
Done.
|
| + |
| + if results_json: |
| + perf_results = json.loads(results_json) |
| + for metric in perf_results: |
| + units = '' |
|
mark a. foltz
2016/04/04 20:25:06
What are the units for metrics other than privateM
Lei Lei
2016/04/13 00:22:43
Right now we only have two metrics, privateMemory
|
| + metric_results = perf_results[metric] |
| + for process in metric_results: |
|
mark a. foltz
2016/04/04 20:25:06
Is metric_results a dictionary? If so, I think thi
Lei Lei
2016/04/13 00:22:43
Done.
|
| + process_results = metric_results[process] |
| + if len(process_results) > 0: |
| + avg_result = round(sum(process_results)/len(process_results), 4) |
| + if metric == 'privateMemory': |
| + avg_result = round(avg_result/(1024 * 1024), 2) |
| + units = 'MB' |
|
mark a. foltz
2016/04/04 20:25:06
Do you need to reset this if metric != privateMemo
Lei Lei
2016/04/13 00:22:43
Yes, the units is reset at the beginning of for lo
|
| + results.AddValue(scalar.ScalarValue( |
| + results.current_page, '%s_%s' % (process, metric), units, |
| + avg_result)) |