summaryrefslogtreecommitdiffstats
path: root/src/libserver
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2018-07-24 19:48:08 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2018-07-24 19:48:08 +0100
commit558bae256922e3c4149fd9798dbd98b04bd5cc55 (patch)
treee67e2fdc03f003aa9d54c80b8f58f69ef247423a /src/libserver
parenta281d6a475ceb0e7553db38a2e74656aed3a8988 (diff)
downloadrspamd-558bae256922e3c4149fd9798dbd98b04bd5cc55.tar.gz
rspamd-558bae256922e3c4149fd9798dbd98b04bd5cc55.zip
[Minor] Place moving average function is generic utilities
Diffstat (limited to 'src/libserver')
-rw-r--r--src/libserver/symbols_cache.c58
1 files changed, 4 insertions, 54 deletions
diff --git a/src/libserver/symbols_cache.c b/src/libserver/symbols_cache.c
index 943125287..6076d1743 100644
--- a/src/libserver/symbols_cache.c
+++ b/src/libserver/symbols_cache.c
@@ -85,19 +85,13 @@ struct symbols_cache {
gint peak_cb;
};
-struct counter_data {
- gdouble mean;
- gdouble stddev;
- guint64 number;
-};
-
struct item_stat {
- struct counter_data time_counter;
+ struct rspamd_counter_data time_counter;
gdouble avg_time;
gdouble weight;
guint hits;
guint64 total_hits;
- struct counter_data frequency_counter;
+ struct rspamd_counter_data frequency_counter;
gdouble avg_frequency;
gdouble stddev_frequency;
};
@@ -109,7 +103,7 @@ struct cache_item {
guint64 last_count;
/* Per process counter */
- struct counter_data *cd;
+ struct rspamd_counter_data *cd;
gchar *symbol;
enum rspamd_symbol_type type;
@@ -338,50 +332,6 @@ cache_logic_cmp (const void *p1, const void *p2, gpointer ud)
return 0;
}
-/**
- * Set counter for a symbol using moving average
- */
-static double
-rspamd_set_counter (struct counter_data *cd, gdouble value)
-{
- gdouble cerr;
-
- /* Cumulative moving average using per-process counter data */
- if (cd->number == 0) {
- cd->mean = 0;
- cd->stddev = 0;
- }
-
- cd->mean += (value - cd->mean) / (gdouble)(++cd->number);
- cerr = (value - cd->mean) * (value - cd->mean);
- cd->stddev += (cerr - cd->stddev) / (gdouble)(cd->number);
-
- return cd->mean;
-}
-
-/**
- * Set counter for a symbol using exponential moving average
- */
-static double
-rspamd_set_counter_ema (struct counter_data *cd, gdouble value, gdouble alpha)
-{
- gdouble diff, incr;
-
- /* Cumulative moving average using per-process counter data */
- if (cd->number == 0) {
- cd->mean = 0;
- cd->stddev = 0;
- }
-
- diff = value - cd->mean;
- incr = diff * alpha;
- cd->mean += incr;
- cd->stddev = (1 - alpha) * (cd->stddev + diff * incr);
- cd->number ++;
-
- return cd->mean;
-}
-
static void
rspamd_symbols_cache_tsort_visit (struct symbols_cache *cache,
struct cache_item *it,
@@ -874,7 +824,7 @@ rspamd_symbols_cache_add_symbol (struct symbols_cache *cache,
* save or accumulate
*/
item->cd = rspamd_mempool_alloc0 (cache->static_pool,
- sizeof (struct counter_data));
+ sizeof (struct rspamd_counter_data));
item->func = func;
item->user_data = user_data;
item->priority = priority;