From a6ce41fac5f7e626c25fc4335a5bb958cdddf454 Mon Sep 17 00:00:00 2001 From: zzz <zzz@mail.i2p> Date: Sat, 15 Oct 2011 17:11:40 +0000 Subject: [PATCH] * Stats: Add API methods for zero duration, for efficiency --- core/java/src/net/i2p/stat/RateStat.java | 11 +++++++++++ core/java/src/net/i2p/stat/StatManager.java | 10 ++++++++++ 2 files changed, 21 insertions(+) diff --git a/core/java/src/net/i2p/stat/RateStat.java b/core/java/src/net/i2p/stat/RateStat.java index 8dc1583d17..0920508457 100644 --- a/core/java/src/net/i2p/stat/RateStat.java +++ b/core/java/src/net/i2p/stat/RateStat.java @@ -46,6 +46,17 @@ public class RateStat { r.addData(value, eventDuration); } + /** + * Update all of the rates for the various periods with the given value. + * Zero duration. + * @since 0.8.10 + */ + public void addData(long value) { + if (_statLog != null) _statLog.addData(_groupName, _statName, value, 0); + for (Rate r: _rates.values()) + r.addData(value); + } + /** coalesce all the stats */ public void coalesceStats() { for (Rate r: _rates.values()){ diff --git a/core/java/src/net/i2p/stat/StatManager.java b/core/java/src/net/i2p/stat/StatManager.java index 7dfcf5e303..ba50620ae9 100644 --- a/core/java/src/net/i2p/stat/StatManager.java +++ b/core/java/src/net/i2p/stat/StatManager.java @@ -150,6 +150,16 @@ public class StatManager { if (stat != null) stat.addData(data, eventDuration); } + /** + * Update the given rate statistic, taking note that the given data point was received (and recalculating all rates). + * Zero duration. + * @since 0.8.10 + */ + public void addRateData(String name, long data) { + RateStat stat = _rateStats.get(name); // unsynchronized + if (stat != null) stat.addData(data); + } + private int coalesceCounter; /** every this many minutes for frequencies */ private static final int FREQ_COALESCE_RATE = 9; -- GitLab