mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-12-24 07:02:26 +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;
|
||||
case "top":
|
||||
//TODO List each's script RAM usage
|
||||
post("Not yet implemented");
|
||||
if(commandArray.length != 1) {
|
||||
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;
|
||||
default:
|
||||
post("Command not found");
|
||||
|
Loading…
Reference in New Issue
Block a user