enprofiler.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762
  1. /**
  2. * \defgroup Profiler Enforce Script profiling API
  3. * \warning Only available on developer and diag builds
  4. * @{
  5. */
  6. //! Flags that influences the behaviour of the EnProfiler API, applied through ...Flags functions
  7. enum EnProfilerFlags
  8. {
  9. //! No flags
  10. NONE,
  11. //! When present, will reset [PD] on sorting, otherwise will accumulate on top of it
  12. RESET,
  13. //! Whether to profile child modules
  14. RECURSIVE,
  15. //! All flags enabled
  16. ALL
  17. };
  18. //! Current base scripted modules
  19. enum EnProfilerModule
  20. {
  21. //! 1_Core
  22. CORE,
  23. //! 2_GameLib
  24. GAMELIB,
  25. //! 3_Game
  26. GAME,
  27. //! 4_World
  28. WORLD,
  29. //! 5_Mission
  30. MISSION,
  31. //! init.c
  32. MISSION_CUSTOM,
  33. //! Can be returned from some methods
  34. ERROR,
  35. };
  36. /**
  37. *\brief There are 3 states which can be toggled that governs whether script profiling is enabled or not
  38. * \note The reason for this is because when it is enabled in debug menu, or through this API without 'immediate', it will only be enabled the next frame
  39. */
  40. enum EnProfilerEnabledFlags
  41. {
  42. //! No flags, has value 0, so will count as false in conditions
  43. NONE,
  44. //! Script profiling UI is enabled in WIN+ALT debug menu, when this is true, it will override SCRP
  45. DIAG,
  46. //! It has been set to being always enabled through EnProfiler (SCRipt Profiler)
  47. SCRP,
  48. //! Whether profiling is currently truly happening (SCRipt Context)
  49. SCRC,
  50. };
  51. typedef Param2<float, typename> EnProfilerTimeClassPair;
  52. typedef Param2<int, typename> EnProfilerCountClassPair;
  53. typedef Param2<float, string> EnProfilerTimeFuncPair;
  54. typedef Param2<int, string> EnProfilerCountFuncPair;
  55. /**
  56. *\brief Set of methods for accessing script profiling data
  57. * \note To enable profiling on game launch, use parameter "-profile"
  58. * \note Any mention of "[DM]" in this context will mean the WIN+ALT debug menu
  59. * \note Any mention of "[CI]" in this context will mean Class Instances count
  60. * \note Any mention of "[SR]" in this context will mean a Session Reset (See ResetSession for more information)
  61. * \note Any mention of "[SD]" in this context will mean a Sorted Data, which is the data which supplies Get...Per... functions (the ones that give an array)
  62. * \note Any mention of "[PD]" in this context will mean a Profiling Data, which is the time, count and allocation information which is stored on the class/func itself
  63. * \warning [PD] is only calculated AFTER a function call is finished, there is no continuous timer running
  64. * \note 'proto' methods are not tracked, but will contribute to a script methods total time
  65. */
  66. class EnProfiler
  67. {
  68. /**
  69. \brief Enable the gathering of script profiling data
  70. \note DEFAULT: disabled (unless launched with "-profile", then it is default enabled)
  71. \note This is separate from the one in [DM], so toggling it in [DM] will not affect this, and toggling it here will not affect [DM]
  72. \note It will ignore the call if trying to set the current state, except when "immediate" is used
  73. \param enable \p bool Whether to enable or disable, if it was previously not enabled, it will cause [SR]
  74. \note Disabling does not cause [SR], so all data will stay intact
  75. \param immediate \p bool When true will instantly start/stop profiling, otherwise it will apply it at the end of the frame (to have one stable point in time)
  76. \warning Keep in mind that when using immediate, it will not be the data of the entire frame, which can skew data if not kept in mind
  77. \param sessionReset \p bool When set to false, no [SR] will trigger, regardless of situation
  78. @code
  79. // Simple enable, will start profiling the next frame
  80. // Will cause [SR] if !IsEnabledP() before this call
  81. EnProfiler.Enable(true);
  82. // Immediate enable, will start profiling immediately
  83. // Will cause [SR] if !IsEnabledP() before this call
  84. EnProfiler.Enable(true, true);
  85. // Immediate disable, will stop profiling immediately
  86. // Disabling will never cause [SR], preserving data
  87. EnProfiler.Enable(false, true);
  88. // Simple disable, will not profile the next frame (but still finish profiling the current one)
  89. // Disabling will never cause [SR], preserving data
  90. EnProfiler.Enable(false);
  91. @endcode
  92. */
  93. static proto void Enable(bool enable, bool immediate = false, bool sessionReset = true);
  94. /**
  95. \brief Return if script profiling is enabled
  96. \note Helper methods below
  97. \return \p int Flags regarding the current state
  98. @code
  99. int isScriptProfilingEnabled = EnProfiler.IsEnabled();
  100. @endcode
  101. */
  102. static proto int IsEnabled();
  103. /**
  104. \brief Return if script profiling is enabled through [DM]
  105. \return \p bool Whether script profiling is enabled through [DM]
  106. @code
  107. bool isScriptProfilingDiagEnabled = EnProfiler.IsEnabledD();
  108. @endcode
  109. */
  110. static bool IsEnabledD()
  111. {
  112. return (IsEnabled() & EnProfilerEnabledFlags.DIAG);
  113. }
  114. /**
  115. \brief Return if script profiling is enabled through EnProfiler
  116. \note When using "-profile" launch parameter, it will enable it through EnProfiler, so this will return true
  117. \return \p bool Whether script profiling is enabled through script profiler
  118. @code
  119. bool isScriptProfilingToggleEnabled = EnProfiler.IsEnabledP();
  120. @endcode
  121. */
  122. static bool IsEnabledP()
  123. {
  124. return (IsEnabled() & EnProfilerEnabledFlags.SCRP);
  125. }
  126. /**
  127. \brief Return if script profiling is actually turned on inside of the script context
  128. \note When using "-profile" launch parameter, it will enable it through EnProfiler, so this will return true
  129. \return \p bool Whether script is being profiled as of this moment
  130. @code
  131. bool isScriptProfilingEnabled = EnProfiler.IsEnabledC();
  132. @endcode
  133. */
  134. static bool IsEnabledC()
  135. {
  136. return (IsEnabled() & EnProfilerEnabledFlags.SCRC);
  137. }
  138. /**
  139. \brief The internal sorting that happens at the end of the frame (so it is NOT necessary to call this manually) to supply Get...Per... functions
  140. \note This will clear the previous [SD] and sort the [PD] currently available at this moment
  141. \note Flags apply to this
  142. \warning Keep in mind that EnProfilerFlags.RESET will clear all [PD] after this is called
  143. @code
  144. // Sorting all the currently available [PD], populating [SD]
  145. EnProfiler.SortData();
  146. // If flag EnProfilerFlags.RESET is enabled, then this will return 0 now even if it has been called, as [PD] has been cleared
  147. // This goes for any Get...Of... function (Except for [CI], the counter persists)
  148. EnProfiler.GetTimeOfFunc("Sleep", EnProfilerTests, true);
  149. @endcode
  150. */
  151. static proto void SortData();
  152. /**
  153. \brief Perform [SR], clearing SessionFrame, ProfiledSessionFrames, [SD] and [PD] (except for [CI])
  154. \note Can also be triggered by a variety of other functions in this API
  155. \note When triggered by the other functions, it will call with fullReset = false
  156. \param fullReset \p bool Whether to clear [PD] of all modules, when false it will only clear the [PD] according to current settings
  157. @code
  158. // Considering the settings: SetFlags(EnProfilerFlags.NONE) and SetModule(EnProfilerModule.GAME)
  159. // The following call will only clear [PD] of 3_Game
  160. EnProfiler.ResetSession();
  161. // Considering the settings: SetFlags(EnProfilerFlags.RECURSIVE) and SetModule(EnProfilerModule.WORLD)
  162. // The following call will clear [PD] of 3_Game, 4_World, 5_Mission and their children
  163. EnProfiler.ResetSession();
  164. // The following call resets [PD] across all modules
  165. EnProfiler.ResetSession(true);
  166. @endcode
  167. */
  168. static proto void ResetSession(bool fullReset = false);
  169. /** \name EnProfilerFlags
  170. Set of functions to configure the currently active EnProfilerFlags
  171. */
  172. //@{
  173. /**
  174. \brief Override the currently used set of EnProfilerFlags across the API
  175. \note DEFAULT: EnProfilerFlags.ALL
  176. \param flags \p int The combination of desired EnProfilerFlags to override the currently used set
  177. \param sessionReset \p bool When set to false, no [SR] will trigger, regardless of situation
  178. \return \p int The currently used set of EnProfilerFlags after the function call
  179. @code
  180. // No RESET flag, [PD] will be accumulated across frames
  181. // No RECURSIVE flag, only the curently profiled module will be sorted
  182. EnProfiler.SetFlags(EnProfilerFlags.NONE);
  183. // RESET flag, [PD] will be reset after sorting
  184. // No RECURSIVE flag, only the curently profiled module will be sorted
  185. EnProfiler.SetFlags(EnProfilerFlags.RESET);
  186. // RESET flag, [PD] will be reset after sorting
  187. // RECURSIVE flag, all modules will be sorted
  188. EnProfiler.SetFlags(EnProfilerFlags.ALL);
  189. @endcode
  190. */
  191. static proto int SetFlags(int flags, bool sessionReset = true);
  192. /**
  193. \brief Get the currently used flags across the API
  194. \return \p int The currently used set of EnProfilerFlags
  195. @code
  196. int flags = EnProfiler.GetFlags();
  197. if (flags & EnProfilerFlags.RECURSIVE)
  198. {
  199. Print("Currently profiling all modules.");
  200. }
  201. @endcode
  202. */
  203. static proto int GetFlags();
  204. /**
  205. \brief Check if the flags are set
  206. \note Is effectively the same as the code displayed in GetFlags example, but without the bitwise operation
  207. \param flags \p int The combination of EnProfilerFlags to check if present
  208. \return \p bool If the flags are set
  209. @code
  210. if (EnProfiler.IsFlagsSet(EnProfilerFlags.ALL))
  211. {
  212. Print("Currently all flags are enabled.");
  213. }
  214. if (EnProfiler.IsFlagsSet(EnProfilerFlags.RECURSIVE))
  215. {
  216. Print("Currently profiling all modules.");
  217. }
  218. @endcode
  219. */
  220. static proto bool IsFlagsSet(int flags);
  221. /**
  222. \brief Add flags to the currently used set of EnProfilerFlags across the API
  223. \note Simply a helper method to quickly add EnProfilerFlags
  224. \param flags \p int The combination of desired EnProfilerFlags to be added to the currently used set
  225. \param sessionReset \p bool When set to false, no [SR] will trigger, regardless of situation
  226. \return \p int The currently used set of EnProfilerFlags after the function call
  227. @code
  228. // In the case where the current set of EnProfilerFlags is EnProfilerFlags.RESET
  229. EnProfiler.AddFlags(EnProfilerFlags.RECURSIVE);
  230. // The resulting set of flags now will be EnProfilerFlags.RESET | EnProfilerFlags.RECURSIVE
  231. // As the above is pretty much the same as the following
  232. // EnProfiler.SetFlags(EnProfiler.GetFlags() | EnProfilerFlags.RECURSIVE);
  233. // But a much cleaner and faster alternative (bitwise operations in script is ~10x slower than C++)
  234. @endcode
  235. */
  236. static proto int AddFlags(int flags, bool sessionReset = true);
  237. /**
  238. \brief Remove flags from the currently used set of EnProfilerFlags across the API
  239. \note Simply a helper method to quickly remove EnProfilerFlags
  240. \param flags \p int The combination of desired EnProfilerFlags to be added to the currently used set
  241. \param sessionReset \p bool When set to false, no [SR] will trigger, regardless of situation
  242. \return \p int The currently used set of EnProfilerFlags after the function call
  243. @code
  244. // In the case where the current set of EnProfilerFlags is EnProfilerFlags.RESET
  245. EnProfiler.RemoveFlags(EnProfilerFlags.RESET);
  246. // The resulting set of flags now will be EnProfilerFlags.NONE
  247. // As the above is pretty much the same as the following
  248. // EnProfiler.SetFlags(EnProfiler.GetFlags() & ~EnProfilerFlags.RECURSIVE);
  249. // But a much cleaner and faster alternative (bitwise operations in script is ~10x slower than C++)
  250. @endcode
  251. */
  252. static proto int RemoveFlags(int flags, bool sessionReset = true);
  253. /**
  254. \brief Remove all flags from the currently used set of EnProfilerFlags across the API
  255. \note Simply a helper method to quickly remove all EnProfilerFlags
  256. \param sessionReset \p bool When set to false, no [SR] will trigger, regardless of situation
  257. \return \p int The currently used set of EnProfilerFlags after the function call
  258. @code
  259. // In the case where the current set of EnProfilerFlags is EnProfilerFlags.RESET
  260. EnProfiler.ClearFlags();
  261. // The resulting set of flags now will be EnProfilerFlags.NONE
  262. // As the above is pretty much the same as the following
  263. // EnProfiler.SetFlags(EnProfilerFlags.NONE);
  264. // But a much cleaner and implicit alternative
  265. @endcode
  266. */
  267. static proto int ClearFlags(bool sessionReset = true);
  268. //@}
  269. /** \name EnProfilerModule
  270. Set of functions to configure the currently profiled EnProfilerModule
  271. */
  272. //@{
  273. /**
  274. \brief Set the module to be profiled
  275. \note DEFAULT: EnProfilerModule.CORE
  276. \note When session reset is enabled, it will only reset the module which it is currently being set to, previous module data will be untouched
  277. \param module \p EnProfilerModule The module to profile
  278. \param sessionReset \p bool When set to false, no [SR] will trigger, regardless of situation
  279. @code
  280. EnProfiler.SetModule(EnProfilerModule.WORLD);
  281. @endcode
  282. */
  283. static proto void SetModule(EnProfilerModule module, bool sessionReset = true);
  284. /**
  285. \brief Get the currently profiled module
  286. \return \p EnProfilerModule The currently profiled module
  287. @code
  288. EnProfilerModule module = EnProfiler.GetModule();
  289. @endcode
  290. */
  291. static proto EnProfilerModule GetModule();
  292. /**
  293. \brief Helper to convert EnProfilerModule to string
  294. \param module \p EnProfilerModule The module to get the name of
  295. \return \p string The name of the module
  296. @code
  297. string moduleName = EnProfiler.ModuleToName(EnProfilerModule.GAME);
  298. @endcode
  299. */
  300. static proto owned string ModuleToName(EnProfilerModule module);
  301. /**
  302. \brief Convert string to EnProfilerModule
  303. \param moduleName \p string The name of the module
  304. \param module \p EnProfilerModule The enum value of the module or EnProfilerModule.ERROR if not found
  305. \return \p bool Whether the module was found
  306. @code
  307. // Get the name of the module of the current class
  308. string nameOfCurrentModule = Type().GetModule();
  309. EnProfilerModule module;
  310. // Convert it to the enum value
  311. if (EnProfiler.NameToModule(nameOfCurrentModule, module))
  312. {
  313. EnProfiler.SetModule(module);
  314. }
  315. else
  316. {
  317. ErrorEx(string.Format("Could not find EnProfilerModule: %1", nameOfCurrentModule));
  318. }
  319. @endcode
  320. */
  321. static proto bool NameToModule(string moduleName, out EnProfilerModule module);
  322. //@}
  323. /**
  324. \brief Set the interval for the [SD] to update
  325. \note DEFAULT: 0
  326. \note [DM] has the following values: {0, 5, 10, 20, 30, 50, 60, 120, 144}; When an interval not part of this list is set, [DM] will be set to "CUSTOM_INTERVAL"
  327. \note Does not affect the gathering of [PD], this will happen continuously as the profiling is enabled
  328. \note This also delays the [SR] caused by EnProfilerFlags.RESET
  329. \param interval \p int Amount of frames to wait before [SD] is updated
  330. \param sessionReset \p bool When set to false, no [SR] will trigger, regardless of situation
  331. @code
  332. // This will make it so that [SD] is updated every 60 frames
  333. EnProfiler.SetInterval(60);
  334. @endcode
  335. */
  336. static proto void SetInterval(int interval, bool sessionReset = true);
  337. /**
  338. \brief Get the currently set interval
  339. \return \p int The currently set interval
  340. @code
  341. int currentInterval = EnProfiler.GetInterval();
  342. @endcode
  343. */
  344. static proto int GetInterval();
  345. /**
  346. \brief Set the resolution of the fetched Time data
  347. \note DEFAULT: 100000
  348. \note [DM] has the following values: {100000, 1000000, 1, 10, 100, 1000, 10000}; These are the only values available, otherwise it will round up to one in the list
  349. \note Does not affect any data itself, only the fetching and displaying of it (therefore, no [SR] is ever triggered by this method)
  350. \param resolution \p int The nth resolution of a second
  351. @code
  352. // Have all time being reported in 1 second
  353. EnProfiler.SetTimeResolution(1);
  354. // Have all time being reported in 1000th of a second (ms)
  355. EnProfiler.SetTimeResolution(1000);
  356. @endcode
  357. */
  358. static proto void SetTimeResolution(int resolution);
  359. /**
  360. \brief Get the currently set time resolution
  361. \return \p int The currently set resolution
  362. @code
  363. int currentTimeResolution = EnProfiler.GetTimeResolution();
  364. @endcode
  365. */
  366. static proto int GetTimeResolution();
  367. /**
  368. \brief Enable/disable returning calculated averages
  369. \note DEFAULT: false
  370. \note When EnProfilerFlags.RESET flag is not present, it will divide by the session frame
  371. \note When an interval is set, it will divide by the interval
  372. \note Does not affect any data itself, only the fetching and displaying of it (therefore, no [SR] is ever triggered by this method)
  373. \note [CI] will never be an average, it will always be the current count of the instance (allocations will be the value of how many times an instance is created)
  374. \param enable \p bool Whether to enable or disable
  375. @code
  376. // For example, take the situation where we only reset every 60 frames
  377. EnProfiler.AddFlags(EnProfilerFlags.RESET);
  378. EnProfiler.SetInterval(60);
  379. EnProfiler.EnableAverage(true);
  380. // And a method is called once per frame, gathering the count of that function will be 1
  381. // Or if a method is called twice per frame, gathering the count of that function will be 2
  382. // Or if a method is 3 times every 3 frames, gathering the count of that function will be 1
  383. // ...
  384. // So you get the average amount of times the method is called per frame, out of the sample of 60 frames
  385. @endcode
  386. */
  387. static proto void EnableAverage(bool enable);
  388. /**
  389. \brief Check if returning of average data is enabled
  390. \return \p bool Whether returning of average data is enabled
  391. @code
  392. bool isDataAverage = EnProfiler.IsAverage();
  393. @endcode
  394. */
  395. static proto bool IsAverage();
  396. /**
  397. \brief Print out [SD] to script log
  398. @code
  399. EnProfiler.Dump();
  400. @endcode
  401. */
  402. static proto void Dump();
  403. /** \name Frame data
  404. Set of functions to obtain information about frame counts
  405. */
  406. //@{
  407. /**
  408. \brief Get the total amount of frames passed
  409. \return \p int The total amount of frames passed
  410. @code
  411. int gameFrame = EnProfiler.GetGameFrame();
  412. @endcode
  413. */
  414. static proto int GetGameFrame();
  415. /**
  416. \brief Get the total amount of frames in this profiling session
  417. \note This will only differ from GetProfiledSessionFrames when there is an Interval set
  418. \return \p int The total amount of frames in this profiling session
  419. @code
  420. int sessionFrame = EnProfiler.GetSessionFrame();
  421. @endcode
  422. */
  423. static proto int GetSessionFrame();
  424. /**
  425. \brief Get the total amount of frames across all profiling session
  426. \note This will only differ from GetProfiledFrames when there was an Interval set at some point
  427. \return \p int The total amount of frames across all profiling session
  428. @code
  429. int totalFrames = EnProfiler.GetTotalFrames();
  430. @endcode
  431. */
  432. static proto int GetTotalFrames();
  433. /**
  434. \brief Get the total amount of frames profiled in this profiling session
  435. \note This will only differ from GetSessionFrame when there is an Interval set
  436. \return \p int The total amount of frames profiled in this profiling session
  437. @code
  438. int profiledSessionFrames = EnProfiler.GetProfiledSessionFrames();
  439. @endcode
  440. */
  441. static proto int GetProfiledSessionFrames();
  442. /**
  443. \brief Get the total amount of frames profiled across all profiling session
  444. \note This will only differ from GetTotalFrames when there was an Interval set at some point
  445. \return \p int The total amount of frames profiled across all profiling session
  446. @code
  447. int totalProfiledFrames = EnProfiler.GetProfiledFrames();
  448. @endcode
  449. */
  450. static proto int GetProfiledFrames();
  451. //@}
  452. /** \name Sorted data
  453. Set of functions to obtain [SD]
  454. \warning Data is appended to the array, it will not clear any previous data already existing in the array
  455. \note Read SortData as well for more information regarding [SD]
  456. */
  457. //@{
  458. /**
  459. \brief Obtain [SD] for Time Per Class
  460. \param outArr \p array<ref EnProfilerTimeClassPair> Array sorted by time consumed by a class
  461. \param count \p int The maximum amount of entries wanted
  462. @code
  463. // In this example the array will be filled with the 20 most time intensive classes
  464. // If there are less than 20 classes which consumed time, it will output that number of classes instead
  465. array<ref EnProfilerTimeClassPair> timePerClass = {};
  466. EnProfiler.GetTimePerClass(timePerClass, 20);
  467. // In this example the array will be filled with all classes sorted by time
  468. array<ref EnProfilerTimeClassPair> timePerClass2 = {};
  469. EnProfiler.GetTimePerClass(timePerClass2);
  470. @endcode
  471. */
  472. static proto void GetTimePerClass(notnull out array<ref EnProfilerTimeClassPair> outArr, int count = int.MAX);
  473. /**
  474. \brief Obtain [SD] for Allocations Per Class
  475. \param outArr \p array<ref EnProfilerCountClassPair> Array sorted by number of allocations of a class
  476. \param count \p int The maximum amount of entries wanted
  477. @code
  478. array<ref EnProfilerCountClassPair> allocPerClass = {};
  479. EnProfiler.GetAllocationsPerClass(allocPerClass, 20);
  480. @endcode
  481. */
  482. static proto void GetAllocationsPerClass(notnull out array<ref EnProfilerCountClassPair> outArr, int count = int.MAX);
  483. /**
  484. \brief Obtain [SD] for Instances Per Class
  485. \param outArr \p array<ref EnProfilerCountClassPair> Array sorted by number of instances of a class
  486. \param count \p int The maximum amount of entries wanted
  487. @code
  488. array<ref EnProfilerCountClassPair> instancesPerClass = {};
  489. EnProfiler.GetInstancesPerClass(instancesPerClass, 20);
  490. @endcode
  491. */
  492. static proto void GetInstancesPerClass(notnull out array<ref EnProfilerCountClassPair> outArr, int count = int.MAX);
  493. /**
  494. \brief Obtain [SD] for Time Per Function
  495. \param outArr \p array<ref EnProfilerTimeFuncPair> Array sorted by time consumed by a function
  496. \param count \p int The maximum amount of entries wanted
  497. @code
  498. array<ref EnProfilerTimeFuncPair> timePerFunc = {};
  499. EnProfiler.GetTimePerFunc(timePerFunc, 20);
  500. @endcode
  501. */
  502. static proto void GetTimePerFunc(notnull out array<ref EnProfilerTimeFuncPair> outArr, int count = int.MAX);
  503. /**
  504. \brief Obtain [SD] for Count Per Function
  505. \param outArr \p array<ref EnProfilerCountFuncPair> Array sorted by amount of times a function was called
  506. \param count \p int The maximum amount of entries wanted
  507. @code
  508. array<ref EnProfilerCountFuncPair> countPerFunc = {};
  509. EnProfiler.GetCountPerFunc(countPerFunc, 20);
  510. @endcode
  511. */
  512. static proto void GetCountPerFunc(notnull out array<ref EnProfilerCountFuncPair> outArr, int count = int.MAX);
  513. //@}
  514. /** \name Specific data
  515. Set of functions to obtain specific data
  516. */
  517. //@{
  518. /**
  519. \brief Obtain [SD] or [PD] regarding the time a specific class consumed
  520. \param clss \p typename Typename of desired class
  521. \param immediate \p bool When true, it will pull from [SD], when false it will pull from [PD]
  522. \return \p float Time consumed by the specified class
  523. @code
  524. // Consider the class
  525. EPTHelperClass clss = new EPTHelperClass();
  526. // Some functions being called here...
  527. // Gathering of data can be done through
  528. float timeOfClass = EnProfiler.GetTimeOfClass(clss.Type(), true);
  529. // Or when you have no variable/reference
  530. float timeOfClass2 = EnProfiler.GetTimeOfClass(StaticGetType(EPTHelperClass), true);
  531. @endcode
  532. */
  533. static proto float GetTimeOfClass(typename clss, bool immediate = false);
  534. /**
  535. \brief Obtain [SD] or [PD] regarding the allocations of a specific class
  536. \param clss \p typename Typename of desired class
  537. \param immediate \p bool When true, it will pull from [SD], when false it will pull from [PD]
  538. \return \p int Allocations of the specified class
  539. @code
  540. int allocationsOfClass = EnProfiler.GetAllocationsOfClass(StaticGetType(EPTHelperClass), true);
  541. @endcode
  542. */
  543. static proto int GetAllocationsOfClass(typename clss, bool immediate = false);
  544. /**
  545. \brief Obtain [SD] or [PD] regarding the [CI] of a specific class
  546. \param clss \p typename Typename of desired class
  547. \param immediate \p bool When true, it will pull from [SD], when false it will pull from [PD]
  548. \return \p int [CI] of the specified class
  549. @code
  550. int instancesOfClass = EnProfiler.GetInstancesOfClass(StaticGetType(EPTHelperClass), true);
  551. @endcode
  552. */
  553. static proto int GetInstancesOfClass(typename clss, bool immediate = false);
  554. /**
  555. \brief Obtain [SD] or [PD] regarding the time consumed by a specific function
  556. \param funct \p string Function name
  557. \param clss \p typename Typename of class the function belongs to
  558. \param immediate \p bool When true, it will pull from [SD], when false it will pull from [PD]
  559. \return \p float Time consumed by the specified function or -1 when function was not found
  560. @code
  561. float timeOfFunc = EnProfiler.GetTimeOfFunc("StringFormat", StaticGetType(EnProfilerTests), true);
  562. @endcode
  563. */
  564. static proto float GetTimeOfFunc(string funct, typename clss, bool immediate = false);
  565. /**
  566. \brief Obtain [SD] or [PD] regarding the time consumed by a specific global function
  567. \param funct \p string Function name
  568. \param immediate \p bool When true, it will pull from [SD], when false it will pull from [PD]
  569. \return \p float Time consumed by the specified function or -1 when function was not found
  570. @code
  571. float timeOfFunc = EnProfiler.GetTimeOfFuncG("ErrorEx", true);
  572. @endcode
  573. */
  574. static proto float GetTimeOfFuncG(string funct, bool immediate, bool immediate = false);
  575. /**
  576. \brief Obtain [SD] or [PD] regarding the amount of times a specific function was called
  577. \param funct \p string Function name
  578. \param clss \p typename Typename of class the function belongs to
  579. \param immediate \p bool When true, it will pull from [SD], when false it will pull from [PD]
  580. \return \p int Amount of calls to the specified function or -1 when function was not found
  581. @code
  582. int callCountOfFunc = EnProfiler.GetCountOfFunc("StringFormat", StaticGetType(EnProfilerTests), true);
  583. @endcode
  584. */
  585. static proto int GetCountOfFunc(string funct, typename clss, bool immediate = false);
  586. /**
  587. \brief Obtain [SD] or [PD] regarding the amount of times a specific function was called
  588. \param funct \p string Function name
  589. \param immediate \p bool When true, it will pull from [SD], when false it will pull from [PD]
  590. \return \p int Amount of calls to the specified function or -1 when function was not found
  591. @code
  592. int callCountOfFunc = EnProfiler.GetCountOfFuncG("ErrorEx", true);
  593. @endcode
  594. */
  595. static proto int GetCountOfFuncG(string funct, bool immediate = false);
  596. //@}
  597. /** \name Misc
  598. Set of helper functions
  599. */
  600. //@{
  601. /**
  602. \brief Helper method to ascertain the profiler will record [PD] right after this call
  603. \return \p bool Whether it was enabled before or not
  604. @code
  605. bool wasEnabled = EnProfiler.RequestImmediateData();
  606. @endcode
  607. */
  608. static bool RequestImmediateData()
  609. {
  610. // I only care if it is actually profiling right now, so C
  611. bool wasEnabled = IsEnabledC();
  612. if (!wasEnabled)
  613. {
  614. // I want the data, and I want it now, so immediate
  615. Enable(true, true);
  616. }
  617. return wasEnabled;
  618. }
  619. //@}
  620. };
  621. //@}