perfTimer.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. //*@@@+++@@@@******************************************************************
  2. //
  3. // Copyright © Microsoft Corp.
  4. // All rights reserved.
  5. //
  6. // Redistribution and use in source and binary forms, with or without
  7. // modification, are permitted provided that the following conditions are met:
  8. //
  9. // • Redistributions of source code must retain the above copyright notice,
  10. // this list of conditions and the following disclaimer.
  11. // • Redistributions in binary form must reproduce the above copyright notice,
  12. // this list of conditions and the following disclaimer in the documentation
  13. // and/or other materials provided with the distribution.
  14. //
  15. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  16. // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17. // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  18. // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
  19. // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  20. // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  21. // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  22. // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  23. // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  24. // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  25. // POSSIBILITY OF SUCH DAMAGE.
  26. //
  27. //*@@@---@@@@******************************************************************
  28. #ifndef __PERFTIMER_H_
  29. #define __PERFTIMER_H_
  30. //***************************************************************************
  31. // Description
  32. //
  33. // Performance timer API used to measure codec performance. The underlying
  34. // implementation of this API may vary - from ANSI-C implementation via clock,
  35. // Win32 implementation via QueryPerformanceCounter or GetProcessTimes. At
  36. // present we only support one implementation of this PerfTimer "object".
  37. // You choose the implementation by choosing which one of the many files
  38. // to compile and link with your application.
  39. //***************************************************************************
  40. #ifdef DISABLE_PERF_MEASUREMENT
  41. #define PERFTIMER_ONLY(code)
  42. #define PERFTIMER_NEW(fPerf, ppPerfTimer)
  43. #define PERFTIMER_DELETE(fPerf, ppPerfTimer)
  44. #define PERFTIMER_START(fPerf, pPerfTimer)
  45. #define PERFTIMER_STOP(fPerf, pPerfTimer)
  46. #define PERFTIMER_GETRESULTS(fPerf, pPerfTimer, pResults)
  47. #define PERFTIMER_COPYSTARTTIME(fPerf, pDst, pSrc)
  48. #define PERFTIMER_REPORT(fPerf, pCodec)
  49. #else // DISABLE_PERF_MEASUREMENT
  50. #define PERFTIMER_ONLY(code) code
  51. #define PERFTIMER_NEW(fPerf, ppPerfTimer) if (fPerf) {Bool b = b = PerfTimerNew(ppPerfTimer); assert(b);};
  52. #define PERFTIMER_DELETE(fPerf, pPerfTimer) if (fPerf) {PerfTimerDelete(pPerfTimer);};
  53. #define PERFTIMER_START(fPerf, pPerfTimer) if (fPerf) {Bool b = b = PerfTimerStart(pPerfTimer); assert(b);};
  54. #define PERFTIMER_STOP(fPerf, pPerfTimer) if (fPerf) {Bool b = b = PerfTimerStop(pPerfTimer); assert(b);};
  55. #define PERFTIMER_GETRESULTS(fPerf, pPerfTimer, pResults) \
  56. if (fPerf) {Bool b = b = PerfTimerGetResults((pPerfTimer), (pResults)); assert(b);};
  57. #define PERFTIMER_COPYSTARTTIME(fPerf, pDst, pSrc) \
  58. if (fPerf) {Bool b = b = PerfTimerCopyStartTime((pDst), (pSrc)); assert(b);};
  59. #define PERFTIMER_REPORT(fPerf, pCodec) \
  60. if (fPerf) {OutputPerfTimerReport(pCodec);};
  61. #endif // DISABLE_PERF_MEASUREMENT
  62. //***************************************************************************
  63. // Data Types
  64. //***************************************************************************
  65. typedef U64 PERFTIMERTIME;
  66. typedef struct PERFTIMERRESULTS
  67. {
  68. PERFTIMERTIME iElapsedTime; // In nanoseconds or CPU cycles
  69. PERFTIMERTIME iTicksPerSecond; // Number of ticks per second (clock frequency)
  70. PERFTIMERTIME iZeroTimeIntervals; // Number of zero-time intervals.
  71. // Presence of zero-time intervals may indicate insufficient clock precision
  72. } PERFTIMERRESULTS;
  73. #define NANOSECONDS_PER_SECOND 1000000000
  74. //***************************************************************************
  75. // Data Declarations
  76. //***************************************************************************
  77. typedef enum
  78. {
  79. CS_UNINIT,
  80. CS_RUNNING,
  81. CS_STOPPED,
  82. } CLOCKSTATE;
  83. typedef struct PERFTIMERSTATE
  84. {
  85. CLOCKSTATE eState;
  86. PERFTIMERTIME iElapsedTime;
  87. PERFTIMERTIME iPrevStartTime;
  88. PERFTIMERTIME iZeroTimeIntervals;
  89. } PERFTIMERSTATE;
  90. //***************************************************************************
  91. // Functions and Macros
  92. //***************************************************************************
  93. Bool PerfTimerNew(PERFTIMERSTATE **ppNewPerfTimer);
  94. void PerfTimerDelete(PERFTIMERSTATE *pThisPerfTimer);
  95. Bool PerfTimerStart(PERFTIMERSTATE *pThisPerfTimer);
  96. Bool PerfTimerStop(PERFTIMERSTATE *pThisPerfTimer);
  97. Bool PerfTimerGetResults(PERFTIMERSTATE *pThisPerfTimer,
  98. PERFTIMERRESULTS *pPerfTimerResults);
  99. Bool PerfTimerCopyStartTime(PERFTIMERSTATE *pDestPerfTimer,
  100. PERFTIMERSTATE *pSrcPerfTimer);
  101. #endif // __PERFTIMER_H_