]> source.dussan.org Git - rspamd.git/commitdiff
Support re_cache statistics
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 10 Dec 2015 11:25:43 +0000 (11:25 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 10 Dec 2015 11:25:43 +0000 (11:25 +0000)
src/libserver/re_cache.c
src/libserver/re_cache.h

index c2ca68788200e970d4dd4e28ec76a88405acec6b..eba4f168ba00263d4444674853268600084d35b4 100644 (file)
@@ -107,6 +107,7 @@ struct rspamd_re_runtime {
        guchar *checked;
        guchar *results;
        struct rspamd_re_cache *cache;
+       struct rspamd_re_cache_stat stat;
 };
 
 static GQuark
@@ -411,6 +412,14 @@ rspamd_re_cache_runtime_new (struct rspamd_re_cache *cache)
        return rt;
 }
 
+const struct rspamd_re_cache_stat *
+rspamd_re_cache_get_stat (struct rspamd_re_runtime *rt)
+{
+       g_assert (rt != NULL);
+
+       return &rt->stat;
+}
+
 static guint
 rspamd_re_cache_process_pcre (struct rspamd_re_runtime *rt,
                rspamd_regexp_t *re, const guchar *in, gsize len,
@@ -442,6 +451,14 @@ rspamd_re_cache_process_pcre (struct rspamd_re_runtime *rt,
                }
        }
 
+       rt->stat.regexp_checked ++;
+       rt->stat.bytes_scanned_pcre += len;
+       rt->stat.bytes_scanned += len;
+
+       if (r > 0) {
+               rt->stat.regexp_matched ++;
+       }
+
        return r;
 }
 
@@ -478,6 +495,9 @@ rspamd_re_cache_hyperscan_cb (unsigned int id,
                                to - from,
                                FALSE);
        }
+       else {
+               rt->stat.regexp_matched++;
+       }
 
        setbit (rt->checked, id);
 
@@ -532,6 +552,7 @@ rspamd_re_cache_process_regexp_data (struct rspamd_re_runtime *rt,
                cbdata.in = in;
                cbdata.re = re;
                cbdata.rt = rt;
+               rt->stat.bytes_scanned += len;
 
                if ((hs_scan (re_class->hs_db, in, len, 0, re_class->hs_scratch,
                                rspamd_re_cache_hyperscan_cb, &cbdata)) != HS_SUCCESS) {
index 429d16e0a3bc6b7f19e358db49b2b72760f6414e..8e3505ba7502c232ed9aee023aea4a69f3784e54 100644 (file)
@@ -42,6 +42,13 @@ enum rspamd_re_type {
        RSPAMD_RE_MAX
 };
 
+struct rspamd_re_cache_stat {
+       guint64 bytes_scanned;
+       guint64 bytes_scanned_pcre;
+       guint regexp_checked;
+       guint regexp_matched;
+};
+
 /**
  * Initialize re_cache persistent structure
  */
@@ -78,6 +85,12 @@ void rspamd_re_cache_init (struct rspamd_re_cache *cache);
  */
 struct rspamd_re_runtime* rspamd_re_cache_runtime_new (struct rspamd_re_cache *cache);
 
+/**
+ * Get runtime statistics
+ */
+const struct rspamd_re_cache_stat *
+               rspamd_re_cache_get_stat (struct rspamd_re_runtime *rt);
+
 /**
  * Process regexp runtime and return the result for a specific regexp
  * @param task task object