You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
MiniDexed/src/perftimer.cpp

51 lines
1.0 KiB

//
// 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;
}
}