Merge pull request #4034 from ZappoMan/multiThreadedPerformanceTimer

Multi threaded performance timer
This commit is contained in:
Andrew Meadows 2015-01-05 13:01:59 -08:00
commit 0b9c9daed9
2 changed files with 18 additions and 13 deletions

View file

@ -13,7 +13,8 @@
#include <map>
#include <string>
#include <QtCore/QDebug>
#include <QDebug>
#include <QThread>
#include "PerfStat.h"
@ -77,15 +78,26 @@ void PerformanceTimerRecord::tallyResult(const quint64& now) {
// PerformanceTimer
// ----------------------------------------------------------------------------
QString PerformanceTimer::_fullName;
QHash<QThread*, QString> PerformanceTimer::_fullNames;
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() {
quint64 elapsedusec = (usecTimestampNow() - _start);
PerformanceTimerRecord& namedRecord = _records[_fullName];
QString& fullName = _fullNames[QThread::currentThread()];
PerformanceTimerRecord& namedRecord = _records[fullName];
namedRecord.accumulateResult(elapsedusec);
_fullName.resize(_fullName.size() - (_name.size() + 1));
fullName.resize(fullName.size() - (_name.size() + 1));
}
// static

View file

@ -73,14 +73,7 @@ private:
class PerformanceTimer {
public:
PerformanceTimer(const QString& name) :
_start(0),
_name(name) {
_fullName.append("/");
_fullName.append(_name);
_start = usecTimestampNow();
}
PerformanceTimer(const QString& name);
~PerformanceTimer();
static const PerformanceTimerRecord& getTimerRecord(const QString& name) { return _records[name]; };
@ -91,7 +84,7 @@ public:
private:
quint64 _start;
QString _name;
static QString _fullName;
static QHash<QThread*, QString> _fullNames;
static QMap<QString, PerformanceTimerRecord> _records;
};