Chromium Code Reviews| 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 return; | |
|
apacible
2016/04/14 17:35:20
nit: return not needed
Lei Lei
2016/04/14 20:05:46
Done.
| |
| 46 } | |
| 47 } | |
| 48 | |
| 49 function openPort_(name) { | |
| 50 var rt = window.chrome.runtime; | |
| 51 if (rt && rt.connect) { | |
| 52 console.info('Opening port named ' + name); | |
| 53 return rt.connect(extensionId, {'name': name}); | |
| 54 } | |
| 55 return null; | |
| 56 } | |
| OLD | NEW |