/** * Update and add (updates reference and update time). * @param now * @param amount */ public final void add(final long now, final float amount) { update(now); buckets[0] += amount; }
/** * Get moderate lag spikes of the last hour (>150 ms, lowest tracked spike * duration). * * @return the moderate lag spikes * @deprecated What is moderate :) ? */ public static final int getModerateLagSpikes() { spikes[0].update(System.currentTimeMillis()); return (int) spikes[0].score(1f); }
/** * Get heavy lag spikes of the last hour (> 450 ms supposedly, first * duration bigger than 150 ms). * * @return the heavy lag spikes * @deprecated What is heavy :) ? */ public static final int getHeavyLagSpikes() { spikes[1].update(System.currentTimeMillis()); return (int) spikes[1].score(1f); }
/** * Get total number of lag spikes counted at all. This is the number of lag * spikes with a duration above spikeDuations[0] which should be 150 ms. * This is the score of spikes[0]. * * @return the number of lag spikes */ public static final int getNumberOfLagSpikes() { spikes[0].update(System.currentTimeMillis()); return (int) spikes[0].score(1f); }
/** * 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 the lag spikes */ 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; }
/** * Update and then reduce all given ActionFrequency instances by the given * amount, capped at a maximum of 0 for the resulting first bucket score. * * @param amount * The amount to subtract. * @param freqs */ public static void reduce(final long time, final float amount, final ActionFrequency... freqs) { for (int i = 0; i < freqs.length; i++) { final ActionFrequency freq = freqs[i]; freq.update(time); freq.setBucket(0, Math.max(0f, freq.bucketScore(0) - amount)); } }
/** * Update and then reduce all given ActionFrequency instances by the given * amount, without capping the result. * * @param amount * The amount to subtract. * @param freqs */ public static void subtract(final long time, final float amount, final ActionFrequency... freqs) { for (int i = 0; i < freqs.length; i++) { final ActionFrequency freq = freqs[i]; freq.update(time); freq.setBucket(0, freq.bucketScore(0) - amount); } }
@Override protected float getScore(List<Character> chars, long ts) { lastAdd = ts; final char[] a = DigestedWords.toArray(chars); final String key = new String(a); ActionFrequency freq = entries.get(key); if (freq == null){ freq = new ActionFrequency(nBuckets, durBucket); entries.put(key, freq); return 0.0f; } freq.update(ts); float score = Math.min(1.0f, freq.score(factor)); freq.add(ts, 1.0f); return score; }
taskLoad.update(tick); final boolean isHeavyLoad = taskLoad.score(1f) > heavyLoad || TickTask.getLag(msMonitored, true) > 1.1f;
if (Math.abs(data.sumYaw) < stationary) { data.yawFreq.update(now); return false;
public boolean check(final Player player, final ChatConfig cc, final ChatData data) { final long now = System.currentTimeMillis(); // Skip if is too close to the startup time. if (now - TickTask.getTimeStart() < cc.loginsStartupDelay) return false; // Split into 6 buckets always. final long durBucket = 1000L * cc.loginsSeconds / 6; final ActionFrequency freq = getActionFrequency(player.getWorld().getName(), 6, durBucket, cc.loginsPerWorldCount); freq.update(now); final boolean cancel = freq.score(1f) > cc.loginsLimit; // TODO: >= ... This will be 1 after the first login (!). if (!cancel) freq.add(1f); return cancel; }
data.chatFrequency.update(time);
lastDur = 50; for (int i = 0; i < spikeDurations.length; i++) { spikes[i].update(time);