aboutsummaryrefslogtreecommitdiffstats
path: root/src/libserver/symbols_cache.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2018-03-23 13:47:58 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2018-03-23 13:47:58 +0000
commitc3eb6a173e5076a19ad1cf03653b8cc6b610e2c5 (patch)
tree62a39803532363816f5eb7f8444473aa6504466c /src/libserver/symbols_cache.c
parent0e14312dc263b8712e4c840d8eaebe313ef9d93f (diff)
downloadrspamd-c3eb6a173e5076a19ad1cf03653b8cc6b610e2c5.tar.gz
rspamd-c3eb6a173e5076a19ad1cf03653b8cc6b610e2c5.zip
[Fix] Add rounding when printing a lot of FP variables
Diffstat (limited to 'src/libserver/symbols_cache.c')
-rw-r--r--src/libserver/symbols_cache.c46
1 files changed, 33 insertions, 13 deletions
diff --git a/src/libserver/symbols_cache.c b/src/libserver/symbols_cache.c
index 060f3875f..ecc569573 100644
--- a/src/libserver/symbols_cache.c
+++ b/src/libserver/symbols_cache.c
@@ -653,6 +653,8 @@ rspamd_symbols_cache_load_items (struct symbols_cache *cache, const gchar *name)
return TRUE;
}
+#define ROUND_DOUBLE(x) (floor((x) * 100.0) / 100.0)
+
static gboolean
rspamd_symbols_cache_save_items (struct symbols_cache *cache, const gchar *name)
{
@@ -695,17 +697,21 @@ rspamd_symbols_cache_save_items (struct symbols_cache *cache, const gchar *name)
while (g_hash_table_iter_next (&it, &k, &v)) {
item = v;
elt = ucl_object_typed_new (UCL_OBJECT);
- ucl_object_insert_key (elt, ucl_object_fromdouble (item->st->weight),
+ ucl_object_insert_key (elt,
+ ucl_object_fromdouble (ROUND_DOUBLE (item->st->weight)),
"weight", 0, false);
- ucl_object_insert_key (elt, ucl_object_fromdouble (item->st->time_counter.mean),
+ ucl_object_insert_key (elt,
+ ucl_object_fromdouble (ROUND_DOUBLE (item->st->time_counter.mean)),
"time", 0, false);
- ucl_object_insert_key (elt, ucl_object_fromdouble (item->st->total_hits),
+ ucl_object_insert_key (elt, ucl_object_fromint (item->st->total_hits),
"count", 0, false);
freq = ucl_object_typed_new (UCL_OBJECT);
- ucl_object_insert_key (freq, ucl_object_fromdouble (item->st->frequency_counter.mean),
+ ucl_object_insert_key (freq,
+ ucl_object_fromdouble (ROUND_DOUBLE (item->st->frequency_counter.mean)),
"avg", 0, false);
- ucl_object_insert_key (freq, ucl_object_fromdouble (item->st->frequency_counter.stddev),
+ ucl_object_insert_key (freq,
+ ucl_object_fromdouble (ROUND_DOUBLE (item->st->frequency_counter.stddev)),
"stddev", 0, false);
ucl_object_insert_key (elt, freq, "frequency", 0, false);
@@ -722,6 +728,8 @@ rspamd_symbols_cache_save_items (struct symbols_cache *cache, const gchar *name)
return ret;
}
+#undef ROUND_DOUBLE
+
gint
rspamd_symbols_cache_add_symbol (struct symbols_cache *cache,
const gchar *name,
@@ -1930,6 +1938,8 @@ struct counters_cbdata {
struct symbols_cache *cache;
};
+#define ROUND_DOUBLE(x) (floor((x) * 100.0) / 100.0)
+
static void
rspamd_symbols_cache_counters_cb (gpointer v, gpointer ud)
{
@@ -1949,23 +1959,31 @@ rspamd_symbols_cache_counters_cb (gpointer v, gpointer ud)
g_assert (item->parent < (gint)cbd->cache->items_by_id->len);
parent = g_ptr_array_index (cbd->cache->items_by_id,
item->parent);
- ucl_object_insert_key (obj, ucl_object_fromdouble (item->st->weight),
+ ucl_object_insert_key (obj,
+ ucl_object_fromdouble (ROUND_DOUBLE (item->st->weight)),
"weight", 0, false);
- ucl_object_insert_key (obj, ucl_object_fromdouble (parent->st->avg_frequency),
+ ucl_object_insert_key (obj,
+ ucl_object_fromdouble (ROUND_DOUBLE (parent->st->avg_frequency)),
"frequency", 0, false);
- ucl_object_insert_key (obj, ucl_object_fromint (parent->st->total_hits),
+ ucl_object_insert_key (obj,
+ ucl_object_fromint (parent->st->total_hits),
"hits", 0, false);
- ucl_object_insert_key (obj, ucl_object_fromdouble (parent->st->avg_time),
+ ucl_object_insert_key (obj,
+ ucl_object_fromdouble (ROUND_DOUBLE (parent->st->avg_time)),
"time", 0, false);
}
else {
- ucl_object_insert_key (obj, ucl_object_fromdouble (item->st->weight),
+ ucl_object_insert_key (obj,
+ ucl_object_fromdouble (ROUND_DOUBLE (item->st->weight)),
"weight", 0, false);
- ucl_object_insert_key (obj, ucl_object_fromdouble (item->st->avg_frequency),
+ ucl_object_insert_key (obj,
+ ucl_object_fromdouble (ROUND_DOUBLE (item->st->avg_frequency)),
"frequency", 0, false);
- ucl_object_insert_key (obj, ucl_object_fromint (item->st->total_hits),
+ ucl_object_insert_key (obj,
+ ucl_object_fromint (item->st->total_hits),
"hits", 0, false);
- ucl_object_insert_key (obj, ucl_object_fromdouble (item->st->avg_time),
+ ucl_object_insert_key (obj,
+ ucl_object_fromdouble (ROUND_DOUBLE (item->st->avg_time)),
"time", 0, false);
}
@@ -1973,6 +1991,8 @@ rspamd_symbols_cache_counters_cb (gpointer v, gpointer ud)
}
}
+#undef ROUND_DOUBLE
+
ucl_object_t *
rspamd_symbols_cache_counters (struct symbols_cache * cache)
{