Chromium Code Reviews| Index: chrome/test/media_router/telemetry/benchmarks/pagesets/cpu_memory_script.js |
| diff --git a/chrome/test/media_router/telemetry/benchmarks/pagesets/cpu_memory_script.js b/chrome/test/media_router/telemetry/benchmarks/pagesets/cpu_memory_script.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..8f2130a5666b76bd0aefda1f1cd9b3b48ad26f27 |
| --- /dev/null |
| +++ b/chrome/test/media_router/telemetry/benchmarks/pagesets/cpu_memory_script.js |
| @@ -0,0 +1,56 @@ |
| +/** |
| + * 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. |
| + * |
| + * @fileoverview Script to interact with test extension to get CPU/memory usage. |
| + * |
| + */ |
| + |
| + |
| +// MR test extension ID. |
| +var extensionId = 'ocihafebdemjoofhbdnamghkfobfgbal'; |
| + |
| +/** |
| + * The dictionary to store the performance results with the following format: |
| + * key: the metric, e.g. CPU, private memory |
| + * value: map of the performance results for different processes. |
| + * key: process type, e.g. tab, browser, gpu, extension. |
| + * value: list of the performance results. |
| + */ |
| +window.perfResults = {}; |
| + |
| +/** |
| + * Connects to the test extension and starts to collect CPU/memory usage data. |
| + */ |
| +function collectPerfData() { |
| + processCpuPort_ = openPort_('collectData'); |
| + if (processCpuPort_) { |
| + processCpuPort_.onMessage.addListener(function(message) { |
| + for (metric in message) { |
| + if (!window.perfResults[metric]) { |
| + window.perfResults[metric] = {}; |
| + } |
| + for (process_type in message[metric]) { |
| + if (!window.perfResults[metric][process_type]) { |
| + window.perfResults[metric][process_type] = [] |
| + } |
| + window.perfResults[metric][process_type].push( |
| + message[metric][process_type]); |
| + } |
| + } |
| + }); |
| + } else { |
| + console.log('Unable to connect to port'); |
| + return; |
|
apacible
2016/04/14 17:35:20
nit: return not needed
Lei Lei
2016/04/14 20:05:46
Done.
|
| + } |
| +} |
| + |
| +function openPort_(name) { |
| + var rt = window.chrome.runtime; |
| + if (rt && rt.connect) { |
| + console.info('Opening port named ' + name); |
| + return rt.connect(extensionId, {'name': name}); |
| + } |
| + return null; |
| +} |