cputicker.h

Go to the documentation of this file.
00001 // TITLE:
00002 // High-Resolution Counter Class.
00003 //
00004 // VERSION:
00005 // 1.24
00006 //
00007 // AUTHORS:
00008 // Created by J.M.McGuiness, http://www.hussar.demon.co.uk
00009 //            PJ Naughter,   Email: pjn@indigo.ie Web: http://indigo.ie/~pjn
00010 //
00011 // DESCRIPTION:
00012 // This file declares a class the wraps the Pentium-specific time stamp counter.
00013 // This counter has a resolution in terms of PCLKS (processor clocks) so it can
00014 // be used for direct instruction timings.
00015 //
00016 // LEGALITIES:
00017 // Copyright © 1996-2001 by J.M.McGuiness and PJ Naughter, all rights reserved.
00018 //
00019 // This file must not be distributed without the authors prior
00020 // consent.
00021 //
00023 
00024 
00026 
00027 #ifndef __CPUTICKER_H__
00028 #define __CPUTICKER_H__
00029 
00030 
00031 
00032 
00033 
00035 class CCPUTicker : public CObject
00036 {
00037 public:
00038         void FindOverHead();
00039         unsigned OverHead;
00040         unsigned FindBase();
00041         double GetFreq();
00042 //constructors / Destructors
00043         CCPUTicker();
00044         CCPUTicker(const CCPUTicker& ticker);
00045 
00046 //copy constructor
00047         inline CCPUTicker& operator=(const CCPUTicker& ticker);
00048 
00049 //perform the actual measurement
00050   __int64 Measure();
00051 
00052 //accessors to the actual measurement value
00053   double GetTickCountAsSeconds() const;  
00054   inline __int64 GetTickCount() const { return m_TickCount; };  
00055 
00056 //static methods
00057         static BOOL GetCPUFrequency(double& frequency, double& target_ave_dev, 
00058                               unsigned long interval = 1000,
00059                               unsigned int max_loops = 20);
00060   static BOOL GetCachedCPUFrequency(double& frequency, double& target_ave_dev);
00061 
00062 //Is high resolution available on this CPU
00063         BOOL IsAvailable() const;
00064 
00065 //Standard MFC diagnostics
00066 #ifdef _DEBUG
00067         virtual void AssertValid() const;
00068         virtual void Dump(CDumpContext& dc) const;
00069 #endif
00070 
00071 protected:
00072   __int64 m_TickCount;
00073 
00074         static BOOL m_bHasRDTSC;
00075   static BOOL m_bRunningOnNT;
00076   static BOOL m_bStaticsCalculated;
00077 
00078   static double m_deviation;
00079   static double m_freq;
00080   static BOOL m_bFrequencyCalculated;
00081 
00082   static BOOL CheckHasRDTSC();
00083   static BOOL RunningOnNT();
00084 
00085         DECLARE_DYNAMIC(CCPUTicker)
00086 };
00087 
00088 
00089 #endif //__CPUTICKER_H__

Generated on Sun Dec 17 14:54:15 2006 for Kryptos by  doxygen 1.5.1-p1