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.onUpdated.addListener(function(processes) { |
8 var table = "<table>\n" + | 8 var table = "<table>\n" + |
9 "<tr><td><b>Process</b></td>" + | 9 "<tr><td><b>Process</b></td>" + |
10 "<td>Type</td>" + | 10 "<td>Type</td>" + |
11 "<td>CPU</td>" + | 11 "<td>CPU</td>" + |
12 "<td>Network</td>" + | 12 "<td>Network</td>" + |
13 "<td>Shared Memory</td>" + | |
14 "<td>Private Memory</td>" + | 13 "<td>Private Memory</td>" + |
15 "</tr>\n"; | 14 "</tr>\n"; |
16 for (pid in processes) { | 15 for (pid in processes) { |
17 table = displayProcessInfo(processes[pid], table); | 16 table = displayProcessInfo(processes[pid], table); |
18 } | 17 } |
19 table += "</table>\n"; | 18 table += "</table>\n"; |
20 var div = document.getElementById("process-list"); | 19 var div = document.getElementById("process-list"); |
21 div.innerHTML = table; | 20 div.innerHTML = table; |
22 }); | 21 }); |
23 } | 22 } |
24 | 23 |
25 function displayProcessInfo(process, table) { | 24 function displayProcessInfo(process, table) { |
26 // Format network string like task manager | 25 // Format network string like task manager |
27 var network = process.network; | 26 var network = process.network; |
28 if (network > 1024) { | 27 if (network > 1024) { |
29 network = (network / 1024).toFixed(1) + " kB/s"; | 28 network = (network / 1024).toFixed(1) + " kB/s"; |
30 } else if (network > 0) { | 29 } else if (network > 0) { |
31 network += " B/s"; | 30 network += " B/s"; |
32 } else if (network == -1) { | 31 } else if (network == -1) { |
33 network = "N/A"; | 32 network = "N/A"; |
34 } | 33 } |
35 | 34 |
36 table += | 35 table += |
37 "<tr><td>" + process.id + "</td>" + | 36 "<tr><td>" + process.id + "</td>" + |
38 "<td>" + process.type + "</td>" + | 37 "<td>" + process.type + "</td>" + |
39 "<td>" + process.cpu + "</td>" + | 38 "<td>" + process.cpu + "</td>" + |
40 "<td>" + network + "</td>" + | 39 "<td>" + network + "</td>" + |
41 "<td>" + (process.sharedMemory / 1024) + "K</td>" + | |
42 "<td>" + (process.privateMemory / 1024) + "K</td>" + | 40 "<td>" + (process.privateMemory / 1024) + "K</td>" + |
43 "</tr>\n"; | 41 "</tr>\n"; |
44 return table; | 42 return table; |
45 } | 43 } |
46 | 44 |
47 document.addEventListener('DOMContentLoaded', init); | 45 document.addEventListener('DOMContentLoaded', init); |
OLD | NEW |