Change appearance of the output of the lag command.

This commit is contained in:
asofold 2013-02-04 09:21:06 +01:00
parent cf065d6da2
commit c49b1fb7b6

View File

@ -18,28 +18,25 @@ public class LagCommand extends NCPCommand {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
{
long max = 50L * (1L + TickTask.lagMaxTicks) * TickTask.lagMaxTicks;
long medium = 50L * TickTask.lagMaxTicks;
long second = 1200L;
StringBuilder builder = new StringBuilder(300);
builder.append("Lag tracking (roughly):");
builder.append("\nAverage lag:");
for (long ms : new long[]{second, medium, max}){
double lag = TickTask.getLag(ms);
int p = Math.max(0, (int) ((lag - 1.0) * 100.0));
builder.append(" " + p + "%[" + StringUtil.fdec1.format((double) ms / 1200.0) + "s]" );
}
builder.append("---- Lag tracking ----\n");
// Lag spikes.
long[] spikeDurations = TickTask.getLagSpikeDurations();
int[] spikes = TickTask.getLagSpikes();
builder.append("\nLast hour spikes (" + spikes[0] + " total, all > " + spikeDurations[0] + " ms):\n| ");
if (spikes[0] > 0){
builder.append("#### Lag spikes ####\n");
if (spikes[0] == 0){
builder.append("No spikes > " + spikeDurations[0] + " ms within the last 40 to 60 minutes.");
}
else if (spikes[0] > 0){
builder.append("Total: " + spikes[0] + " > " + spikeDurations[0] + " ms within the last 40 to 60 minutes.");
builder.append("\n| ");
for (int i = 0; i < spikeDurations.length; i++){
if (i < spikeDurations.length - 1 && spikes[i] == spikes[i + 1]){
// Ignore these, get printed later.
continue;
}
if (spikes[i] == 0){
builder.append("none |");
continue; // Could be break.
}
else if (i < spikeDurations.length - 1){
builder.append((spikes[i] - spikes[i + 1]) + "x" + spikeDurations[i] + "..." + spikeDurations[i + 1] + " | ");
@ -49,9 +46,18 @@ public class LagCommand extends NCPCommand {
}
}
}
else{
builder.append("none | ");
builder.append("\n");
// TPS lag.
long max = 50L * (1L + TickTask.lagMaxTicks) * TickTask.lagMaxTicks;
long medium = 50L * TickTask.lagMaxTicks;
long second = 1200L;
builder.append("#### TPS lag ####\nPerc.[time]:");
for (long ms : new long[]{second, medium, max}){
double lag = TickTask.getLag(ms);
int p = Math.max(0, (int) ((lag - 1.0) * 100.0));
builder.append(" " + p + "%[" + StringUtil.fdec1.format((double) ms / 1200.0) + "s]" );
}
// Send message.
sender.sendMessage(builder.toString());
return true;
}