// Copyright (c) 2012 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. // Shows an updating list of process statistics. function init() { chrome.processes.onUpdatedWithMemory.addListener( function(processes) { var table = "\n" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "\n"; for (pid in processes) { table = displayProcessInfo(processes[pid], table); } table += "
ProcessOS IDTitleTypeTabsCPUNetworkPrivate MemoryFPSJS Memory
\n"; var div = document.getElementById("process-list"); div.innerHTML = table; }); document.getElementById("killProcess").onclick = function () { var procId = parseInt(prompt("Enter process ID")); chrome.processes.terminate(procId); } } function displayProcessInfo(process, table) { // Format network string like task manager var network = process.network; if (network > 1024) { network = (network / 1024).toFixed(1) + " kB/s"; } else if (network > 0) { network += " B/s"; } else if (network == -1) { network = "N/A"; } table += "" + process.id + "" + "" + process.osProcessId + "" + "" + process.title + "" + "" + process.type + "" + "" + process.tabs + "" + "" + process.cpu + "" + "" + network + ""; if ("privateMemory" in process) { table += "" + (process.privateMemory / 1024) + "K"; } else { table += "N/A"; } if ("fps" in process) { table += "" + process.fps.toFixed(2) + ""; } else { table += "N/A"; } if ("jsMemoryAllocated" in process) { var allocated = process.jsMemoryAllocated / 1024; var used = process.jsMemoryUsed / 1024; table += "" + allocated.toFixed(2) + "K (" + used.toFixed(2) + "K live)"; } else { table += "N/A"; } table += "" + "\n"; return table; } document.addEventListener('DOMContentLoaded', init);