profile_highlevel.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. /*
  2. ** Command & Conquer Generals Zero Hour(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. /////////////////////////////////////////////////////////////////////////EA-V1
  19. // $File: //depot/GeneralsMD/Staging/code/Libraries/Source/profile/profile_highlevel.h $
  20. // $Author: mhoffe $
  21. // $Revision: #2 $
  22. // $DateTime: 2003/07/09 10:57:23 $
  23. //
  24. // ©2003 Electronic Arts
  25. //
  26. // High level profiling
  27. //////////////////////////////////////////////////////////////////////////////
  28. #ifdef _MSC_VER
  29. # pragma once
  30. #endif
  31. #ifndef PROFILE_HIGHLEVEL_H // Include guard
  32. #define PROFILE_HIGHLEVEL_H
  33. /// \internal internal Id representation
  34. class ProfileId;
  35. /**
  36. \brief The high level profiler.
  37. */
  38. class ProfileHighLevel
  39. {
  40. friend class Profile;
  41. // no, no copying allowed!
  42. ProfileHighLevel(const ProfileHighLevel&);
  43. ProfileHighLevel& operator=(const ProfileHighLevel&);
  44. public:
  45. /// \brief A high level profile ID.
  46. class Id
  47. {
  48. friend ProfileHighLevel;
  49. public:
  50. Id(void): m_idPtr(0) {}
  51. /**
  52. \brief Increment the internal profile value.
  53. \note Do not mix with SetMax.
  54. \param add amount to add to internal profile value
  55. */
  56. void Increment(double add=1.0);
  57. /**
  58. \brief Set a new maximum value.
  59. \note Do not mix with Increment.
  60. This function sets a new maximum value (if the value
  61. passed in is actually larger than the current max value).
  62. \param max new maximum value (if larger than current max value,
  63. otherwise current max value is left unchanged)
  64. */
  65. void SetMax(double max);
  66. /**
  67. \brief Returns the internal Id name.
  68. \return internal Id name, e.g. 'render.texture.count.512x512'
  69. */
  70. const char *GetName(void) const;
  71. /**
  72. \brief Returns the descriptive name.
  73. \return descriptive name, e.g. '# of 512x512 textures'
  74. */
  75. const char *GetDescr(void) const;
  76. /**
  77. \brief Returns the value's unit text.
  78. \return unit text, e.g. 'bytes'
  79. */
  80. const char *GetUnit(void) const;
  81. /**
  82. \brief Returns the current value.
  83. 'Current' means the value since the last call to this function for
  84. the same Id.
  85. This function is intended for displaying profile data while the
  86. application is running.
  87. \note The contents of the buffer returned may be overwritten by
  88. any consecutive call to any profile module function.
  89. \return current value
  90. */
  91. const char *GetCurrentValue(void) const;
  92. /**
  93. \brief Returns the value for the given recorded frame/range.
  94. \note The contents of the buffer returned may be overwritten by
  95. any consecutive call to any profile module function.
  96. \param frame number of recorded frame/range
  97. \return value at given frame, NULL if frame not found
  98. */
  99. const char *GetValue(unsigned frame) const;
  100. /**
  101. \brief Returns the total value for all frames.
  102. This even includes data collected while no frames have been
  103. recorded.
  104. \note A call to ProfileHighLevel::ClearTotals() resets this value.
  105. \return total value
  106. */
  107. const char *GetTotalValue(void) const;
  108. private:
  109. /// internal pointer
  110. ProfileId *m_idPtr;
  111. };
  112. /// \brief Timer based function block profile
  113. class Block
  114. {
  115. friend ProfileHighLevel;
  116. // no copying
  117. Block(const Block&);
  118. Block& operator=(const Block&);
  119. public:
  120. /**
  121. \brief Instructs high level profiler to start a new timer
  122. based function block (or update if it already exists)
  123. \note These function blocks are in the same name space as
  124. high level profile values registered with ProfileHighLevel::AddProfile()
  125. \param name name of function block
  126. */
  127. explicit Block(const char *name);
  128. /// \brief Updates timer based function block
  129. ~Block();
  130. private:
  131. /// internal id (time)
  132. Id m_idTime;
  133. /// start time
  134. _int64 m_start;
  135. };
  136. /**
  137. \brief Registers a new high level profile value.
  138. If there is already a high level profile with the given name the
  139. Id of that profile is returned instead.
  140. High level profiles can only be added, never removed.
  141. \note Important: This function can (and should) be used in static
  142. initializers!
  143. \note This function may be slow so don't use it too often.
  144. \param name value name, e.g. "render.texture.count.512x512"
  145. \param descr descriptive name, e.g. "# of 512x512 textures"
  146. \param unit unit name, e.g. "byte" or "sec"
  147. \param precision number of decimal places to show
  148. \param exp10 10 base exponent (used for scaleing)
  149. \return internal profile ID value
  150. */
  151. static Id AddProfile(const char *name, const char *descr, const char *unit, int precision, int exp10=0);
  152. /**
  153. \brief Enumerates the list of known high level profile values.
  154. \note Profiles are always sorted ascending by profile name.
  155. \param index index value, >=0
  156. \param id return buffer for ID value
  157. \return true if ID found at given index, false if not
  158. */
  159. static bool EnumProfile(unsigned index, Id &id);
  160. /**
  161. \brief Searches for the given high level profile.
  162. \note Actually the ID returned belongs to the first profile
  163. which has a name that is equal to or larger than the name
  164. searched for.
  165. \param name profile name to search for
  166. \param id return buffer for ID value
  167. \return true if ID found, false if not
  168. */
  169. static bool FindProfile(const char *name, Id &id);
  170. private:
  171. /** \internal
  172. Undocumented default constructor. Initializes high level profiler.
  173. We can make this private as well so nobody accidently tries to create
  174. another instance.
  175. */
  176. ProfileHighLevel(void);
  177. /**
  178. \brief The only high level profiler instance.
  179. */
  180. static ProfileHighLevel Instance;
  181. };
  182. #endif // PROFILE_HIGHLEVEL_H