Browse Source

[Minor] Improve counters output

tags/1.5.0
Vsevolod Stakhov 7 years ago
parent
commit
31ff56946c
4 changed files with 24 additions and 12 deletions
  1. 15
    9
      src/client/rspamc.c
  2. 5
    2
      src/controller.c
  3. 3
    1
      src/libserver/symbols_cache.c
  4. 1
    0
      src/libserver/symbols_cache.h

+ 15
- 9
src/client/rspamc.c View 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++;

+ 5
- 2
src/controller.c View 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);

+ 3
- 1
src/libserver/symbols_cache.c View 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;

+ 1
- 0
src/libserver/symbols_cache.h View 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

Loading…
Cancel
Save