From: Vsevolod Stakhov Date: Wed, 13 Apr 2022 21:16:01 +0000 (+0100) Subject: [Minor] Add some more helpers X-Git-Tag: 3.3~293^2~33 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=491ff2c2d609bb2d7e35a8203413223c586f3f98;p=rspamd.git [Minor] Add some more helpers --- 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; + } }; /*