ECCache.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * Copyright 2005 - 2016 Zarafa and its licensors
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU Affero General Public License, version 3,
  6. * as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU Affero General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU Affero General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. *
  16. */
  17. #include <kopano/platform.h>
  18. #include <kopano/kcodes.h>
  19. #include "ECCache.h"
  20. #include <kopano/ECLogger.h>
  21. #include <kopano/stringutil.h>
  22. namespace KC {
  23. ECCacheBase::ECCacheBase(const std::string &strCachename, size_type ulMaxSize, long lMaxAge)
  24. : m_strCachename(strCachename)
  25. , m_ulMaxSize(ulMaxSize)
  26. , m_lMaxAge(lMaxAge)
  27. { }
  28. void ECCacheBase::RequestStats(void(callback)(const std::string &, const std::string &, const std::string &, void*), void *obj)
  29. {
  30. callback((std::string)"cache_" + m_strCachename + "_items", (std::string)"Cache " + m_strCachename + " items", stringify_int64(ItemCount()), obj);
  31. callback((std::string)"cache_" + m_strCachename + "_size", (std::string)"Cache " + m_strCachename + " size", stringify_int64(Size()), obj);
  32. callback((std::string)"cache_" + m_strCachename + "_maxsz", (std::string)"Cache " + m_strCachename + " maximum size", stringify_int64(m_ulMaxSize), obj);
  33. callback((std::string)"cache_" + m_strCachename + "_req", (std::string)"Cache " + m_strCachename + " requests", stringify_int64(HitCount()), obj);
  34. callback((std::string)"cache_" + m_strCachename + "_hit", (std::string)"Cache " + m_strCachename + " hits", stringify_int64(ValidCount()), obj);
  35. }
  36. void ECCacheBase::DumpStats(void) const
  37. {
  38. unsigned long long z;
  39. std::string strName;
  40. strName = m_strCachename + " cache size:";
  41. z = Size();
  42. ec_log_info(
  43. " %-30s %8lu (%8llu bytes) (usage %.02f%%)",
  44. strName.c_str(), ItemCount(), z, z / (double)MaxSize() * 100.0);
  45. strName = m_strCachename + " cache hits:";
  46. z = ValidCount();
  47. ec_log_info(" %-30s %8llu / %llu (%.02f%%)",
  48. strName.c_str(), z, static_cast<unsigned long long>(HitCount()),
  49. z / (double)HitCount() * 100.0);
  50. }
  51. } /* namespace */