home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / Found / FWDebug / FWPrfCnt.cpp < prev    next >
Encoding:
Text File  |  1996-09-17  |  3.1 KB  |  116 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWPrfCnt.cpp
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWFound.hpp"
  11.  
  12. #ifndef FWSTDDEF_H
  13. #include "FWStdDef.h"
  14. #endif
  15.  
  16. #ifdef FW_PROFILE
  17.  
  18. #ifndef FWPRFCNT_H
  19. #include "FWPrfCnt.h"
  20. #endif
  21.  
  22. #include <string.h>
  23.  
  24. #pragma segment FWDebug_PerformanceCounter
  25.  
  26.  
  27. //========================================================================================
  28. // CLASS FW_CPrivPerformanceCounter
  29. //========================================================================================
  30.  
  31. #ifdef FW_BUILD_WIN
  32. DWORD FW_CPrivPerformanceCounter::gWinOverhead = (DWORD) -1;
  33. DWORD FW_CPrivPerformanceCounter::gWinFreq = 0;
  34. #endif
  35.  
  36. #ifdef FW_BUILD_MAC
  37. const long kMacMaxInterval    = -60l * 1000l * 1000l;    // microseconds: 1 minute
  38.  
  39. long FW_CPrivPerformanceCounter::gMacTMOverhead = -1;
  40. #endif
  41.  
  42. //----------------------------------------------------------------------------------------
  43. // FW_CPrivPerformanceCounter::FW_CPrivPerformanceCounter
  44. //----------------------------------------------------------------------------------------
  45.  
  46. FW_CPrivPerformanceCounter::FW_CPrivPerformanceCounter() :
  47.     fResult(-1)
  48. {
  49. #ifdef FW_BUILD_WIN
  50.     ::QueryPerformanceCounter(&fWinBegin);
  51.     
  52.     // Determine the overhead
  53.     if (gWinOverhead == (DWORD) -1)
  54.     {
  55.         ::QueryPerformanceCounter(&fWinEnd);
  56.         gWinOverhead = fWinEnd.LowPart - fWinBegin.LowPart;
  57.         
  58.         // Get the resolution
  59.         LARGE_INTEGER liFreq;
  60.         ::QueryPerformanceFrequency(&liFreq);
  61.         gWinFreq = liFreq.LowPart;
  62.  
  63.         ::QueryPerformanceCounter(&fWinBegin);
  64.     }
  65. #endif
  66. #ifdef FW_BUILD_MAC
  67.     ::memset(&fMacTMTask, 0, sizeof(fMacTMTask));
  68.     ::InsTime((QElemPtr) &fMacTMTask);
  69.     ::PrimeTime((QElemPtr) &fMacTMTask, kMacMaxInterval);
  70.     
  71.     // Determine the overhead
  72.     if (gMacTMOverhead == -1)
  73.     {
  74.         ::RmvTime((QElemPtr) &fMacTMTask);
  75.         gMacTMOverhead = fMacTMTask.tmCount - kMacMaxInterval;
  76.  
  77.         ::InsTime((QElemPtr) &fMacTMTask);
  78.         ::PrimeTime((QElemPtr) &fMacTMTask, kMacMaxInterval);
  79.     }
  80.  
  81.     fMacIsInQueue = TRUE;
  82. #endif
  83. }
  84.  
  85. //----------------------------------------------------------------------------------------
  86. // FW_CPrivPerformanceCounter::~FW_CPrivPerformanceCounter
  87. //----------------------------------------------------------------------------------------
  88.  
  89. FW_CPrivPerformanceCounter::~FW_CPrivPerformanceCounter()
  90. {
  91. #ifdef FW_BUILD_MAC
  92.     if (fMacIsInQueue)
  93.         ::RmvTime((QElemPtr) &fMacTMTask);
  94. #endif
  95. }
  96.  
  97. //----------------------------------------------------------------------------------------
  98. // FW_CPrivPerformanceCounter::EndCheckPoint
  99. //----------------------------------------------------------------------------------------
  100.  
  101. void FW_CPrivPerformanceCounter::EndCheckPoint()
  102. {
  103. #ifdef FW_BUILD_WIN
  104.     ::QueryPerformanceCounter(&fWinEnd);
  105.     fResult = fWinEnd.LowPart - fWinBegin.LowPart - gWinOverhead;
  106. #endif
  107. #ifdef FW_BUILD_MAC
  108.     FW_ASSERT(fMacIsInQueue);
  109.     ::RmvTime((QElemPtr) &fMacTMTask);
  110.     fMacIsInQueue = FALSE;
  111.     fResult = fMacTMTask.tmCount - kMacMaxInterval - gMacTMOverhead;
  112. #endif
  113. }
  114.  
  115. #endif
  116.