commit 491ff2c: [Minor] Add some more helpers
Vsevolod Stakhov
vsevolod at rspamd.com
Sat Apr 30 19:21:27 UTC 2022
Author: Vsevolod Stakhov
Date: 2022-04-13 22:16:01 +0100
URL: https://github.com/rspamd/rspamd/commit/491ff2c2d609bb2d7e35a8203413223c586f3f98
[Minor] Add some more helpers
---
src/libserver/symcache/symcache_c.cxx | 51 +++++++++++++++++++++++++++-
src/libserver/symcache/symcache_internal.hxx | 10 ++++++
2 files changed, 60 insertions(+), 1 deletion(-)
diff --git a/src/libserver/symcache/symcache_c.cxx b/src/libserver/symcache/symcache_c.cxx
index c61b17340..88a0d5605 100644
--- a/src/libserver/symcache/symcache_c.cxx
+++ b/src/libserver/symcache/symcache_c.cxx
@@ -93,4 +93,53 @@ rspamd_symcache_add_condition_delayed (struct rspamd_symcache *cache,
real_cache->add_delayed_condition(sym, cbref);
return TRUE;
-}
\ No newline at end of file
+}
+
+gint rspamd_symcache_find_symbol (struct rspamd_symcache *cache,
+ const gchar *name)
+{
+ auto *real_cache = C_API_SYMCACHE(cache);
+
+ auto sym_maybe = real_cache->get_item_by_name(name, false);
+
+ if (sym_maybe != nullptr) {
+ return sym_maybe->id;
+ }
+
+ return -1;
+}
+
+gboolean rspamd_symcache_stat_symbol (struct rspamd_symcache *cache,
+ const gchar *name,
+ gdouble *frequency,
+ gdouble *freq_stddev,
+ gdouble *tm,
+ guint *nhits)
+{
+ auto *real_cache = C_API_SYMCACHE(cache);
+
+ auto sym_maybe = real_cache->get_item_by_name(name, false);
+
+ if (sym_maybe != nullptr) {
+ *frequency = sym_maybe->st->avg_frequency;
+ *freq_stddev = sqrt(sym_maybe->st->stddev_frequency);
+ *tm = sym_maybe->st->time_counter.mean;
+
+ if (nhits) {
+ *nhits = sym_maybe->st->hits;
+ }
+
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+
+guint
+rspamd_symcache_stats_symbols_count (struct rspamd_symcache *cache)
+{
+ auto *real_cache = C_API_SYMCACHE(cache);
+ return real_cache->get_stats_symbols_count();
+}
+
diff --git a/src/libserver/symcache/symcache_internal.hxx b/src/libserver/symcache/symcache_internal.hxx
index e967bbe83..155efa1ae 100644
--- a/src/libserver/symcache/symcache_internal.hxx
+++ b/src/libserver/symcache/symcache_internal.hxx
@@ -377,6 +377,8 @@ private:
double total_weight;
std::size_t used_items;
std::size_t stats_symbols_count;
+
+private:
std::uint64_t total_hits;
struct rspamd_config *cfg;
@@ -509,6 +511,14 @@ public:
* @param cbref
*/
auto add_delayed_condition(std::string_view sym, int cbref) -> void;
+
+ /**
+ * Returns number of symbols that needs to be checked in statistical algorithm
+ * @return
+ */
+ auto get_stats_symbols_count() const {
+ return stats_symbols_count;
+ }
};
/*
More information about the Commits
mailing list