cacheStats.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /**
  2. * PANDA 3D SOFTWARE
  3. * Copyright (c) Carnegie Mellon University. All rights reserved.
  4. *
  5. * All use of this software is subject to the terms of the revised BSD
  6. * license. You should have received a copy of this license along
  7. * with this source code in a file named "LICENSE."
  8. *
  9. * @file cacheStats.h
  10. * @author drose
  11. * @date 2007-07-24
  12. */
  13. #ifndef CACHESTATS_H
  14. #define CACHESTATS_H
  15. #include "pandabase.h"
  16. #include "clockObject.h"
  17. #include "pnotify.h"
  18. /**
  19. * This is used to track the utilization of the TransformState and RenderState
  20. * caches, for low-level performance tuning information.
  21. */
  22. class EXPCL_PANDA_PGRAPH CacheStats {
  23. public:
  24. CacheStats() = default;
  25. void init();
  26. void reset(double now);
  27. void write(std::ostream &out, const char *name) const;
  28. INLINE void maybe_report(const char *name);
  29. INLINE void inc_hits();
  30. INLINE void inc_misses();
  31. INLINE void inc_adds(bool is_new);
  32. INLINE void inc_dels();
  33. INLINE void add_total_size(int count);
  34. INLINE void add_num_states(int count);
  35. private:
  36. #ifndef NDEBUG
  37. int _cache_hits = 0;
  38. int _cache_misses = 0;
  39. int _cache_adds = 0;
  40. int _cache_new_adds = 0;
  41. int _cache_dels = 0;
  42. int _total_cache_size = 0;
  43. int _num_states = 0;
  44. double _last_reset = 0.0;
  45. bool _cache_report = false;
  46. double _cache_report_interval = 0.0;
  47. #endif // NDEBUG
  48. };
  49. #include "cacheStats.I"
  50. #endif