mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 20:23:06 +02:00
Merge pull request #4034 from ZappoMan/multiThreadedPerformanceTimer
Multi threaded performance timer
This commit is contained in:
commit
0b9c9daed9
2 changed files with 18 additions and 13 deletions
|
@ -13,7 +13,8 @@
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include <QtCore/QDebug>
|
#include <QDebug>
|
||||||
|
#include <QThread>
|
||||||
|
|
||||||
#include "PerfStat.h"
|
#include "PerfStat.h"
|
||||||
|
|
||||||
|
@ -77,15 +78,26 @@ void PerformanceTimerRecord::tallyResult(const quint64& now) {
|
||||||
// PerformanceTimer
|
// PerformanceTimer
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
QString PerformanceTimer::_fullName;
|
QHash<QThread*, QString> PerformanceTimer::_fullNames;
|
||||||
QMap<QString, PerformanceTimerRecord> PerformanceTimer::_records;
|
QMap<QString, PerformanceTimerRecord> PerformanceTimer::_records;
|
||||||
|
|
||||||
|
|
||||||
|
PerformanceTimer::PerformanceTimer(const QString& name) :
|
||||||
|
_start(0),
|
||||||
|
_name(name)
|
||||||
|
{
|
||||||
|
QString& fullName = _fullNames[QThread::currentThread()];
|
||||||
|
fullName.append("/");
|
||||||
|
fullName.append(_name);
|
||||||
|
_start = usecTimestampNow();
|
||||||
|
}
|
||||||
|
|
||||||
PerformanceTimer::~PerformanceTimer() {
|
PerformanceTimer::~PerformanceTimer() {
|
||||||
quint64 elapsedusec = (usecTimestampNow() - _start);
|
quint64 elapsedusec = (usecTimestampNow() - _start);
|
||||||
PerformanceTimerRecord& namedRecord = _records[_fullName];
|
QString& fullName = _fullNames[QThread::currentThread()];
|
||||||
|
PerformanceTimerRecord& namedRecord = _records[fullName];
|
||||||
namedRecord.accumulateResult(elapsedusec);
|
namedRecord.accumulateResult(elapsedusec);
|
||||||
_fullName.resize(_fullName.size() - (_name.size() + 1));
|
fullName.resize(fullName.size() - (_name.size() + 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
|
|
|
@ -73,14 +73,7 @@ private:
|
||||||
class PerformanceTimer {
|
class PerformanceTimer {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
PerformanceTimer(const QString& name) :
|
PerformanceTimer(const QString& name);
|
||||||
_start(0),
|
|
||||||
_name(name) {
|
|
||||||
_fullName.append("/");
|
|
||||||
_fullName.append(_name);
|
|
||||||
_start = usecTimestampNow();
|
|
||||||
}
|
|
||||||
|
|
||||||
~PerformanceTimer();
|
~PerformanceTimer();
|
||||||
|
|
||||||
static const PerformanceTimerRecord& getTimerRecord(const QString& name) { return _records[name]; };
|
static const PerformanceTimerRecord& getTimerRecord(const QString& name) { return _records[name]; };
|
||||||
|
@ -91,7 +84,7 @@ public:
|
||||||
private:
|
private:
|
||||||
quint64 _start;
|
quint64 _start;
|
||||||
QString _name;
|
QString _name;
|
||||||
static QString _fullName;
|
static QHash<QThread*, QString> _fullNames;
|
||||||
static QMap<QString, PerformanceTimerRecord> _records;
|
static QMap<QString, PerformanceTimerRecord> _records;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue