]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Improve counters output
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 28 Jan 2017 12:27:52 +0000 (12:27 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 28 Jan 2017 12:27:52 +0000 (12:27 +0000)
src/client/rspamc.c
src/controller.c
src/libserver/symbols_cache.c
src/libserver/symbols_cache.h

index dac493d8ce5a306a925b487438d2a5f7b7993584..d71a3e089e6aa1f68c3321cc06bf4160fa9d6f08 100644 (file)
@@ -772,8 +772,8 @@ rspamc_counters_sort (const ucl_object_t **o1, const ucl_object_t **o2)
                                elt2 = ucl_object_lookup (*o2, "frequency");
 
                                if (elt1 && elt2) {
-                                       order1 = ucl_object_toint (elt1);
-                                       order2 = ucl_object_toint (elt2);
+                                       order1 = ucl_object_todouble (elt1) * 100000;
+                                       order2 = ucl_object_todouble (elt2) * 100000;
                                }
                        }
                        else if (g_ascii_strcasecmp (args[0], "time") == 0) {
@@ -796,10 +796,11 @@ rspamc_counters_sort (const ucl_object_t **o1, const ucl_object_t **o2)
 static void
 rspamc_counters_output (FILE *out, ucl_object_t *obj)
 {
-       const ucl_object_t *cur, *sym, *weight, *freq, *tim;
+       const ucl_object_t *cur, *sym, *weight, *freq, *freq_dev, *tim;
        ucl_object_iter_t iter = NULL;
        gchar fmt_buf[64], dash_buf[82];
        gint l, max_len = INT_MIN, i;
+       static const gint dashes = 44;
 
        if (obj->type != UCL_ARRAY) {
                rspamd_printf ("Bad output\n");
@@ -817,27 +818,29 @@ rspamc_counters_output (FILE *out, ucl_object_t *obj)
                if (sym != NULL) {
                        l = sym->len;
                        if (l > max_len) {
-                               max_len = MIN (40, l);
+                               max_len = MIN (sizeof (dash_buf) - dashes - 1, l);
                        }
                }
        }
 
        rspamd_snprintf (fmt_buf, sizeof (fmt_buf),
-               "| %%3s | %%%ds | %%6s | %%9s | %%9s |\n", max_len);
-       memset (dash_buf, '-', 40 + max_len);
-       dash_buf[40 + max_len] = '\0';
+               "| %%3s | %%%ds | %%7s | %%13s | %%7s |\n", max_len);
+       memset (dash_buf, '-', dashes + max_len);
+       dash_buf[dashes + max_len] = '\0';
 
        printf ("Symbols cache\n");
        printf (" %s \n", dash_buf);
        if (tty) {
                printf ("\033[1m");
        }
-       printf (fmt_buf, "Pri", "Symbol", "Weight", "Frequency", "Avg. time");
+       printf (fmt_buf, "Pri", "Symbol", "Weight", "Frequency", "Time");
+       printf (" %s \n", dash_buf);
+       printf (fmt_buf, "", "", "", "hits/sec", "usec");
        if (tty) {
                printf ("\033[0m");
        }
        rspamd_snprintf (fmt_buf, sizeof (fmt_buf),
-               "| %%3d | %%%ds | %%6.1f | %%9.3f | %%9.3f |\n", max_len);
+               "| %%3d | %%%ds | %%7.1f | %%6.3f(%%5.3f) | %%7.4f |\n", max_len);
 
        iter = NULL;
        i = 0;
@@ -846,12 +849,15 @@ rspamc_counters_output (FILE *out, ucl_object_t *obj)
                sym = ucl_object_lookup (cur, "symbol");
                weight = ucl_object_lookup (cur, "weight");
                freq = ucl_object_lookup (cur, "frequency");
+               freq_dev = ucl_object_lookup (cur, "frequency_stddev");
                tim = ucl_object_lookup (cur, "time");
+
                if (sym && weight && freq && tim) {
                        printf (fmt_buf, i,
                                ucl_object_tostring (sym),
                                ucl_object_todouble (weight),
                                ucl_object_todouble (freq),
+                               ucl_object_todouble (freq_dev),
                                ucl_object_todouble (tim));
                }
                i++;
index b5af6adc9164a1e9d4a674a17a8dbb9691ae61c8..abb6ebe81496e53d44c9860d9579559319c6366f 100644 (file)
@@ -776,7 +776,7 @@ rspamd_controller_handle_symbols (struct rspamd_http_connection_entry *conn_ent,
                group_symbols = ucl_object_typed_new (UCL_ARRAY);
 
                while (g_hash_table_iter_next (&sit, &k, &v)) {
-                       gdouble tm = 0.0, freq = 0;
+                       gdouble tm = 0.0, freq = 0, freq_dev = 0;
 
                        sym = v;
                        sym_obj = ucl_object_typed_new (UCL_OBJECT);
@@ -793,10 +793,13 @@ rspamd_controller_handle_symbols (struct rspamd_http_connection_entry *conn_ent,
                        }
 
                        if (rspamd_symbols_cache_stat_symbol (session->ctx->cfg->cache,
-                                       sym->name, &freq, &tm)) {
+                                       sym->name, &freq, &freq_dev, &tm)) {
                                ucl_object_insert_key (sym_obj,
                                                ucl_object_fromdouble (freq),
                                                "frequency", 0, false);
+                               ucl_object_insert_key (sym_obj,
+                                               ucl_object_fromdouble (freq_dev),
+                                               "frequency_stddev", 0, false);
                                ucl_object_insert_key (sym_obj,
                                                ucl_object_fromdouble (tm),
                                                "time", 0, false);
index 5c53a0e08f42b540e7d7d6e11cfa4628f143ac1c..557347899fd4ceb8010aa337dff1d1a50ad439c3 100644 (file)
@@ -2086,6 +2086,7 @@ gboolean
 rspamd_symbols_cache_stat_symbol (struct symbols_cache *cache,
                const gchar *name,
                gdouble *frequency,
+               gdouble *freq_stddev,
                gdouble *tm)
 {
        struct cache_item *item;
@@ -2099,7 +2100,8 @@ rspamd_symbols_cache_stat_symbol (struct symbols_cache *cache,
        item = g_hash_table_lookup (cache->items_by_symbol, name);
 
        if (item != NULL) {
-               *frequency = item->st->frequency_counter.mean;
+               *frequency = item->st->avg_frequency;
+               *freq_stddev = item->st->stddev_frequency;
                *tm = item->st->time_counter.mean;
 
                return TRUE;
index 7f8832f07afe5739aa6f92f592874634157ab697..eadffded39cb37a2529d333c37ebccc9abb467f8 100644 (file)
@@ -143,6 +143,7 @@ gint rspamd_symbols_cache_find_symbol (struct symbols_cache *cache,
 gboolean rspamd_symbols_cache_stat_symbol (struct symbols_cache *cache,
                const gchar *name,
                gdouble *frequency,
+               gdouble *freq_stddev,
                gdouble *tm);
 /**
  * Find symbol in cache by its id