OLD | NEW |
1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import logging | 5 import logging |
6 import json | 6 import json |
7 | 7 |
8 from telemetry.core import exceptions | 8 from telemetry.core import exceptions |
9 from telemetry.value import scalar | 9 from telemetry.value import scalar |
10 | 10 |
11 from metrics import Metric | 11 from metrics import Metric |
12 | 12 |
13 | 13 |
14 METRICS = {'privateMemory': {'units': 'MB', 'display_name': 'private_memory'}, | 14 METRICS = {'privateMemory': {'units': 'MB', 'display_name': 'private_memory'}, |
15 'cpu': {'units': '%', 'display_name': 'cpu_utilization'}} | 15 'cpu': {'units': '%', 'display_name': 'cpu_utilization'}} |
16 | 16 |
17 | 17 |
18 class MediaRouterCPUMemoryMetric(Metric): | 18 class MediaRouterCPUMemoryMetric(Metric): |
19 "A metric for media router CPU/Memory usage." | 19 "A metric for media router CPU/Memory usage." |
20 | 20 |
21 def Start(self, page, tab): | 21 def Start(self, page, tab): |
22 raise NotImplementedError() | 22 raise NotImplementedError() |
23 | 23 |
24 def Stop(self, page, tab): | 24 def Stop(self, page, tab): |
25 raise NotImplementedError() | 25 raise NotImplementedError() |
26 | 26 |
27 def AddResults(self, tab, results): | 27 def AddResults(self, tab, results): |
28 results_json = None | 28 results_json = None |
29 try: | 29 try: |
30 results_json = tab.EvaluateJavaScript2( | 30 results_json = tab.EvaluateJavaScript( |
31 'JSON.stringify(window.perfResults)') | 31 'JSON.stringify(window.perfResults)') |
32 except exceptions.EvaluateException: | 32 except exceptions.EvaluateException: |
33 pass | 33 pass |
34 # This log gives the detailed information about CPU/memory usage. | 34 # This log gives the detailed information about CPU/memory usage. |
35 logging.info('results_json' + ': ' + str(results_json)) | 35 logging.info('results_json' + ': ' + str(results_json)) |
36 | 36 |
37 if not results_json: | 37 if not results_json: |
38 return | 38 return |
39 perf_results = json.loads(results_json) | 39 perf_results = json.loads(results_json) |
40 for (metric, metric_results) in perf_results.iteritems(): | 40 for (metric, metric_results) in perf_results.iteritems(): |
(...skipping 12 matching lines...) Expand all Loading... |
53 avg_result)) | 53 avg_result)) |
54 | 54 |
55 # Calculate MR extension wakeup time | 55 # Calculate MR extension wakeup time |
56 if 'mr_extension' in perf_results['cpu']: | 56 if 'mr_extension' in perf_results['cpu']: |
57 wakeup_percentage = round( | 57 wakeup_percentage = round( |
58 (len(perf_results['cpu']['mr_extension']) * 100 / | 58 (len(perf_results['cpu']['mr_extension']) * 100 / |
59 len(perf_results['cpu']['browser'])), 2) | 59 len(perf_results['cpu']['browser'])), 2) |
60 results.AddValue(scalar.ScalarValue( | 60 results.AddValue(scalar.ScalarValue( |
61 results.current_page, 'mr_extension_wakeup_percentage', | 61 results.current_page, 'mr_extension_wakeup_percentage', |
62 '%', wakeup_percentage)) | 62 '%', wakeup_percentage)) |
OLD | NEW |