Counters.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #include "anki/util/StdTypes.h"
  2. #include "anki/util/Singleton.h"
  3. #include "anki/util/File.h"
  4. #include "anki/util/HighRezTimer.h"
  5. namespace anki {
  6. /// Enumeration of counters
  7. enum Counter
  8. {
  9. C_FPS,
  10. C_MAIN_RENDERER_TIME,
  11. C_RENDERER_MS_TIME,
  12. C_RENDERER_IS_TIME,
  13. C_RENDERER_PPS_TIME,
  14. C_RENDERER_SHADOW_PASSES,
  15. C_RENDERER_DRAWCALLS_COUNT,
  16. C_RENDERER_VERTICES_COUNT,
  17. C_RENDERER_LIGHTS_COUNT,
  18. C_SCENE_UPDATE_TIME,
  19. C_SWAP_BUFFERS_TIME,
  20. C_COUNT
  21. };
  22. /// The counters manager. It's been used with a singleton
  23. class CountersManager
  24. {
  25. public:
  26. CountersManager();
  27. ~CountersManager();
  28. void increaseCounter(Counter counter, F64 val);
  29. void increaseCounter(Counter counter, U64 val);
  30. /// Write the counters of the frame. Should be called after swapbuffers
  31. void resolveFrame();
  32. /// Resolve all counters and closes the files. Should be called when app
  33. /// terminates
  34. void flush();
  35. /// Start a timer of a specific counter
  36. void startTimer(Counter counter);
  37. /// Stop the timer and increase the counter
  38. void stopTimerIncreaseCounter(Counter counter);
  39. private:
  40. File perframeFile;
  41. File perrunFile;
  42. Vector<U64> perframeValues;
  43. Vector<U64> perrunValues;
  44. Vector<HighRezTimer::Scalar> counterTimes;
  45. };
  46. /// The singleton of the counters manager
  47. typedef Singleton<CountersManager> CountersManagerSingleton;
  48. // Macros that encapsulate the functionaly
  49. #if ANKI_ENABLE_COUNTERS
  50. # define ANKI_COUNTER_INC(counter_, val_) \
  51. CountersManagerSingleton::get().increaseCounter(counter_, val_)
  52. # define ANKI_COUNTER_START_TIMER(counter_) \
  53. CountersManagerSingleton::get().startTimer(counter_)
  54. # define ANKI_COUNTER_STOP_TIMER_INC(counter_) \
  55. CountersManagerSingleton::get().stopTimerIncreaseCounter(counter_)
  56. # define ANKI_COUNTERS_RESOLVE_FRAME() \
  57. CountersManagerSingleton::get().resolveFrame()
  58. # define ANKI_COUNTERS_FLUSH() \
  59. CountersManagerSingleton::get().flush()
  60. #else // !ANKI_ENABLE_COUNTERS
  61. # define ANKI_COUNTER_INC(counter_, val_) ((void)0)
  62. # define ANKI_COUNTER_START_TIMER(counter_) ((void)0)
  63. # define ANKI_COUNTER_STOP_TIMER_INC(counter_) ((void)0)
  64. # define ANKI_COUNTERS_RESOLVE_FRAME() ((void)0)
  65. # define ANKI_COUNTERS_FLUSH() ((void)0)
  66. #endif // ANKI_ENABLE_COUNTERS
  67. } // end namespace anki