expr->subr->priority (elt->p.atom);
}
elt->p.atom->hits = 0;
- elt->p.atom->avg_ticks = 0.0;
}
}
return FALSE;
}
-#define ATOM_PRIORITY(a) ((a)->p.atom->hits / ((a)->p.atom->avg_ticks > 0 ? \
- (a)->p.atom->avg_ticks * 10000000 : 1.0))
+#define ATOM_PRIORITY(a) ((a)->p.atom->hits / ((a)->p.atom->exec_time.mean > 0 ? \
+ (a)->p.atom->exec_time.mean * 10000000 : 1.0))
static gint
rspamd_ast_priority_cmp (GNode *a, GNode *b)
w2 = ATOM_PRIORITY (eb);
ea->p.atom->hits = 0;
- ea->p.atom->avg_ticks = 0.0;
return w1 - w2;
}
struct rspamd_expression_elt *elt;
GNode *cld;
gdouble acc = NAN;
- gdouble t1, t2, val;
+ float t1, t2;
+ gdouble val;
gboolean calc_ticks = FALSE;
const gchar *op_name = NULL;
switch (elt->type) {
case ELT_ATOM:
if (!(elt->flags & RSPAMD_EXPR_FLAG_PROCESSED)) {
-
/*
- * Sometimes get ticks for this expression. 'Sometimes' here means
- * that we get lowest 5 bits of the counter `evals` and 5 bits
- * of some shifted address to provide some sort of jittering for
- * ticks evaluation
+ * Check once per 256 evaluations approx
*/
- if ((e->evals & 0x1F) == (GPOINTER_TO_UINT (node) >> 4 & 0x1F)) {
- calc_ticks = TRUE;
+ calc_ticks = (rspamd_random_uint64_fast() & 0xff) == 0xff;
+ if (calc_ticks) {
t1 = rspamd_get_ticks (TRUE);
}
if (calc_ticks) {
t2 = rspamd_get_ticks (TRUE);
- elt->p.atom->avg_ticks += ((t2 - t1) - elt->p.atom->avg_ticks) /
- (e->evals);
+ rspamd_set_counter_ema(&elt->p.atom->exec_time, (t2 - t1), 0.5f);
}
elt->flags |= RSPAMD_EXPR_FLAG_PROCESSED;
#include "config.h"
#include "mem_pool.h"
#include "fstring.h"
+#include "util.h"
#ifdef __cplusplus
extern "C" {
/* String representation of atom */
const gchar *str;
/* Length of the string representation of atom */
- gsize len;
- /* Average execution time (in ticks) */
- gdouble avg_ticks;
- /* Amount of positive triggers */
- guint hits;
+ guint len;
/* Relative priority */
gint priority;
+ guint hits;
+ struct rspamd_counter_data exec_time;
} rspamd_expression_atom_t;
typedef gdouble (*rspamd_expression_process_cb) (gpointer runtime_data,