Update "top" command

Updated the entry construction to use `.join()` and added/updated comments.
This commit is contained in:
Kyle B 2017-06-16 13:23:42 -04:00 committed by GitHub
parent 34a86fc32c
commit 96be33344f

@ -959,30 +959,29 @@ var Terminal = {
} }
post("Script RAM Usage Threads"); post("Script RAM Usage Threads");
var currRunningScripts = Player.getCurrentServer().runningScripts; var currRunningScripts = Player.getCurrentServer().runningScripts;
for(i = 0; i < currRunningScripts.length; i++) { //Iterate through active scripts on current server
//Check if script is on current server for(var i = 0; i < currRunningScripts.length; i++) {
for(j = 0; j < Player.getCurrentServer().scripts.length; j++) { //Iterate through scripts on current server
if(currRunningScripts[i] === Player.getCurrentServer().scripts[j].filename) { for(var j = 0; j < Player.getCurrentServer().scripts.length; j++) {
if(currRunningScripts[i] === Player.getCurrentServer().scripts[j].filename) { //If the script is active
var script = Player.getCurrentServer().scripts[j]; var script = Player.getCurrentServer().scripts[j];
//Add script name //Calculate name padding
var entry = script.filename; var numSpacesScript = 26 - script.filename.length; // 26 is the width of each column
var spacesScript = Array(numSpacesScript+1).join(" ");
//Calculate padding and add RAM usage //Calculate and transform RAM usage
var numSpaces = 26 - entry.length; var ramUsage = script.ramUsage * script.threads * Math.pow(1.02, script.threads - 1);
var spaces = Array(numSpaces+1).join(" "); ramUsage = ramUsage.toFixed(3) + "GB"; //Rounds RAM to three decimal places
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 //Calculate RAM padding
numSpaces = 26 - (ramUsage.length + 2); var numSpacesRAM = 26 - ramUsage.length;
spaces = Array(numSpaces+1).join(" "); var spacesRAM = Array(numSpacesRAM+1).join(" ");
entry += spaces;
entry += script.threads;
post(entry); var entry = [script.filename, spacesScript, ramUsage, spacesRAM, script.threads];
post(entry.join(""));
} }
} }
} }