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