aboutsummaryrefslogtreecommitdiffstats
path: root/src/client
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2018-07-28 15:05:38 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2018-07-28 15:05:38 +0100
commit3f126bff76de841969ddcff0c3c6dee00b1462c0 (patch)
tree6db682a65e409400f3a1255b572a12a6e84a3362 /src/client
parentb6e156e807a83b2b843929832869ccc3b6ecaec2 (diff)
downloadrspamd-3f126bff76de841969ddcff0c3c6dee00b1462c0.tar.gz
rspamd-3f126bff76de841969ddcff0c3c6dee00b1462c0.zip
[Feature] Improve `rspamc counters` output
Diffstat (limited to 'src/client')
-rw-r--r--src/client/rspamc.c44
1 files changed, 32 insertions, 12 deletions
diff --git a/src/client/rspamc.c b/src/client/rspamc.c
index 201e80403..58bb89a49 100644
--- a/src/client/rspamc.c
+++ b/src/client/rspamc.c
@@ -990,6 +990,15 @@ rspamc_counters_sort (const ucl_object_t **o1, const ucl_object_t **o2)
order2 = ucl_object_todouble (elt2) * 1000000;
}
}
+ else if (g_ascii_strcasecmp (args[0], "hits") == 0) {
+ elt1 = ucl_object_lookup (*o1, "hits");
+ elt2 = ucl_object_lookup (*o2, "hits");
+
+ if (elt1 && elt2) {
+ order1 = ucl_object_toint (elt1);
+ order2 = ucl_object_toint (elt2);
+ }
+ }
g_strfreev (args);
}
@@ -1001,9 +1010,9 @@ 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, *freq_dev, *tim;
+ const ucl_object_t *cur, *sym, *weight, *freq, *freq_dev, *nhits;
ucl_object_iter_t iter = NULL;
- gchar fmt_buf[64], dash_buf[82];
+ gchar fmt_buf[64], dash_buf[82], sym_buf[82];
gint l, max_len = INT_MIN, i;
static const gint dashes = 44;
@@ -1038,14 +1047,14 @@ rspamc_counters_output (FILE *out, ucl_object_t *obj)
if (tty) {
printf ("\033[1m");
}
- printf (fmt_buf, "Pri", "Symbol", "Weight", "Frequency", "Time");
+ printf (fmt_buf, "Pri", "Symbol", "Weight", "Frequency", "Hits");
printf (" %s \n", dash_buf);
- printf (fmt_buf, "", "", "", "hits/sec", "usec");
+ printf (fmt_buf, "", "", "", "hits/min", "");
if (tty) {
printf ("\033[0m");
}
rspamd_snprintf (fmt_buf, sizeof (fmt_buf),
- "| %%3d | %%%ds | %%7.1f | %%6.3f(%%5.3f) | %%7.4f |\n", max_len);
+ "| %%3d | %%%ds | %%7.1f | %%6.3f(%%5.3f) | %%7ju |\n", max_len);
iter = NULL;
i = 0;
@@ -1055,15 +1064,26 @@ rspamc_counters_output (FILE *out, ucl_object_t *obj)
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");
+ nhits = ucl_object_lookup (cur, "hits");
+
+ if (sym && weight && freq && nhits) {
+ const gchar *sym_name;
+
+ if (sym->len > max_len) {
+ rspamd_snprintf (sym_buf, sizeof (sym_buf), "%*s...",
+ (max_len - 3), ucl_object_tostring (sym));
+ sym_name = sym_buf;
+ }
+ else {
+ sym_name = ucl_object_tostring (sym);
+ }
- 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));
+ sym_name,
+ ucl_object_todouble (weight),
+ ucl_object_todouble (freq) * 60.0,
+ ucl_object_todouble (freq_dev) * 60.0,
+ (uintmax_t)ucl_object_toint (nhits));
}
i++;
}