Use QElapsedTimer class instead of MUtils::OS::perfcounter_read() where appropriate.
This commit is contained in:
parent
f602bfa6c9
commit
b704d5161f
@ -35,7 +35,7 @@
|
|||||||
#define VER_LAMEXP_MINOR_LO 1
|
#define VER_LAMEXP_MINOR_LO 1
|
||||||
#define VER_LAMEXP_TYPE Beta
|
#define VER_LAMEXP_TYPE Beta
|
||||||
#define VER_LAMEXP_PATCH 5
|
#define VER_LAMEXP_PATCH 5
|
||||||
#define VER_LAMEXP_BUILD 1617
|
#define VER_LAMEXP_BUILD 1619
|
||||||
#define VER_LAMEXP_CONFG 1558
|
#define VER_LAMEXP_CONFG 1558
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -50,6 +50,7 @@
|
|||||||
#include <QTextStream>
|
#include <QTextStream>
|
||||||
#include <QScrollBar>
|
#include <QScrollBar>
|
||||||
#include <QCloseEvent>
|
#include <QCloseEvent>
|
||||||
|
#include <QElapsedTimer>
|
||||||
#include <QWindowsVistaStyle>
|
#include <QWindowsVistaStyle>
|
||||||
#include <QWindowsXPStyle>
|
#include <QWindowsXPStyle>
|
||||||
|
|
||||||
@ -146,7 +147,6 @@ AboutDialog::AboutDialog(SettingsModel *settings, QWidget *parent, bool firstSta
|
|||||||
m_disque(NULL),
|
m_disque(NULL),
|
||||||
m_disqueTimer(NULL),
|
m_disqueTimer(NULL),
|
||||||
m_rotateNext(false),
|
m_rotateNext(false),
|
||||||
m_disqueDelay(_I64_MAX),
|
|
||||||
m_lastTab(0)
|
m_lastTab(0)
|
||||||
{
|
{
|
||||||
//Init the dialog, from the .ui file
|
//Init the dialog, from the .ui file
|
||||||
@ -387,17 +387,18 @@ void AboutDialog::gotoLicenseTab(void)
|
|||||||
void AboutDialog::moveDisque(void)
|
void AboutDialog::moveDisque(void)
|
||||||
{
|
{
|
||||||
int delta = 2;
|
int delta = 2;
|
||||||
const qint64 perfFrequ = MUtils::OS::perfcounter_freq();
|
QElapsedTimer elapsedTimer;
|
||||||
const qint64 perfCount = MUtils::OS::perfcounter_read();
|
elapsedTimer.start();
|
||||||
|
|
||||||
if((perfFrequ >= 0) && (perfCount >= 0))
|
if((!m_disqueDelay.isNull()) && m_disqueDelay->isValid())
|
||||||
{
|
{
|
||||||
if(m_disqueDelay != _I64_MAX)
|
const qint64 delay = m_disqueDelay->restart();
|
||||||
{
|
delta = qBound(1, static_cast<int>(ceil(static_cast<double>(delay) / 5.12)), 128);
|
||||||
const double delay = static_cast<double>(perfCount) - static_cast<double>(m_disqueDelay);
|
|
||||||
delta = qMax(1, qMin(128, static_cast<int>(ceil(delay / static_cast<double>(perfFrequ) / 0.00512))));
|
|
||||||
}
|
}
|
||||||
m_disqueDelay = perfCount;
|
else
|
||||||
|
{
|
||||||
|
m_disqueDelay.reset(new QElapsedTimer());
|
||||||
|
m_disqueDelay->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(m_disque)
|
if(m_disque)
|
||||||
|
@ -33,6 +33,7 @@ namespace Ui {
|
|||||||
class QLabel;
|
class QLabel;
|
||||||
class QPixmap;
|
class QPixmap;
|
||||||
class QTimer;
|
class QTimer;
|
||||||
|
class QElapsedTimer;
|
||||||
class SettingsModel;
|
class SettingsModel;
|
||||||
|
|
||||||
//AboutDialog class
|
//AboutDialog class
|
||||||
@ -78,7 +79,7 @@ private:
|
|||||||
double m_discOpacity;
|
double m_discOpacity;
|
||||||
QPixmap *m_cartoon[4];
|
QPixmap *m_cartoon[4];
|
||||||
bool m_rotateNext;
|
bool m_rotateNext;
|
||||||
__int64 m_disqueDelay;
|
QScopedPointer<QElapsedTimer> m_disqueDelay;
|
||||||
|
|
||||||
void initInformationTab(void);
|
void initInformationTab(void);
|
||||||
void initContributorsTab(void);
|
void initContributorsTab(void);
|
||||||
|
@ -69,10 +69,12 @@
|
|||||||
#include <QProgressDialog>
|
#include <QProgressDialog>
|
||||||
#include <QResizeEvent>
|
#include <QResizeEvent>
|
||||||
#include <QTime>
|
#include <QTime>
|
||||||
|
#include <QElapsedTimer>
|
||||||
#include <QThreadPool>
|
#include <QThreadPool>
|
||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <float.h>
|
#include <float.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
@ -291,7 +293,6 @@ ProcessingDialog::ProcessingDialog(FileListModel *fileListModel, const AudioFile
|
|||||||
m_skippedJobs.clear();
|
m_skippedJobs.clear();
|
||||||
m_userAborted = false;
|
m_userAborted = false;
|
||||||
m_forcedAbort = false;
|
m_forcedAbort = false;
|
||||||
m_timerStart = 0I64;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
@ -555,7 +556,9 @@ void ProcessingDialog::initEncoding(void)
|
|||||||
|
|
||||||
m_initThreads = m_threadPool->maxThreadCount();
|
m_initThreads = m_threadPool->maxThreadCount();
|
||||||
QTimer::singleShot(100, this, SLOT(initNextJob()));
|
QTimer::singleShot(100, this, SLOT(initNextJob()));
|
||||||
m_timerStart = MUtils::OS::perfcounter_read();
|
|
||||||
|
m_totalTime.reset(new QElapsedTimer());
|
||||||
|
m_totalTime->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProcessingDialog::initNextJob(void)
|
void ProcessingDialog::initNextJob(void)
|
||||||
@ -705,15 +708,10 @@ void ProcessingDialog::doneEncoding(void)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
const qint64 counter = MUtils::OS::perfcounter_read();
|
if((!m_totalTime.isNull()) && m_totalTime->isValid())
|
||||||
const qint64 frequency = MUtils::OS::perfcounter_freq();
|
|
||||||
if((counter >= 0I64) && (frequency >= 0))
|
|
||||||
{
|
{
|
||||||
if((m_timerStart >= 0I64) && (m_timerStart < counter))
|
m_progressModel->addSystemMessage(tr("Process finished after %1.").arg(time2text(m_totalTime->elapsed())), ProgressModel::SysMsg_Performance);
|
||||||
{
|
m_totalTime->invalidate();
|
||||||
double timeElapsed = static_cast<double>(counter - m_timerStart) / static_cast<double>(frequency);
|
|
||||||
m_progressModel->addSystemMessage(tr("Process finished after %1.").arg(time2text(timeElapsed)), ProgressModel::SysMsg_Performance);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(m_failedJobs.count() > 0)
|
if(m_failedJobs.count() > 0)
|
||||||
@ -1151,12 +1149,10 @@ bool ProcessingDialog::shutdownComputer(void)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString ProcessingDialog::time2text(const double timeVal) const
|
QString ProcessingDialog::time2text(const qint64 &msec) const
|
||||||
{
|
{
|
||||||
double intPart = 0;
|
const qint64 MILLISECONDS_PER_DAY = 86399999; //24x60x60x1000 - 1
|
||||||
double frcPart = modf(timeVal, &intPart);
|
const QTime time = QTime().addMSecs(qMin(msec, MILLISECONDS_PER_DAY));
|
||||||
|
|
||||||
QTime time = QTime().addSecs(qRound(intPart)).addMSecs(qRound(frcPart * 1000.0));
|
|
||||||
|
|
||||||
QString a, b;
|
QString a, b;
|
||||||
|
|
||||||
|
@ -40,10 +40,10 @@ class QLabel;
|
|||||||
class QMenu;
|
class QMenu;
|
||||||
class QModelIndex;
|
class QModelIndex;
|
||||||
class QMovie;
|
class QMovie;
|
||||||
|
class QThreadPool;
|
||||||
|
class QElapsedTimer;
|
||||||
class RAMObserverThread;
|
class RAMObserverThread;
|
||||||
class SettingsModel;
|
class SettingsModel;
|
||||||
class QThreadPool;
|
|
||||||
class lamexp_icon_t;
|
|
||||||
|
|
||||||
enum shutdownFlag_t
|
enum shutdownFlag_t
|
||||||
{
|
{
|
||||||
@ -105,7 +105,7 @@ private:
|
|||||||
AudioFileModel updateMetaInfo(AudioFileModel &audioFile);
|
AudioFileModel updateMetaInfo(AudioFileModel &audioFile);
|
||||||
void writePlayList(void);
|
void writePlayList(void);
|
||||||
bool shutdownComputer(void);
|
bool shutdownComputer(void);
|
||||||
QString time2text(const double timeVal) const;
|
QString time2text(const qint64 &msec) const;
|
||||||
|
|
||||||
QThreadPool *m_threadPool;
|
QThreadPool *m_threadPool;
|
||||||
QList<AudioFileModel> m_pendingJobs;
|
QList<AudioFileModel> m_pendingJobs;
|
||||||
@ -133,7 +133,7 @@ private:
|
|||||||
CPUObserverThread *m_cpuObserver;
|
CPUObserverThread *m_cpuObserver;
|
||||||
RAMObserverThread *m_ramObserver;
|
RAMObserverThread *m_ramObserver;
|
||||||
DiskObserverThread *m_diskObserver;
|
DiskObserverThread *m_diskObserver;
|
||||||
qint64 m_timerStart;
|
QScopedPointer<QElapsedTimer> m_totalTime;
|
||||||
int m_progressViewFilter;
|
int m_progressViewFilter;
|
||||||
QColor *m_defaultColor;
|
QColor *m_defaultColor;
|
||||||
};
|
};
|
||||||
|
@ -44,6 +44,7 @@
|
|||||||
#include <QThreadPool>
|
#include <QThreadPool>
|
||||||
#include <QMutex>
|
#include <QMutex>
|
||||||
#include <QQueue>
|
#include <QQueue>
|
||||||
|
#include <QElapsedTimer>
|
||||||
|
|
||||||
/* helper macros */
|
/* helper macros */
|
||||||
#define PRINT_CPU_TYPE(X) case X: qDebug("Selected CPU is: " #X)
|
#define PRINT_CPU_TYPE(X) case X: qDebug("Selected CPU is: " #X)
|
||||||
@ -319,7 +320,9 @@ double InitializationThread::doInit(const size_t threadCount)
|
|||||||
LockedFile::selfTest();
|
LockedFile::selfTest();
|
||||||
ExtractorTask::clearFlags();
|
ExtractorTask::clearFlags();
|
||||||
|
|
||||||
const long long timeExtractStart = MUtils::OS::perfcounter_read();
|
//Start the timer
|
||||||
|
QElapsedTimer timeExtractStart;
|
||||||
|
timeExtractStart.start();
|
||||||
|
|
||||||
//Extract all files
|
//Extract all files
|
||||||
while(!(queueToolName.isEmpty() || queueChecksum.isEmpty() || queueVersInfo.isEmpty() || queueCpuTypes.isEmpty() || queueVersions.isEmpty()))
|
while(!(queueToolName.isEmpty() || queueChecksum.isEmpty() || queueVersInfo.isEmpty() || queueCpuTypes.isEmpty() || queueVersions.isEmpty()))
|
||||||
@ -364,7 +367,9 @@ double InitializationThread::doInit(const size_t threadCount)
|
|||||||
pool->waitForDone();
|
pool->waitForDone();
|
||||||
MUTILS_DELETE(pool);
|
MUTILS_DELETE(pool);
|
||||||
|
|
||||||
const long long timeExtractEnd = MUtils::OS::perfcounter_read();
|
//Performance measure
|
||||||
|
const qint64 delayExtract = timeExtractStart.elapsed();
|
||||||
|
timeExtractStart.invalidate();
|
||||||
|
|
||||||
//Make sure all files were extracted correctly
|
//Make sure all files were extracted correctly
|
||||||
if(ExtractorTask::getExcept())
|
if(ExtractorTask::getExcept())
|
||||||
@ -388,8 +393,7 @@ double InitializationThread::doInit(const size_t threadCount)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Check delay
|
//Check delay
|
||||||
const double delayExtract = static_cast<double>(timeExtractEnd - timeExtractStart) / static_cast<double>(MUtils::OS::perfcounter_freq());
|
if((double(delayExtract) / 1000.0) > g_allowedExtractDelay)
|
||||||
if(delayExtract > g_allowedExtractDelay)
|
|
||||||
{
|
{
|
||||||
m_slowIndicator = true;
|
m_slowIndicator = true;
|
||||||
qWarning("Extracting tools took %.3f seconds -> probably slow realtime virus scanner.", delayExtract);
|
qWarning("Extracting tools took %.3f seconds -> probably slow realtime virus scanner.", delayExtract);
|
||||||
|
@ -37,25 +37,29 @@
|
|||||||
#include <QLibrary>
|
#include <QLibrary>
|
||||||
#include <QProcessEnvironment>
|
#include <QProcessEnvironment>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
|
#include <QElapsedTimer>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Job Object
|
* Static Objects
|
||||||
*/
|
*/
|
||||||
QScopedPointer<JobObject> AbstractTool::s_jobObject;
|
QScopedPointer<JobObject> AbstractTool::s_jobObjectInstance;
|
||||||
QMutex AbstractTool::s_jobObjMtx;
|
QScopedPointer<QElapsedTimer> AbstractTool::s_startProcessTimer;
|
||||||
quint64 AbstractTool::s_jobObjCnt = 0ui64;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Process Timer
|
* Synchronization
|
||||||
*/
|
*/
|
||||||
quint64 AbstractTool::s_startProcessTimer = 0ui64;
|
|
||||||
QMutex AbstractTool::s_startProcessMutex;
|
QMutex AbstractTool::s_startProcessMutex;
|
||||||
|
QMutex AbstractTool::s_createObjectMutex;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Ref Counter
|
||||||
|
*/
|
||||||
|
quint64 AbstractTool::s_referenceCounter = 0ui64;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Const
|
* Const
|
||||||
*/
|
*/
|
||||||
static const unsigned int START_DELAY = 100U; //in milliseconds
|
static const qint64 START_DELAY = 64i64; //in milliseconds
|
||||||
static const quint64 START_DELAY_NANO = quint64(START_DELAY) * 10000ui64; //in 100-nanosecond intervals
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Constructor
|
* Constructor
|
||||||
@ -65,11 +69,12 @@ AbstractTool::AbstractTool(void)
|
|||||||
m_firstLaunch(true)
|
m_firstLaunch(true)
|
||||||
|
|
||||||
{
|
{
|
||||||
QMutexLocker lock(&s_jobObjMtx);
|
QMutexLocker lock(&s_createObjectMutex);
|
||||||
|
|
||||||
if(s_jobObjCnt++ == 0)
|
if(s_referenceCounter++ == 0)
|
||||||
{
|
{
|
||||||
s_jobObject.reset(new JobObject());
|
s_jobObjectInstance.reset(new JobObject());
|
||||||
|
s_startProcessTimer.reset(new QElapsedTimer());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,11 +83,12 @@ AbstractTool::AbstractTool(void)
|
|||||||
*/
|
*/
|
||||||
AbstractTool::~AbstractTool(void)
|
AbstractTool::~AbstractTool(void)
|
||||||
{
|
{
|
||||||
QMutexLocker lock(&s_jobObjMtx);
|
QMutexLocker lock(&s_createObjectMutex);
|
||||||
|
|
||||||
if(--s_jobObjCnt == 0)
|
if(--s_referenceCounter == 0)
|
||||||
{
|
{
|
||||||
s_jobObject.reset(NULL);
|
s_jobObjectInstance.reset(NULL);
|
||||||
|
s_startProcessTimer.reset(NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,14 +99,16 @@ bool AbstractTool::startProcess(QProcess &process, const QString &program, const
|
|||||||
{
|
{
|
||||||
QMutexLocker lock(&s_startProcessMutex);
|
QMutexLocker lock(&s_startProcessMutex);
|
||||||
|
|
||||||
quint64 currentFileTime = MUtils::OS::current_file_time();
|
if((!s_startProcessTimer.isNull()) && s_startProcessTimer->isValid())
|
||||||
while(currentFileTime < s_startProcessTimer)
|
{
|
||||||
|
qint64 elapsed = s_startProcessTimer->elapsed();
|
||||||
|
while(elapsed < START_DELAY)
|
||||||
{
|
{
|
||||||
const quint64 expectedFileTime = s_startProcessTimer;
|
|
||||||
lock.unlock();
|
lock.unlock();
|
||||||
MUtils::OS::sleep_ms(size_t((expectedFileTime - currentFileTime) / 10000ui64) + 1U);
|
MUtils::OS::sleep_ms((size_t)(START_DELAY - elapsed));
|
||||||
lock.relock();
|
lock.relock();
|
||||||
currentFileTime = MUtils::OS::current_file_time();
|
elapsed = s_startProcessTimer->elapsed();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
emit messageLogged(commandline2string(program, args) + "\n");
|
emit messageLogged(commandline2string(program, args) + "\n");
|
||||||
@ -110,9 +118,9 @@ bool AbstractTool::startProcess(QProcess &process, const QString &program, const
|
|||||||
|
|
||||||
if(process.waitForStarted())
|
if(process.waitForStarted())
|
||||||
{
|
{
|
||||||
if(!s_jobObject.isNull())
|
if(!s_jobObjectInstance.isNull())
|
||||||
{
|
{
|
||||||
if(!s_jobObject->addProcessToJob(&process))
|
if(!s_jobObjectInstance->addProcessToJob(&process))
|
||||||
{
|
{
|
||||||
qWarning("Failed to assign process to job object!");
|
qWarning("Failed to assign process to job object!");
|
||||||
}
|
}
|
||||||
@ -126,7 +134,7 @@ bool AbstractTool::startProcess(QProcess &process, const QString &program, const
|
|||||||
m_firstLaunch = false;
|
m_firstLaunch = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
s_startProcessTimer = MUtils::OS::current_file_time() + START_DELAY_NANO;
|
s_startProcessTimer->start();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -137,7 +145,7 @@ bool AbstractTool::startProcess(QProcess &process, const QString &program, const
|
|||||||
process.kill();
|
process.kill();
|
||||||
process.waitForFinished(-1);
|
process.waitForFinished(-1);
|
||||||
|
|
||||||
s_startProcessTimer = MUtils::OS::current_file_time() + START_DELAY_NANO;
|
s_startProcessTimer->start();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
|
|
||||||
class QMutex;
|
class QMutex;
|
||||||
class QProcess;
|
class QProcess;
|
||||||
|
class QElapsedTimer;
|
||||||
class JobObject;
|
class JobObject;
|
||||||
|
|
||||||
class AbstractTool : public QObject
|
class AbstractTool : public QObject
|
||||||
@ -47,12 +48,13 @@ protected:
|
|||||||
static const int m_processTimeoutInterval = 600000;
|
static const int m_processTimeoutInterval = 600000;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static quint64 s_startProcessTimer;
|
static QScopedPointer<JobObject> s_jobObjectInstance;
|
||||||
static QMutex s_startProcessMutex;
|
static QScopedPointer<QElapsedTimer> s_startProcessTimer;
|
||||||
|
|
||||||
static QScopedPointer<JobObject> s_jobObject;
|
static QMutex s_startProcessMutex;
|
||||||
static QMutex s_jobObjMtx;
|
static QMutex s_createObjectMutex;
|
||||||
static quint64 s_jobObjCnt;
|
|
||||||
|
static quint64 s_referenceCounter;
|
||||||
|
|
||||||
bool m_firstLaunch;
|
bool m_firstLaunch;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user