added class CTimingMeas
This commit is contained in:
parent
583a61081b
commit
403d3820bf
1 changed files with 56 additions and 0 deletions
56
src/util.h
56
src/util.h
|
@ -39,6 +39,7 @@
|
|||
#include <QDesktopServices>
|
||||
#include <QUrl>
|
||||
#include <QLocale>
|
||||
#include <QElapsedTimer>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include "global.h"
|
||||
|
@ -1135,6 +1136,61 @@ public:
|
|||
};
|
||||
|
||||
|
||||
// Timing measurement ----------------------------------------------------------
|
||||
// intended for debugging the timing jitter of the sound card or server timer
|
||||
class CTimingMeas
|
||||
{
|
||||
public:
|
||||
CTimingMeas ( const int iNNMeas, const QString strNFName = "" ) :
|
||||
iNumMeas ( iNNMeas ), vElapsedTimes ( iNNMeas ), strFileName ( strNFName ) { Reset(); }
|
||||
|
||||
void Reset() { iCnt = -1; }
|
||||
void Measure()
|
||||
{
|
||||
// exclude the very first measurement (initialization phase)
|
||||
if ( iCnt == -1 )
|
||||
{
|
||||
iCnt = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
// store current measurement
|
||||
vElapsedTimes[iCnt++] = ElapsedTimer.nsecsElapsed();
|
||||
|
||||
// reset count if number of measurements are done
|
||||
if ( iCnt >= iNumMeas )
|
||||
{
|
||||
iCnt = 0;
|
||||
|
||||
// store results in a file if file name is given
|
||||
if ( !strFileName.isEmpty() )
|
||||
{
|
||||
QFile File ( strFileName );
|
||||
|
||||
if ( File.open ( QIODevice::WriteOnly | QIODevice::Text ) )
|
||||
{
|
||||
QTextStream streamFile ( &File );
|
||||
for ( int i = 0; i < iNumMeas; i++ )
|
||||
{
|
||||
// convert ns in ms and store the value
|
||||
streamFile << static_cast<double> ( vElapsedTimes[i] ) / 1000000 << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
ElapsedTimer.start();
|
||||
}
|
||||
|
||||
protected:
|
||||
int iNumMeas;
|
||||
CVector<int> vElapsedTimes;
|
||||
QString strFileName;
|
||||
QElapsedTimer ElapsedTimer;
|
||||
int iCnt;
|
||||
};
|
||||
|
||||
|
||||
/******************************************************************************\
|
||||
* Statistics *
|
||||
\******************************************************************************/
|
||||
|
|
Loading…
Reference in a new issue