OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // Shows an updating list of process statistics. | 5 // Shows an updating list of process statistics. |
6 function init() { | 6 function init() { |
7 chrome.experimental.processes.onUpdated.addListener(function(processes) { | 7 chrome.experimental.processes.onUpdatedWithMemory.addListener( |
8 var table = "<table>\n" + | 8 function(processes) { |
9 "<tr><td><b>Process</b></td>" + | 9 var table = "<table>\n" + |
10 "<td>Type</td>" + | 10 "<tr><td><b>Process</b></td>" + |
11 "<td>CPU</td>" + | 11 "<td>OS ID</td>" + |
12 "<td>Network</td>" + | 12 "<td>Type</td>" + |
13 "<td>Shared Memory</td>" + | 13 "<td>Tabs</td>" + |
14 "<td>Private Memory</td>" + | 14 "<td>CPU</td>" + |
15 "</tr>\n"; | 15 "<td>Network</td>" + |
16 for (pid in processes) { | 16 "<td>Private Memory</td>" + |
17 table = displayProcessInfo(processes[pid], table); | 17 "<td>FPS</td>" + |
18 } | 18 "<td>JS Memory</td>" + |
19 table += "</table>\n"; | 19 "<td></td>" + |
20 var div = document.getElementById("process-list"); | 20 "</tr>\n"; |
21 div.innerHTML = table; | 21 for (pid in processes) { |
22 }); | 22 table = displayProcessInfo(processes[pid], table); |
| 23 } |
| 24 table += "</table>\n"; |
| 25 var div = document.getElementById("process-list"); |
| 26 div.innerHTML = table; |
| 27 }); |
| 28 |
| 29 document.getElementById("killProcess").onclick = function () { |
| 30 var procId = parseInt(prompt("Enter process ID")); |
| 31 chrome.experimental.processes.terminate(procId); |
| 32 } |
23 } | 33 } |
24 | 34 |
25 function displayProcessInfo(process, table) { | 35 function displayProcessInfo(process, table) { |
26 // Format network string like task manager | 36 // Format network string like task manager |
27 var network = process.network; | 37 var network = process.network; |
28 if (network > 1024) { | 38 if (network > 1024) { |
29 network = (network / 1024).toFixed(1) + " kB/s"; | 39 network = (network / 1024).toFixed(1) + " kB/s"; |
30 } else if (network > 0) { | 40 } else if (network > 0) { |
31 network += " B/s"; | 41 network += " B/s"; |
32 } else if (network == -1) { | 42 } else if (network == -1) { |
33 network = "N/A"; | 43 network = "N/A"; |
34 } | 44 } |
35 | 45 |
36 table += | 46 table += |
37 "<tr><td>" + process.id + "</td>" + | 47 "<tr><td>" + process.id + "</td>" + |
| 48 "<td>" + process.osProcessId + "</td>" + |
38 "<td>" + process.type + "</td>" + | 49 "<td>" + process.type + "</td>" + |
| 50 "<td>" + process.tabs + "</td>" + |
39 "<td>" + process.cpu + "</td>" + | 51 "<td>" + process.cpu + "</td>" + |
40 "<td>" + network + "</td>" + | 52 "<td>" + network + "</td>"; |
41 "<td>" + (process.sharedMemory / 1024) + "K</td>" + | 53 |
42 "<td>" + (process.privateMemory / 1024) + "K</td>" + | 54 if ("privateMemory" in process) { |
| 55 table += "<td>" + (process.privateMemory / 1024) + "K</td>"; |
| 56 } else { |
| 57 table += "<td>N/A</td>"; |
| 58 } |
| 59 if ("fps" in process) { |
| 60 table += "<td>" + process.fps.toFixed(2) + "</td>"; |
| 61 } else { |
| 62 table += "<td>N/A</td>"; |
| 63 } |
| 64 |
| 65 if ("jsMemoryAllocated" in process) { |
| 66 var allocated = process.jsMemoryAllocated / 1024; |
| 67 var used = process.jsMemoryUsed / 1024; |
| 68 table += "<td>" + allocated.toFixed(2) + "K (" + used.toFixed(2) + |
| 69 "K live)</td>"; |
| 70 } else { |
| 71 table += "<td>N/A</td>"; |
| 72 } |
| 73 |
| 74 table += |
| 75 "<td></td>" + |
43 "</tr>\n"; | 76 "</tr>\n"; |
44 return table; | 77 return table; |
45 } | 78 } |
46 | 79 |
47 document.addEventListener('DOMContentLoaded', init); | 80 document.addEventListener('DOMContentLoaded', init); |
OLD | NEW |