diff options
author | 2011-03-11 21:49:04 +0000 | |
---|---|---|
committer | 2011-03-11 21:49:04 +0000 | |
commit | 75a85b781c6e97e7c5df24a316b385a3aae76423 (patch) | |
tree | e8d4bcb7d317c41a6b5cad63fce8642fc0a30347 | |
parent | 6dc6fabb8a074fcef35cd9ac409245702f3e386d (diff) | |
download | paludis-75a85b781c6e97e7c5df24a316b385a3aae76423.tar.gz paludis-75a85b781c6e97e7c5df24a316b385a3aae76423.tar.xz |
Pool stats
-rw-r--r-- | paludis/util/pool-impl.hh | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/paludis/util/pool-impl.hh b/paludis/util/pool-impl.hh index ac40c6516..891758c51 100644 --- a/paludis/util/pool-impl.hh +++ b/paludis/util/pool-impl.hh @@ -23,6 +23,8 @@ #include <paludis/util/pool.hh> #include <paludis/util/mutex.hh> #include <paludis/util/hashes.hh> +#include <paludis/util/log.hh> +#include <paludis/util/stringify.hh> #include <unordered_map> #include <memory> @@ -37,10 +39,31 @@ namespace paludis } template <typename T_> + struct PoolReuseScore + { + static const std::string message(const int size, const int reused) + { + return "Size " + stringify(size) + " reused " + stringify(reused) + " for " + __PRETTY_FUNCTION__; + } + }; + + template <typename T_> struct Imp<Pool<T_> > { mutable Mutex mutex; mutable std::unordered_map<PoolKeys, std::shared_ptr<const T_>, PoolKeysHasher, PoolKeysComparator> store; + mutable unsigned reused; + + Imp() : + reused(0) + { + } + + ~Imp() + { + Log::get_instance()->message("pool.reused_score", ll_debug, lc_no_context) + << PoolReuseScore<T_>::message(store.size(), reused); + } }; template <typename T_> @@ -80,6 +103,8 @@ namespace paludis auto i(_imp->store.find(keys)); if (i == _imp->store.end()) i = _imp->store.insert(std::make_pair(keys, std::make_shared<const T_>(PreventConversion<Args_>(args)...))).first; + else + ++_imp->reused; return i->second; } |