wwprofile.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. /*
  2. ** Command & Conquer Generals(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /***********************************************************************************************
  19. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : WWDebug *
  23. * *
  24. * $Archive:: /Commando/Code/wwdebug/wwprofile.h $*
  25. * *
  26. * $Author:: Tom_s $*
  27. * *
  28. * $Modtime:: 6/29/01 3:10p $*
  29. * *
  30. * $Revision:: 8 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #if _MSC_VER >= 1000
  36. #pragma once
  37. #endif // _MSC_VER >= 1000
  38. #ifndef WWPROFILE_H
  39. #define WWPROFILE_H
  40. #ifdef _UNIX
  41. typedef signed long long __int64;
  42. typedef signed long long _int64;
  43. #endif
  44. /*
  45. ** A node in the WWProfile Hierarchy Tree
  46. */
  47. class WWProfileHierachyNodeClass {
  48. public:
  49. WWProfileHierachyNodeClass( const char * name, WWProfileHierachyNodeClass * parent );
  50. ~WWProfileHierachyNodeClass( void );
  51. WWProfileHierachyNodeClass * Get_Sub_Node( const char * name );
  52. WWProfileHierachyNodeClass * Get_Parent( void ) { return Parent; }
  53. WWProfileHierachyNodeClass * Get_Sibling( void ) { return Sibling; }
  54. WWProfileHierachyNodeClass * Get_Child( void ) { return Child; }
  55. void Reset( void );
  56. void Call( void );
  57. bool Return( void );
  58. const char * Get_Name( void ) { return Name; }
  59. int Get_Total_Calls( void ) { return TotalCalls; }
  60. float Get_Total_Time( void ) { return TotalTime; }
  61. protected:
  62. const char * Name;
  63. int TotalCalls;
  64. float TotalTime;
  65. __int64 StartTime;
  66. int RecursionCounter;
  67. WWProfileHierachyNodeClass * Parent;
  68. WWProfileHierachyNodeClass * Child;
  69. WWProfileHierachyNodeClass * Sibling;
  70. };
  71. /*
  72. ** An iterator to navigate through the tree
  73. */
  74. class WWProfileIterator
  75. {
  76. public:
  77. // Access all the children of the current parent
  78. void First(void);
  79. void Next(void);
  80. bool Is_Done(void);
  81. void Enter_Child( void ); // Make the current child the new parent
  82. void Enter_Child( int index ); // Make the given child the new parent
  83. void Enter_Parent( void ); // Make the current parent's parent the new parent
  84. // Access the current child
  85. const char * Get_Current_Name( void ) { return CurrentChild->Get_Name(); }
  86. int Get_Current_Total_Calls( void ) { return CurrentChild->Get_Total_Calls(); }
  87. float Get_Current_Total_Time( void ) { return CurrentChild->Get_Total_Time(); }
  88. // Access the current parent
  89. const char * Get_Current_Parent_Name( void ) { return CurrentParent->Get_Name(); }
  90. int Get_Current_Parent_Total_Calls( void ) { return CurrentParent->Get_Total_Calls(); }
  91. float Get_Current_Parent_Total_Time( void ) { return CurrentParent->Get_Total_Time(); }
  92. protected:
  93. WWProfileHierachyNodeClass * CurrentParent;
  94. WWProfileHierachyNodeClass * CurrentChild;
  95. WWProfileIterator( WWProfileHierachyNodeClass * start );
  96. friend class WWProfileManager;
  97. };
  98. /*
  99. ** An iterator to walk through the tree in depth first order
  100. */
  101. class WWProfileInOrderIterator
  102. {
  103. public:
  104. void First(void);
  105. void Next(void);
  106. bool Is_Done(void);
  107. // Access the current node
  108. const char * Get_Current_Name( void ) { return CurrentNode->Get_Name(); }
  109. int Get_Current_Total_Calls( void ) { return CurrentNode->Get_Total_Calls(); }
  110. float Get_Current_Total_Time( void ) { return CurrentNode->Get_Total_Time(); }
  111. protected:
  112. WWProfileHierachyNodeClass * CurrentNode;
  113. WWProfileInOrderIterator( void );
  114. friend class WWProfileManager;
  115. };
  116. /*
  117. ** The Manager for the WWProfile system
  118. */
  119. class WWProfileManager {
  120. public:
  121. static void Start_Profile( const char * name );
  122. static void Stop_Profile( void );
  123. static void Reset( void );
  124. static void Increment_Frame_Counter( void );
  125. static int Get_Frame_Count_Since_Reset( void ) { return FrameCounter; }
  126. static float Get_Time_Since_Reset( void );
  127. static WWProfileIterator * Get_Iterator( void );
  128. static void Release_Iterator( WWProfileIterator * iterator );
  129. static WWProfileInOrderIterator * Get_In_Order_Iterator( void );
  130. static void Release_In_Order_Iterator( WWProfileInOrderIterator * iterator );
  131. private:
  132. static WWProfileHierachyNodeClass Root;
  133. static WWProfileHierachyNodeClass * CurrentNode;
  134. static int FrameCounter;
  135. static __int64 ResetTime;
  136. friend class WWProfileInOrderIterator;
  137. };
  138. /*
  139. ** WWProfileSampleClass is a simple way to profile a function's scope
  140. ** Use the WWPROFILE macro at the start of scope to time
  141. */
  142. class WWProfileSampleClass {
  143. public:
  144. WWProfileSampleClass( const char * name )
  145. {
  146. WWProfileManager::Start_Profile( name );
  147. }
  148. ~WWProfileSampleClass( void )
  149. {
  150. WWProfileManager::Stop_Profile();
  151. }
  152. };
  153. #ifdef WWDEBUG
  154. #define WWPROFILE( name ) WWProfileSampleClass _wwprofile( name )
  155. #else
  156. #define WWPROFILE( name )
  157. #endif
  158. /*
  159. ** WWTimeIt is like WWProfile, but it doesn't save anything, it just times one routine, regardless of thread
  160. */
  161. class WWTimeItClass {
  162. public:
  163. WWTimeItClass( const char * name );
  164. ~WWTimeItClass( void );
  165. private:
  166. const char * Name;
  167. __int64 Time;
  168. };
  169. #ifdef WWDEBUG
  170. #define WWTIMEIT( name ) WWTimeItClass _wwtimeit( name )
  171. #else
  172. #define WWTIMEIT( name )
  173. #endif
  174. /*
  175. ** TSS 06/27/01
  176. ** WWMeasureItClass is like WWTimeItClass, but it pokes the result into the given float,
  177. ** and can be used in the release build.
  178. */
  179. class WWMeasureItClass {
  180. public:
  181. WWMeasureItClass( float * p_result );
  182. ~WWMeasureItClass( void );
  183. private:
  184. __int64 Time;
  185. float * PResult;
  186. };
  187. #endif // WWPROFILE_H