| OLD | NEW |
| (Empty) | |
| 1 /** |
| 2 * Copyright 2016 The Chromium Authors. All rights reserved. |
| 3 * Use of this source code is governed by a BSD-style license that can be |
| 4 * found in the LICENSE file. |
| 5 * |
| 6 * @fileoverview Script to interact with test extension to get CPU/memory usage. |
| 7 * |
| 8 */ |
| 9 |
| 10 |
| 11 // MR test extension ID. |
| 12 var extensionId = 'ocihafebdemjoofhbdnamghkfobfgbal'; |
| 13 |
| 14 /** |
| 15 * The dictionary to store the performance results with the following format: |
| 16 * key: the metric, e.g. CPU, private memory |
| 17 * value: map of the performance results for different processes. |
| 18 * key: process type, e.g. tab, browser, gpu, extension. |
| 19 * value: list of the performance results. |
| 20 */ |
| 21 window.perfResults = {}; |
| 22 |
| 23 /** |
| 24 * Connects to the test extension and starts to collect CPU/memory usage data. |
| 25 */ |
| 26 function collectPerfData() { |
| 27 processCpuPort_ = openPort_('collectData'); |
| 28 if (processCpuPort_) { |
| 29 processCpuPort_.onMessage.addListener(function(message) { |
| 30 for (metric in message) { |
| 31 if (!window.perfResults[metric]) { |
| 32 window.perfResults[metric] = {}; |
| 33 } |
| 34 for (process_type in message[metric]) { |
| 35 if (!window.perfResults[metric][process_type]) { |
| 36 window.perfResults[metric][process_type] = [] |
| 37 } |
| 38 window.perfResults[metric][process_type].push( |
| 39 message[metric][process_type]); |
| 40 } |
| 41 } |
| 42 }); |
| 43 } else { |
| 44 console.log('Unable to connect to port'); |
| 45 } |
| 46 } |
| 47 |
| 48 function openPort_(name) { |
| 49 var rt = window.chrome.runtime; |
| 50 if (rt && rt.connect) { |
| 51 console.info('Opening port named ' + name); |
| 52 return rt.connect(extensionId, {'name': name}); |
| 53 } |
| 54 return null; |
| 55 } |
| OLD | NEW |