Team Fortress 2 Source Code as on 22/4/2020
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.

126 lines
3.4 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $Workfile: $
  6. // $Date: $
  7. // $NoKeywords: $
  8. //=============================================================================//
  9. #if !defined( MEASURE_SECTION_H )
  10. #define MEASURE_SECTION_H
  11. #ifdef _WIN32
  12. #pragma once
  13. #endif
  14. #include "tier0/fasttimer.h"
  15. #include "convar.h"
  16. // This is the macro to use in your code to measure until the code goes
  17. // out of scope
  18. #if defined( _DEBUG ) || defined( FORCE_MEASURE )
  19. #define MEASURECODE( description ) \
  20. static CMeasureSection _xxx_ms( description ); \
  21. CMeasureSectionInstance _xxx_ms_inst( &_xxx_ms );
  22. #else
  23. #define MEASURECODE( description )
  24. #endif
  25. // ------------------------------------------------------------------------------------ //
  26. // These things must exist in the executable for the CMeasureSection code to work.
  27. // ------------------------------------------------------------------------------------ //
  28. float GetRealTime(); // Get the clock's time.
  29. extern ConVar game_speeds;
  30. extern ConVar measure_resort;
  31. // ------------------------------------------------------------------------------------ //
  32. // Called once per frame to allow any necessary measurements to latch
  33. void ResetTimeMeasurements( void );
  34. //-----------------------------------------------------------------------------
  35. // Purpose: Accumulates time for the named section
  36. //-----------------------------------------------------------------------------
  37. class CMeasureSection
  38. {
  39. public:
  40. // Allows for measuring named section
  41. CMeasureSection( const char *name );
  42. virtual ~CMeasureSection( void );
  43. // Update max value hit
  44. void UpdateMax( void );
  45. // Reset totals
  46. void Reset( void );
  47. // Reset sortable totals
  48. void SortReset( void );
  49. // Get static name of section
  50. const char *GetName( void );
  51. // Get accumulated time
  52. CCycleCount const& GetTotalTime( void );
  53. CCycleCount const& GetTime();
  54. CCycleCount const& GetMaxTime();
  55. // Add in some time
  56. void AddTime( CCycleCount const &rCount );
  57. // Get next section in chain
  58. CMeasureSection *GetNext( void );
  59. // Get head of list of all sections
  60. static CMeasureSection *GetList( void );
  61. // Sort all sections by most time consuming
  62. static void SortSections( void );
  63. public:
  64. // Time when list should be sorted again
  65. static double m_dNextResort;
  66. private:
  67. // Accumulated time for section
  68. CCycleCount m_dAccumulatedTime;
  69. // Max time for section
  70. CCycleCount m_dMaxTime;
  71. // Elapsed time for section
  72. CCycleCount m_dTotalTime;
  73. // Name of section
  74. const char *m_pszName;
  75. // Next section in chain
  76. CMeasureSection *m_pNext;
  77. // Head of section list
  78. static CMeasureSection *s_pSections;
  79. // Quick total for doing sorts faster
  80. static int s_nCount;
  81. };
  82. //-----------------------------------------------------------------------------
  83. // Purpose: On construction marks time and on destruction adds time to
  84. // parent CMeasureSection object
  85. //-----------------------------------------------------------------------------
  86. class CMeasureSectionInstance
  87. {
  88. public:
  89. // Constructor: Points to object to accumulate time into
  90. CMeasureSectionInstance( CMeasureSection *ms );
  91. // Destructor: Latches accumulated time
  92. virtual ~CMeasureSectionInstance( void );
  93. private:
  94. // Time of construction
  95. CFastTimer m_Timer;
  96. // Where to place elapsed time
  97. CMeasureSection *m_pMS;
  98. };
  99. #endif // MEASURE_SECTION_H