mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-14 03:33:52 +01:00
Update "top" command- columns and loops
Switched the RAM and thread columns so that the RAM usage does not need to be rounded. Updated structure to remove nested loops.
This commit is contained in:
parent
96be33344f
commit
92b100f3ce
@ -954,37 +954,35 @@ var Terminal = {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "top":
|
case "top":
|
||||||
if(commandArray.length != 1) {
|
if(commandArray.length != 1) {
|
||||||
post("Incorrect usage of top command. Usage: top"); return;
|
post("Incorrect usage of top command. Usage: top"); return;
|
||||||
}
|
}
|
||||||
|
|
||||||
post("Script RAM Usage Threads");
|
post("Script Threads RAM Usage");
|
||||||
|
|
||||||
var currRunningScripts = Player.getCurrentServer().runningScripts;
|
var currRunningScripts = Player.getCurrentServer().runningScripts;
|
||||||
//Iterate through active scripts on current server
|
var currScripts = Player.getCurrentServer().scripts;
|
||||||
for(var i = 0; i < currRunningScripts.length; i++) {
|
//Iterate through scripts on current server
|
||||||
//Iterate through scripts on current server
|
for(var i = 0; i < currScripts.length; i++) {
|
||||||
for(var j = 0; j < Player.getCurrentServer().scripts.length; j++) {
|
if(currRunningScripts.includes(currScripts[i].filename)) { //If the script is running
|
||||||
if(currRunningScripts[i] === Player.getCurrentServer().scripts[j].filename) { //If the script is active
|
var script = currScripts[i];
|
||||||
var script = Player.getCurrentServer().scripts[j];
|
|
||||||
|
|
||||||
//Calculate name padding
|
//Calculate name padding
|
||||||
var numSpacesScript = 26 - script.filename.length; // 26 is the width of each column
|
var numSpacesScript = 26 - script.filename.length; //26 -> width of name column
|
||||||
var spacesScript = Array(numSpacesScript+1).join(" ");
|
var spacesScript = Array(numSpacesScript+1).join(" ");
|
||||||
|
|
||||||
//Calculate and transform RAM usage
|
//Calculate thread padding
|
||||||
var ramUsage = script.ramUsage * script.threads * Math.pow(1.02, script.threads - 1);
|
var numSpacesThread = 16 - (script.threads + "").length; //16 -> width of thread column
|
||||||
ramUsage = ramUsage.toFixed(3) + "GB"; //Rounds RAM to three decimal places
|
var spacesThread = Array(numSpacesThread+1).join(" ");
|
||||||
|
|
||||||
//Calculate RAM padding
|
//Calculate and transform RAM usage
|
||||||
var numSpacesRAM = 26 - ramUsage.length;
|
var ramUsage = script.ramUsage * script.threads * Math.pow(1.02, script.threads - 1);
|
||||||
var spacesRAM = Array(numSpacesRAM+1).join(" ");
|
ramUsage = ramUsage + "GB";
|
||||||
|
|
||||||
var entry = [script.filename, spacesScript, ramUsage, spacesRAM, script.threads];
|
var entry = [script.filename, spacesScript, script.threads, spacesThread, ramUsage];
|
||||||
post(entry.join(""));
|
post(entry.join(""));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
post("Command not found");
|
post("Command not found");
|
||||||
|
Loading…
Reference in New Issue
Block a user