diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-12-10 11:25:43 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-12-10 11:25:43 +0000 |
commit | 0c08e9013e3892b65b43e868a470d9339b851c19 (patch) | |
tree | 75073c5b36662cc0ebca8e1f1a209382a29f7b3b /src/libserver | |
parent | 864f980038500399b4f15bf9b60eea1ebba845e4 (diff) | |
download | rspamd-0c08e9013e3892b65b43e868a470d9339b851c19.tar.gz rspamd-0c08e9013e3892b65b43e868a470d9339b851c19.zip |
Support re_cache statistics
Diffstat (limited to 'src/libserver')
-rw-r--r-- | src/libserver/re_cache.c | 21 | ||||
-rw-r--r-- | src/libserver/re_cache.h | 13 |
2 files changed, 34 insertions, 0 deletions
diff --git a/src/libserver/re_cache.c b/src/libserver/re_cache.c index c2ca68788..eba4f168b 100644 --- a/src/libserver/re_cache.c +++ b/src/libserver/re_cache.c @@ -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) { diff --git a/src/libserver/re_cache.h b/src/libserver/re_cache.h index 429d16e0a..8e3505ba7 100644 --- a/src/libserver/re_cache.h +++ b/src/libserver/re_cache.h @@ -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 */ @@ -79,6 +86,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 * @param rt cache runtime object |