More precise lag spike counting.

Also prepares for more flexibility with what to count.
This commit is contained in:
asofold 2012-12-21 15:41:15 +01:00
parent d70041713a
commit 59b0985f11
2 changed files with 66 additions and 20 deletions

View File

@ -29,11 +29,21 @@ public class LagCommand extends NCPCommand {
int p = Math.max(0, (int) ((lag - 1.0) * 100.0)); int p = Math.max(0, (int) ((lag - 1.0) * 100.0));
builder.append(" " + p + "%[" + CheckUtils.fdec1.format((double) ms / 1200.0) + "s]" ); builder.append(" " + p + "%[" + CheckUtils.fdec1.format((double) ms / 1200.0) + "s]" );
} }
builder.append("\nLast hour spikes: "); builder.append("\nLast hour spikes:\n| ");
int spikesM = TickTask.getModerateLagSpikes(); long[] spikeDurations = TickTask.getLagSpikeDurations();
builder.append((spikesM > 0 ? (" | " + spikesM) : " | none") + " over 150 ms"); int[] spikes = TickTask.getLagSpikes();
int spikesH = TickTask.getHeavyLagSpikes(); if (spikes[0] > 0){
builder.append((spikesH > 0 ? (" | " + spikesH) : " | none") + " of which over 1 s"); for (int i = 0; i < spikeDurations.length; i++){
if (i < spikeDurations.length - 1 && spikes[i] == spikes[i + 1]){
// Ignore these, get printed later.
continue;
}
builder.append((spikes[i] > 0 ? (spikes[i]) : "none") + " > " + spikeDurations[i] + " ms | ");
}
}
else{
builder.append("none > " + spikeDurations[0] + " ms |");
}
sender.sendMessage(builder.toString()); sender.sendMessage(builder.toString());
return true; return true;
} }

View File

@ -1,5 +1,6 @@
package fr.neatmonster.nocheatplus.utilities; package fr.neatmonster.nocheatplus.utilities;
import java.util.Arrays;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
@ -59,11 +60,11 @@ public class TickTask implements Runnable {
/** Tick durations summed up in packs of n (nxn time covered) */ /** Tick durations summed up in packs of n (nxn time covered) */
private static final long[] tickDurationsSq = new long[lagMaxTicks]; private static final long[] tickDurationsSq = new long[lagMaxTicks];
/** Lag spikes > 150 ms counting (3 x 20 minutes). */ /** Lag spike durations (min) to keep track of. */
private static final ActionFrequency spikes150 = new ActionFrequency(3, 1000L * 60L * 20L); private static long[] spikeDurations = new long[]{150, 450, 1000, 5000};
/** Lag spikes > 1000 ms counting (3 x 20 minutes). */ /** Lag spikes > 150 ms counting (3 x 20 minutes). For lag spike length see spikeDurations. */
private static final ActionFrequency spikes1000 = new ActionFrequency(3, 1000L * 60L * 20L); private static ActionFrequency[] spikes = new ActionFrequency[spikeDurations.length];
/** Task id of the running TickTask */ /** Task id of the running TickTask */
protected static int taskId = -1; protected static int taskId = -1;
@ -77,6 +78,12 @@ public class TickTask implements Runnable {
/** Lock flag set on disable. */ /** Lock flag set on disable. */
protected static boolean locked = false; protected static boolean locked = false;
static{
for (int i = 0; i < spikeDurations.length; i++){
spikes[i] = new ActionFrequency(3, 1000L * 60L * 20L);
}
}
////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////
// Special static methods, usually not called from outside. // Special static methods, usually not called from outside.
@ -203,21 +210,44 @@ public class TickTask implements Runnable {
} }
/** /**
* Get moderate lag spikes of the last hour (>150 ms). * Get moderate lag spikes of the last hour (>150 ms, lowest tracked spike duration).
* @return * @return
*/ */
public static final int getModerateLagSpikes(){ public static final int getModerateLagSpikes(){
spikes150.update(System.currentTimeMillis()); spikes[0].update(System.currentTimeMillis());
return (int) spikes150.score(1f); return (int) spikes[0].score(1f);
} }
/** /**
* Get heavy lag spikes of the last hour (> 1 s). * Get heavy lag spikes of the last hour (> 450 ms supposedly, first duration bigger than 150 ms).
* @deprecated What is heavy :)
* @return * @return
*/ */
public static final int getHeavyLagSpikes(){ public static final int getHeavyLagSpikes(){
spikes1000.update(System.currentTimeMillis()); spikes[1].update(System.currentTimeMillis());
return (int) spikes1000.score(1f); return (int) spikes[1].score(1f);
}
/**
* Get the stepping for lag spike duration tracking.
* @return
*/
public static final long[] getLagSpikeDurations(){
return Arrays.copyOf(spikeDurations, spikeDurations.length);
}
/**
* Get lag spike count according to getLagSpikeDurations() values. Entries of lower indexes contain the entries of higher indexes (so subtraction would be necessary to get spikes from...to).
* @return
*/
public static final int[] getLagSpikes(){
final int[] out = new int[spikeDurations.length];
final long now = System.currentTimeMillis();
for (int i = 0; i < spikeDurations.length; i++){
spikes[i].update(now);
out[i] = (int) spikes[i].score(1f);
}
return out;
} }
/** /**
@ -277,8 +307,9 @@ public class TickTask implements Runnable {
tickDurations[i] = 0; tickDurations[i] = 0;
tickDurationsSq[i] = 0; tickDurationsSq[i] = 0;
} }
spikes150.clear(0); for (int i = 0; i < spikeDurations.length; i++){
spikes1000.clear(0); spikes[i].clear(0);
}
} }
////////////////////////// //////////////////////////
@ -323,9 +354,14 @@ public class TickTask implements Runnable {
tickDurations[0] = lastDur; tickDurations[0] = lastDur;
// Lag spikes150 counting. [Subject to adjustments!] // Lag spikes150 counting. [Subject to adjustments!]
if (lastDur > 150){ if (lastDur > spikeDurations[0]){
spikes150.add(time, 1f); spikes[0].add(time, 1f);
if (lastDur > 1000) spikes1000.add(time, 1f); for (int i = 1; i < spikeDurations.length; i++){
if (lastDur > spikeDurations[i]){
spikes[i].add(time, 1f);
}
else break;
}
} }
// Finish. // Finish.