Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

144 lines
3.2 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef ENGINESTATS_H
  8. #define ENGINESTATS_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "utlvector.h"
  13. #include "sysexternal.h"
  14. #include "filesystem.h" // FileHandle_t define
  15. enum EngineTimedStatId_t
  16. {
  17. ENGINE_STATS_FRAME_TIME,
  18. ENGINE_STATS_FPS, // this is calculated at EndFrame!
  19. ENGINE_STATS_FPS_VARIABILITY,
  20. ENGINE_STATS_NUM_TIMED_STATS,
  21. };
  22. class CEngineStats
  23. {
  24. public:
  25. CEngineStats();
  26. //
  27. // stats input
  28. //
  29. void BeginRun( void );
  30. // Advances the next frame for the stats...
  31. void NextFrame();
  32. void BeginFrame( void );
  33. // Timed stat gathering
  34. void BeginTimedStat( EngineTimedStatId_t stat );
  35. void EndTimedStat( EngineTimedStatId_t stat );
  36. // Adds to a timed stat...
  37. void AddToTimedStat( EngineTimedStatId_t stat, float time );
  38. // Slams a timed stat
  39. void SetTimedStat( EngineTimedStatId_t stat, float time );
  40. // returns timed stats
  41. double TimedStatInFrame( EngineTimedStatId_t stat ) const;
  42. double TotalTimedStat( EngineTimedStatId_t stat ) const;
  43. void BeginDrawWorld( void );
  44. void EndDrawWorld( void );
  45. void EndFrame( void );
  46. void EndRun( void );
  47. void PauseStats( bool bPaused );
  48. //
  49. // stats output
  50. // call these outside of a BeginFrame/EndFrame pair
  51. //
  52. double GetRunTime( void );
  53. void SetFrameTime( float flFrameTime ) { m_flFrameTime = flFrameTime; }
  54. void SetFPSVariability( float flFPSVariability ) { m_flFPSVariability = flFPSVariability; }
  55. int FrameCount() const { return m_totalNumFrames; }
  56. void EnableVProfStatsRecording( const char *pFileName );
  57. private:
  58. void ComputeFrameTimeStats( void );
  59. // How many frames worth of data have we logged?
  60. int m_totalNumFrames;
  61. // run timing data
  62. double m_runStartTime;
  63. double m_runEndTime;
  64. struct StatGroupInfo_t
  65. {
  66. double m_StatFrameTime[ENGINE_STATS_NUM_TIMED_STATS];
  67. double m_StatStartTime[ENGINE_STATS_NUM_TIMED_STATS];
  68. double m_TotalStatTime[ENGINE_STATS_NUM_TIMED_STATS];
  69. };
  70. StatGroupInfo_t m_StatGroup;
  71. bool m_InFrame;
  72. bool m_bPaused;
  73. bool m_bInRun;
  74. float m_flFrameTime;
  75. float m_flFPSVariability;
  76. char m_szVProfStatsFileName[MAX_PATH];
  77. };
  78. //-----------------------------------------------------------------------------
  79. // Inlined stat gathering methods
  80. //-----------------------------------------------------------------------------
  81. inline void CEngineStats::BeginTimedStat( EngineTimedStatId_t stat )
  82. {
  83. if (m_InFrame)
  84. {
  85. m_StatGroup.m_StatStartTime[stat] =
  86. Sys_FloatTime();
  87. }
  88. }
  89. inline void CEngineStats::EndTimedStat( EngineTimedStatId_t stat )
  90. {
  91. if (m_InFrame)
  92. {
  93. float dt = (float)Sys_FloatTime() - (float)(m_StatGroup.m_StatStartTime[stat]);
  94. m_StatGroup.m_StatFrameTime[stat] += dt;
  95. }
  96. }
  97. // Adds to a timed stat...
  98. inline void CEngineStats::AddToTimedStat( EngineTimedStatId_t stat, float dt )
  99. {
  100. if (m_InFrame)
  101. {
  102. m_StatGroup.m_StatFrameTime[stat] += dt;
  103. }
  104. }
  105. // Slams a timed stat
  106. inline void CEngineStats::SetTimedStat( EngineTimedStatId_t stat, float time )
  107. {
  108. m_StatGroup.m_StatFrameTime[stat] = time;
  109. }
  110. extern CEngineStats g_EngineStats;
  111. #endif // ENGINESTATS_H