mirror of https://github.com/probonopd/MiniDexed
https://github.com/probonopd/MiniDexed/issues/12#issuecomment-1051853664 Thanks @rsta2pull/30/head
parent
997d1c9f5f
commit
cdd603091b
@ -0,0 +1,50 @@ |
|||||||
|
//
|
||||||
|
// perftimer.cpp
|
||||||
|
//
|
||||||
|
#include "perftimer.h" |
||||||
|
#include <iostream> |
||||||
|
|
||||||
|
CPerformanceTimer::CPerformanceTimer (const char *pName, unsigned nDeadlineMicros) |
||||||
|
: m_Name (pName), |
||||||
|
m_nDeadlineMicros (nDeadlineMicros), |
||||||
|
m_nMaximumMicros (0), |
||||||
|
m_nLastDumpTicks (0) |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
void CPerformanceTimer::Start (void) |
||||||
|
{ |
||||||
|
m_nStartTicks = CTimer::GetClockTicks (); |
||||||
|
} |
||||||
|
|
||||||
|
void CPerformanceTimer::Stop (void) |
||||||
|
{ |
||||||
|
unsigned nEndTicks = CTimer::GetClockTicks (); |
||||||
|
unsigned nMicros = (nEndTicks - m_nStartTicks) / (CLOCKHZ / 1000000); |
||||||
|
|
||||||
|
if (nMicros > m_nMaximumMicros) |
||||||
|
{ |
||||||
|
m_nMaximumMicros = nMicros; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void CPerformanceTimer::Dump (unsigned nIntervalTicks) |
||||||
|
{ |
||||||
|
unsigned nTicks = CTimer::GetClockTicks (); |
||||||
|
|
||||||
|
if (nTicks - m_nLastDumpTicks >= nIntervalTicks) |
||||||
|
{ |
||||||
|
m_nLastDumpTicks = nTicks; |
||||||
|
|
||||||
|
unsigned nMaximumMicros = m_nMaximumMicros; // may be overwritten from interrupt
|
||||||
|
|
||||||
|
std::cout << m_Name << ": Maximum duration was " << nMaximumMicros << "us"; |
||||||
|
|
||||||
|
if (m_nDeadlineMicros != 0) |
||||||
|
{ |
||||||
|
std::cout << " (" << nMaximumMicros*100 / m_nDeadlineMicros << "%)"; |
||||||
|
} |
||||||
|
|
||||||
|
std::cout << std::endl; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,30 @@ |
|||||||
|
//
|
||||||
|
// perftimer.h
|
||||||
|
//
|
||||||
|
#ifndef _perftimer_h |
||||||
|
#define _perftimer_h |
||||||
|
|
||||||
|
#include <string> |
||||||
|
#include <circle/timer.h> |
||||||
|
|
||||||
|
class CPerformanceTimer |
||||||
|
{ |
||||||
|
public: |
||||||
|
CPerformanceTimer (const char *pName, unsigned nDeadlineMicros = 0); |
||||||
|
|
||||||
|
void Start (void); |
||||||
|
void Stop (void); |
||||||
|
|
||||||
|
void Dump (unsigned nIntervalTicks = CLOCKHZ); |
||||||
|
|
||||||
|
private: |
||||||
|
std::string m_Name; |
||||||
|
unsigned m_nDeadlineMicros; |
||||||
|
|
||||||
|
unsigned m_nStartTicks; |
||||||
|
unsigned m_nMaximumMicros; |
||||||
|
|
||||||
|
unsigned m_nLastDumpTicks; |
||||||
|
}; |
||||||
|
|
||||||
|
#endif |
Loading…
Reference in new issue