PerfTimer.bf 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Runtime.InteropServices;
  4. using System.Text;
  5. namespace Beefy.utils
  6. {
  7. public abstract class PerfTimer
  8. {
  9. [StdCall, CLink]
  10. extern static void PerfTimer_ZoneStart(char8* name);
  11. [StdCall, CLink]
  12. extern static void PerfTimer_ZoneEnd();
  13. [StdCall, CLink]
  14. extern static void PerfTimer_Message(char8* theString);
  15. [StdCall, CLink]
  16. extern static int32 PerfTimer_IsRecording();
  17. [StdCall, CLink]
  18. extern static void PerfTimer_StartRecording();
  19. [StdCall, CLink]
  20. extern static void PerfTimer_StopRecording();
  21. [StdCall, CLink]
  22. extern static void PerfTimer_DbgPrint();
  23. static DisposeProxy mZoneEndDisposeProxy ~ delete _;
  24. public static DisposeProxy ZoneStart(String name)
  25. {
  26. if (mZoneEndDisposeProxy == null)
  27. mZoneEndDisposeProxy = new DisposeProxy(new => ZoneEnd);
  28. PerfTimer_ZoneStart(name);
  29. return mZoneEndDisposeProxy;
  30. }
  31. public static void ZoneEnd()
  32. {
  33. PerfTimer_ZoneEnd();
  34. }
  35. public static void Message(String theString)
  36. {
  37. PerfTimer_Message(theString);
  38. }
  39. public static void Message(String format, params Object[] theParams)
  40. {
  41. String outStr = scope String();
  42. outStr.AppendF(format, params theParams);
  43. Message(outStr);
  44. }
  45. public static bool IsRecording()
  46. {
  47. return PerfTimer_IsRecording() != 0;
  48. }
  49. public static void StartRecording()
  50. {
  51. PerfTimer_StartRecording();
  52. }
  53. public static void StopRecording()
  54. {
  55. PerfTimer_StopRecording();
  56. }
  57. public static void DbgPrint()
  58. {
  59. PerfTimer_DbgPrint();
  60. }
  61. }
  62. }