Click here to Skip to main content
15,902,299 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionHow to get IE version Pin
rrrado5-Nov-06 22:36
rrrado5-Nov-06 22:36 
AnswerRe: How to get IE version Pin
Nibu babu thomas5-Nov-06 23:41
Nibu babu thomas5-Nov-06 23:41 
GeneralRe: How to get IE version Pin
rrrado6-Nov-06 1:25
rrrado6-Nov-06 1:25 
QuestionRe: How to get IE version Pin
David Crow6-Nov-06 4:23
David Crow6-Nov-06 4:23 
AnswerRe: How to get IE version Pin
rrrado6-Nov-06 6:07
rrrado6-Nov-06 6:07 
QuestionRelease version with shared Dll not running Pin
NorGUI5-Nov-06 22:21
NorGUI5-Nov-06 22:21 
AnswerRe: Release version with shared Dll not running Pin
Cedric Moonen5-Nov-06 22:35
Cedric Moonen5-Nov-06 22:35 
Questionhow to use CPerftimer class in Dialog-based MFC application Pin
daemone5-Nov-06 22:08
daemone5-Nov-06 22:08 
I want to use this timer class for precise data sampling and display the sampled data in strip chart of a dialog time by time
such as 10us a data will be display on strip chart.
below is the class code written by Dean Wyant

// CPerfTimer - a simple Win32 performance counter wrapper<br />
// by Dean Wyant dwyant@mindspring.com<br />
<br />
<br />
//PerfTimer.cpp<br />
<br />
// Declare and initialize static member vars that get set only once and never change<br />
__int64 CPerfTimer::m_Freq = 100000; <br />
__int64 CPerfTimer::m_Adjust = 0; <br />
<br />
// All functions defined inline for speed. After all, the performance counter is <br />
// supposed to be able to time very short events fairly accurately.<br />
<br />
<br />
<br />
BOOL CPerfTimer::IsSupported()<br />
{ // Returns FALSE if performance counter not supported.<br />
  // Call after constructing at least one CPerfTimer<br />
  return (m_Freq > 1);<br />
}<br />
<br />
const double CPerfTimer::Resolution()   <br />
{ // Returns timer resolution in seconds<br />
  return 1.0/(double)m_Freq; <br />
}<br />
<br />
const double CPerfTimer::Resolutionms() <br />
{ // Returns timer resolution in milliseconds<br />
  return 1000.0/(double)m_Freq; <br />
}<br />
<br />
const double CPerfTimer::Resolutionus() <br />
{ // Returns timer resolution in microseconds<br />
  return 1000000.0/(double)m_Freq; <br />
}


// CPerfTimer - a simple Win32 performance counter wrapper
// by Dean Wyant dwyant@mindspring.com

/*

This class is simple to use. Just declare a variable(s) as type CPerfTimer,
call Start() to start timimg and call Stop() to stop timimg. You can pause a
timer by calling Stop() and then you can call Start() to resume. Retrieve the
elapsed time by calling an Elapsed..() function. Assignment, addition,
subtraction and comparison are supported. There are a few information calls
available also. All calls except Start and Stop can be performed on a timer
without stopping it.

*/

#ifndef __PERFTIMER_H__<br />
#define __PERFTIMER_H__<br />
<br />
class CPerfTimer<br />
{<br />
public:<br />
  CPerfTimer(BOOL bStart = FALSE) {Init(bStart);}<br />
<br />
  CPerfTimer(const CPerfTimer& Src); <br />
<br />
  virtual ~CPerfTimer() {;}<br />
<br />
  void Start(BOOL bReset = FALSE);   // Start from current value or optionally from 0<br />
  void Stop();                       // Stop timing. Use Start afterwards to continue.<br />
 <br />
  BOOL IsRunning();                  // Returns FALSE if stopped.<br />
  <br />
  BOOL IsSupported();                // Returns FALSE if performance counter not supported.<br />
                                     // Call after constructing at least one CPerfTimer<br />
<br />
  const double Resolution();         // Returns timer resolution in seconds<br />
  const double Resolutionms();       // Returns timer resolution in milliseconds<br />
  const double Resolutionus();       // Returns timer resolution in microseconds<br />
  <br />
  const double Elapsed();            // Returns elapsed time in seconds<br />
  const double Elapsedms();          // Returns elapsed time in milliseconds <br />
  const double Elapsedus();          // Returns elapsed time in microseconds<br />
<br />
  const CPerfTimer& operator=(const CPerfTimer& Src); // Assignment operator <br />
<br />
  // Math operators<br />
  CPerfTimer operator+(const CPerfTimer& Src) const;<br />
	CPerfTimer operator-(const CPerfTimer& Src) const;<br />
	const CPerfTimer& operator+=(const CPerfTimer& Src);<br />
	const CPerfTimer& operator-=(const CPerfTimer& Src);<br />
  // For time in seconds<br />
  CPerfTimer operator+(const double Secs) const;<br />
	CPerfTimer operator-(const double Secs) const;<br />
	const CPerfTimer& operator+=(const double Secs);<br />
	const CPerfTimer& operator-=(const double Secs);<br />
<br />
  // Boolean comparison operators<br />
	BOOL operator<(const CPerfTimer& Src);<br />
	BOOL operator>(const CPerfTimer& Src);<br />
	BOOL operator<=(const CPerfTimer& Src);<br />
	BOOL operator>=(const CPerfTimer& Src);<br />
  // For time in seconds<br />
  BOOL operator<(const double Secs);<br />
	BOOL operator>(const double Secs);<br />
	BOOL operator<=(const double Secs);<br />
	BOOL operator>=(const double Secs);<br />
<br />
  virtual void Lock() const {;}     // Override for thread safe operation<br />
  virtual void Unlock() const {;}     // Override for thread safe operation<br />
protected:<br />
  void Init(BOOL bStart);<br />
  void Copy(const CPerfTimer& Src);<br />
<br />
private:<br />
  __int64 m_Start;<br />
  static __int64 m_Freq;   // does not change while system is running<br />
  static __int64 m_Adjust; // Adjustment time it takes to Start and Stop<br />
};<br />
<br />
class CPerfTimerT : public CPerfTimer<br />
{ // You only need to use types of this class if a timer is going to be shared between threads<br />
public:<br />
  CPerfTimerT(BOOL bStart = FALSE)<br />
  {<br />
    m_hMutex = CreateMutex(NULL,FALSE,"");<br />
    Init(bStart);<br />
  }<br />
<br />
  CPerfTimerT(const CPerfTimerT& Src) <br />
  { <br />
    m_hMutex = CreateMutex(NULL,FALSE,"");<br />
    Copy(Src); <br />
  }<br />
<br />
  CPerfTimerT(const CPerfTimer& Src) <br />
  { <br />
    m_hMutex = CreateMutex(NULL,FALSE,"");<br />
    Copy(Src); <br />
  }<br />
<br />
  virtual ~CPerfTimerT() <br />
  { CloseHandle(m_hMutex); }<br />
<br />
  const CPerfTimerT& operator=(const CPerfTimerT& Src) // Assignment operator <br />
  {<br />
    Copy(Src);<br />
    return *this; <br />
  }<br />
 <br />
  virtual void Lock() const { WaitForSingleObject(m_hMutex,10000); }   <br />
  virtual void Unlock() const { ReleaseMutex(m_hMutex); }   <br />
private:<br />
  HANDLE m_hMutex;<br />
};<br />
<br />
inline void CPerfTimer::Init(BOOL bStart)<br />
{<br />
  if (!m_Freq) <br />
  { // Initialization should only run once<br />
    QueryPerformanceFrequency((LARGE_INTEGER *)&m_Freq); <br />
    if (!m_Freq)<br />
      m_Freq = 1; // Timer will be useless but will not cause divide by zero<br />
    m_Start = 0; <br />
    m_Adjust = 0; <br />
    Start();            // Time a Stop<br />
    Stop(); <br />
    m_Adjust = m_Start;<br />
  }<br />
  // This is the only part that normally runs<br />
  m_Start = 0; <br />
  if (bStart)<br />
    Start(); <br />
}<br />
<br />
inline CPerfTimer::CPerfTimer(const CPerfTimer& Src)  <br />
{<br />
  Copy(Src);<br />
}<br />
<br />
inline void CPerfTimer::Copy(const CPerfTimer& Src)<br />
{<br />
  if (&Src == this) <br />
    return; // avoid deadlock if someone tries to copy it to itself<br />
  Src.Lock();<br />
  Lock();<br />
  m_Start = Src.m_Start; <br />
  Unlock();<br />
  Src.Unlock();<br />
}<br />
<br />
inline void CPerfTimer::Start(BOOL bReset) <br />
{ // Start from current value or optionally from 0<br />
  __int64 i;<br />
  QueryPerformanceCounter((LARGE_INTEGER *)&i);<br />
  Lock();<br />
  if ((!bReset) && (m_Start < 0))<br />
    m_Start += i;   // We are starting with an accumulated time<br />
  else <br />
    m_Start = i;    // Starting from 0<br />
  Unlock();<br />
} <br />
<br />
inline void CPerfTimer::Stop() <br />
{ // Stop timing. Use Start afterwards to continue<br />
  Lock();<br />
  if (m_Start <= 0)<br />
  {<br />
    Unlock();<br />
    return;          // Was not running<br />
  }<br />
  __int64 i;<br />
  QueryPerformanceCounter((LARGE_INTEGER *)&i); <br />
  m_Start += -i;          // Stopped timer keeps elapsed timer ticks as a negative <br />
  if (m_Start < m_Adjust) // Do not overflow<br />
    m_Start -= m_Adjust;  // Adjust for time timer code takes to run<br />
  else <br />
    m_Start = 0;          // Stop must have been called directly after Start<br />
  Unlock();<br />
} <br />
<br />
inline BOOL CPerfTimer::IsRunning() <br />
{ // Returns FALSE if stopped.<br />
  Lock();<br />
  BOOL bRet = (m_Start > 0); // When < 0, holds elpased clicks<br />
  Unlock();<br />
  return bRet;   <br />
}<br />
 inline const double CPerfTimer::Elapsed()<br />
{ // Returns elapsed time in seconds<br />
  CPerfTimer Result(*this);<br />
  Result.Stop();<br />
  return (double)(-Result.m_Start)/(double)m_Freq; <br />
}<br />
<br />
inline const double CPerfTimer::Elapsedms() <br />
{ // Returns elapsed time in milliseconds<br />
  CPerfTimer Result(*this);<br />
  Result.Stop();<br />
  return (-Result.m_Start*1000.0)/(double)m_Freq; <br />
}<br />
<br />
inline const double CPerfTimer::Elapsedus() <br />
{ // Returns elapsed time in microseconds<br />
  CPerfTimer Result(*this);<br />
  Result.Stop();<br />
  return (-Result.m_Start * 1000000.0)/(double)m_Freq; <br />
}<br />
<br />
<br />
// Assignment operator<br />
inline const CPerfTimer& CPerfTimer::operator=(const CPerfTimer& Src) <br />
{<br />
  Copy(Src);<br />
  return *this; <br />
}<br />
<br />
<br />
// Math operators<br />
inline CPerfTimer CPerfTimer::operator+(const CPerfTimer& Src) const<br />
{<br />
  CPerfTimer Result(*this);<br />
  Result += Src; <br />
  return Result; <br />
}<br />
<br />
inline CPerfTimer CPerfTimer::operator-(const CPerfTimer& Src) const<br />
{<br />
  CPerfTimer Result(*this);<br />
  Result -= Src; <br />
  return Result; <br />
}<br />
<br />
inline const CPerfTimer& CPerfTimer::operator+=(const CPerfTimer& Src)<br />
{<br />
  CPerfTimer SrcStop(Src);  // Temp is necessary in case Src is not stopped<br />
  SrcStop.Stop();<br />
  Lock();<br />
  m_Start += SrcStop.m_Start;<br />
  Unlock();<br />
  return *this; <br />
}<br />
<br />
inline const CPerfTimer& CPerfTimer::operator-=(const CPerfTimer& Src)<br />
{<br />
  CPerfTimer SrcStop(Src);  // Temp is necessary in case Src is not stopped<br />
  SrcStop.Stop();<br />
  Lock();<br />
  m_Start -= SrcStop.m_Start; <br />
  Unlock();<br />
  return *this; <br />
}<br />
<br />
// For time in seconds<br />
inline CPerfTimer CPerfTimer::operator+(const double Secs) const<br />
{<br />
  CPerfTimer Result(*this);<br />
  Result += Secs; <br />
  return Result; <br />
}<br />
<br />
inline CPerfTimer CPerfTimer::operator-(const double Secs) const<br />
{<br />
  CPerfTimer Result(*this);<br />
  Result += Secs; <br />
  return Result; <br />
}<br />
<br />
inline const CPerfTimer& CPerfTimer::operator+=(const double Secs)<br />
{<br />
  Lock();<br />
  m_Start -= (__int64)(Secs*(double)m_Freq);<br />
  Unlock();<br />
  return *this; <br />
}<br />
<br />
inline const CPerfTimer& CPerfTimer::operator-=(const double Secs)<br />
{<br />
  Lock();<br />
  m_Start += (__int64)(Secs*(double)m_Freq);<br />
  Unlock();<br />
  return *this; <br />
}<br />
<br />
<br />
<br />
// Boolean comparison operators<br />
inline BOOL CPerfTimer::operator<(const CPerfTimer& Src)<br />
{ <br />
  BOOL bRet; <br />
  CPerfTimer Temp(Src);<br />
  Lock();<br />
  if (m_Start <= 0)<br />
  {<br />
    Temp.Stop();<br />
    bRet = (m_Start > Temp.m_Start); <br />
    Unlock();<br />
    return bRet;<br />
  }<br />
  else<br />
  if (Temp.m_Start > 0)<br />
  {<br />
    bRet = (m_Start < Temp.m_Start); <br />
    Unlock();<br />
    return bRet;<br />
  }<br />
  else<br />
  {<br />
    Unlock();<br />
    CPerfTimer ThisStop(*this);<br />
    ThisStop.Stop();<br />
    return (ThisStop.m_Start > Temp.m_Start); <br />
  }<br />
}<br />
<br />
inline BOOL CPerfTimer::operator>(const CPerfTimer& Src)<br />
{ <br />
  BOOL bRet; <br />
  CPerfTimer Temp(Src);<br />
  Lock();<br />
  if (m_Start <= 0)<br />
  {<br />
    Temp.Stop();<br />
    bRet = (m_Start < Temp.m_Start); <br />
    Unlock();<br />
    return bRet;<br />
  }<br />
  else<br />
  if (Temp.m_Start > 0)<br />
  {<br />
    bRet = (m_Start > Temp.m_Start); <br />
    Unlock();<br />
    return bRet;<br />
  }<br />
  else<br />
  {<br />
    Unlock();<br />
    CPerfTimer ThisStop(*this);<br />
    ThisStop.Stop();<br />
    return (ThisStop.m_Start < Temp.m_Start); <br />
  }<br />
}<br />
<br />
inline BOOL CPerfTimer::operator<=(const CPerfTimer& Src)<br />
{ <br />
  return !(*this > Src);<br />
}<br />
<br />
inline BOOL CPerfTimer::operator>=(const CPerfTimer& Src)<br />
{ <br />
  return !(*this < Src);<br />
}<br />
<br />
// For time in seconds<br />
inline BOOL CPerfTimer::operator<(const double Secs)<br />
{ <br />
  BOOL bRet; <br />
  Lock();<br />
  if (m_Start <= 0)<br />
  {<br />
    bRet = (m_Start > (__int64)(-Secs*(double)m_Freq)); <br />
    Unlock();<br />
    return bRet;<br />
  }<br />
  else<br />
  {<br />
    Unlock();<br />
    CPerfTimer ThisStop(*this);<br />
    ThisStop.Stop();<br />
    return (ThisStop.m_Start > (__int64)(-Secs*(double)m_Freq)); <br />
  }<br />
}<br />
<br />
inline BOOL CPerfTimer::operator>(const double Secs)<br />
{ <br />
  BOOL bRet; <br />
  Lock();<br />
  if (m_Start <= 0)<br />
  {<br />
    bRet = (m_Start < (__int64)(-Secs*(double)m_Freq)); <br />
    Unlock();<br />
    return bRet;<br />
  }<br />
  else<br />
  {<br />
    Unlock();<br />
    CPerfTimer ThisStop(*this);<br />
    ThisStop.Stop();<br />
    return (ThisStop.m_Start < (__int64)(-Secs*(double)m_Freq)); <br />
  }<br />
}<br />
<br />
inline BOOL CPerfTimer::operator<=(const double Secs)<br />
{ <br />
  return !(*this > Secs);<br />
}<br />
<br />
inline BOOL CPerfTimer::operator>=(const double Secs)<br />
{ <br />
  return !(*this < Secs);<br />
}<br />
<br />
<br />
#endif //__PERFTIMER_H__




daemone
AnswerRe: how to use CPerftimer class in Dialog-based MFC application Pin
Rage5-Nov-06 22:51
professionalRage5-Nov-06 22:51 
GeneralRe: how to use CPerftimer class in Dialog-based MFC application Pin
daemone6-Nov-06 3:15
daemone6-Nov-06 3:15 
AnswerRe: how to use CPerftimer class in Dialog-based MFC application Pin
Hamid_RT5-Nov-06 23:59
Hamid_RT5-Nov-06 23:59 
Questionusing const Pin
minkowski5-Nov-06 22:08
minkowski5-Nov-06 22:08 
AnswerRe: using const Pin
Cedric Moonen5-Nov-06 22:32
Cedric Moonen5-Nov-06 22:32 
GeneralRe: using const Pin
minkowski5-Nov-06 22:37
minkowski5-Nov-06 22:37 
GeneralRe: using const Pin
Rage5-Nov-06 22:45
professionalRage5-Nov-06 22:45 
GeneralRe: using const Pin
minkowski6-Nov-06 3:02
minkowski6-Nov-06 3:02 
GeneralRe: using const Pin
Cedric Moonen6-Nov-06 3:13
Cedric Moonen6-Nov-06 3:13 
GeneralRe: using const Pin
minkowski6-Nov-06 4:22
minkowski6-Nov-06 4:22 
GeneralRe: using const Pin
Cedric Moonen6-Nov-06 4:27
Cedric Moonen6-Nov-06 4:27 
GeneralRe: using const Pin
minkowski6-Nov-06 4:38
minkowski6-Nov-06 4:38 
GeneralRe: using const Pin
David Crow6-Nov-06 4:27
David Crow6-Nov-06 4:27 
Questionsplitter window Pin
sarojkumarjena5-Nov-06 21:41
sarojkumarjena5-Nov-06 21:41 
AnswerRe: splitter window Pin
Sunil P V5-Nov-06 21:56
Sunil P V5-Nov-06 21:56 
GeneralRe: splitter window Pin
Rage5-Nov-06 22:44
professionalRage5-Nov-06 22:44 
GeneralRe: splitter window Pin
Cedric Moonen5-Nov-06 22:54
Cedric Moonen5-Nov-06 22:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.