mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-19 14:13:48 +01:00
Implement top
Implementation of the "top" command. Uses the column formatting from scan, which breaks with long names.
This commit is contained in:
parent
d492244ec7
commit
34a86fc32c
@ -954,8 +954,38 @@ var Terminal = {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "top":
|
case "top":
|
||||||
//TODO List each's script RAM usage
|
if(commandArray.length != 1) {
|
||||||
post("Not yet implemented");
|
post("Incorrect usage of top command. Usage: top"); return;
|
||||||
|
}
|
||||||
|
|
||||||
|
post("Script RAM Usage Threads");
|
||||||
|
var currRunningScripts = Player.getCurrentServer().runningScripts;
|
||||||
|
for(i = 0; i < currRunningScripts.length; i++) {
|
||||||
|
//Check if script is on current server
|
||||||
|
for(j = 0; j < Player.getCurrentServer().scripts.length; j++) {
|
||||||
|
if(currRunningScripts[i] === Player.getCurrentServer().scripts[j].filename) {
|
||||||
|
var script = Player.getCurrentServer().scripts[j];
|
||||||
|
|
||||||
|
//Add script name
|
||||||
|
var entry = script.filename;
|
||||||
|
|
||||||
|
//Calculate padding and add RAM usage
|
||||||
|
var numSpaces = 26 - entry.length;
|
||||||
|
var spaces = Array(numSpaces+1).join(" ");
|
||||||
|
entry += spaces;
|
||||||
|
var ramUsage = (script.ramUsage * script.threads * Math.pow(1.02, script.threads - 1)).toFixed(3);
|
||||||
|
entry += ramUsage + "GB";
|
||||||
|
|
||||||
|
//Calculate padding and add thread count
|
||||||
|
numSpaces = 26 - (ramUsage.length + 2);
|
||||||
|
spaces = Array(numSpaces+1).join(" ");
|
||||||
|
entry += spaces;
|
||||||
|
entry += script.threads;
|
||||||
|
|
||||||
|
post(entry);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
post("Command not found");
|
post("Command not found");
|
||||||
|
Loading…
Reference in New Issue
Block a user