+ to_string(lru_data.size()) + " trackers, memcap: " + to_string(host_cache.get_max_size())
+ " bytes\n";
- for(auto cache : host_cache.seg_list)
- {
- cache->lock();
- cache->stats.bytes_in_use = cache->current_size;
- cache->stats.items_in_use = cache->list.size();
- cache->unlock();
- }
-
PegCount* counts = (PegCount*) host_cache.get_counts();
for ( int i = 0; pegs[i].type != CountType::END; i++ )
{
+ to_string(lru_data.size()) + " trackers, memcap: " + to_string(host_cache.get_max_size())
+ " bytes\n";
- for(auto cache : host_cache.seg_list)
- {
- cache->lock();
- cache->stats.bytes_in_use = cache->current_size;
- cache->stats.items_in_use = cache->list.size();
- cache->unlock();
- }
-
PegCount* counts = (PegCount*) host_cache.get_counts();
const PegInfo* pegs = host_cache.get_pegs();
PegCount* HostCacheModule::get_counts() const
{ return (PegCount*)host_cache.get_counts(); }
+void HostCacheModule::prep_counts(bool)
+{ host_cache.update_counts(); }
+
void HostCacheModule::sum_stats(bool dump_stats)
{
- // These could be set in prep_counts but we set them here
- // to save an extra cache lock.
- for(auto cache : host_cache.seg_list)
- {
- cache->lock();
- cache->stats.bytes_in_use = cache->current_size;
- cache->stats.items_in_use = cache->list.size();
- cache->unlock();
- }
-
Module::sum_stats(dump_stats);
+ host_cache.sum_stats(dump_stats);
+}
+
+void HostCacheModule::reset_stats()
+{
+ host_cache.reset_counts();
+ Module::reset_stats();
}
void HostCacheModule::set_trace(const Trace* trace) const
#define DEFAULT_HOST_CACHE_SEGMENTS 4
extern SO_PUBLIC HostCacheIp default_host_cache;
+extern THREAD_LOCAL struct LruCacheSharedStats host_cache_counts;
template<typename Key, typename Value>
class HostCacheSegmented
bool reload_resize(size_t memcap_per_segment);
bool reload_prune(size_t new_size, unsigned max_prune);
void invalidate();
+ void update_counts();
+ void reset_counts();
+ void sum_stats(bool dump_stats);
std::shared_ptr<Value> operator[](const Key& key);
HostCacheIp* default_cache = &default_host_cache; // Default cache used for host tracker
private:
- void update_counts();
-
uint8_t segment_count;
std::atomic<size_t> memcap_per_segment;
struct LruCacheSharedStats counts;
bool init_done = false;
+ std::mutex stats_lock;
};
template<typename Key, typename Value>
void HostCacheSegmented<Key, Value>::update_counts()
{
+ std::lock_guard<std::mutex> guard(stats_lock);
PegCount* pcs = (PegCount*)&counts;
const PegInfo* pegs = get_pegs();
{
const PegCount* cache_counts = cache->get_counts();
cache->lock();
- for (int i = 0; pegs[i].type != CountType::END; i++)
+ cache->stats.bytes_in_use = cache->current_size;
+ cache->stats.items_in_use = cache->list.size();
+ for (int i = 0; pegs[i].type != CountType::END; i++)
pcs[i] += cache_counts[i];
cache->unlock();
}
+ host_cache_counts = counts;
+}
+
+template<typename Key, typename Value>
+void HostCacheSegmented<Key, Value>::reset_counts()
+{
+ std::lock_guard<std::mutex> guard(stats_lock);
+ const PegInfo* pegs = get_pegs();
+
+ for (auto cache : seg_list)
+ {
+ PegCount* cache_counts = reinterpret_cast<PegCount*> (&cache->stats);
+ cache->lock();
+ for (int i = 0; pegs[i].type != CountType::END; i++)
+ cache_counts[i] = 0;
+ cache->unlock();
+ }
+}
+
+template<typename Key, typename Value>
+void HostCacheSegmented<Key, Value>::sum_stats(bool dump_stats)
+{
+ std::lock_guard<std::mutex> guard(stats_lock);
+ if ( !dump_stats )
+ {
+ const PegInfo* pegs = get_pegs();
+
+ for (auto cache : seg_list)
+ {
+ PegCount* cache_counts = reinterpret_cast<PegCount*> (&cache->stats);
+ cache->lock();
+ for (int i = 0; pegs[i].type != CountType::END; i++)
+ {
+ if ( pegs[i].type == CountType::SUM )
+ cache_counts[i] = 0;
+ }
+ cache->unlock();
+ }
+ }
}
template<typename Key, typename Value>
template<typename Key, typename Value>
PegCount* HostCacheSegmented<Key, Value>::get_counts()
{
- if(init_done)
+ if( init_done )
update_counts();
- return (PegCount*)&counts;
+
+ return (PegCount*)&host_cache_counts;
}
template<typename Key, typename Value>