mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 06:17:28 +02:00
Merge pull request #4939 from Atlante45/perf_timer_tweaks
Deactivate PerformanceTimer when not in use
This commit is contained in:
commit
7ed3a97bf2
5 changed files with 56 additions and 19 deletions
|
@ -979,6 +979,14 @@ void ApplicationOverlay::renderStatsAndLogs() {
|
||||||
glLineWidth(1.0f);
|
glLineWidth(1.0f);
|
||||||
glPointSize(1.0f);
|
glPointSize(1.0f);
|
||||||
|
|
||||||
|
// Determine whether to compute timing details
|
||||||
|
bool shouldDisplayTimingDetail = Menu::getInstance()->isOptionChecked(MenuOption::DisplayDebugTimingDetails) &&
|
||||||
|
Menu::getInstance()->isOptionChecked(MenuOption::Stats) &&
|
||||||
|
Stats::getInstance()->isExpanded();
|
||||||
|
if (shouldDisplayTimingDetail != PerformanceTimer::isActive()) {
|
||||||
|
PerformanceTimer::setActive(shouldDisplayTimingDetail);
|
||||||
|
}
|
||||||
|
|
||||||
if (Menu::getInstance()->isOptionChecked(MenuOption::Stats)) {
|
if (Menu::getInstance()->isOptionChecked(MenuOption::Stats)) {
|
||||||
// let's set horizontal offset to give stats some margin to mirror
|
// let's set horizontal offset to give stats some margin to mirror
|
||||||
int horizontalOffset = MIRROR_VIEW_WIDTH + MIRROR_VIEW_LEFT_PADDING * 2;
|
int horizontalOffset = MIRROR_VIEW_WIDTH + MIRROR_VIEW_LEFT_PADDING * 2;
|
||||||
|
|
|
@ -224,10 +224,11 @@ void Stats::display(
|
||||||
lines = 5;
|
lines = 5;
|
||||||
int columnOneWidth = _generalStatsWidth;
|
int columnOneWidth = _generalStatsWidth;
|
||||||
|
|
||||||
|
bool performanceTimerIsActive = PerformanceTimer::isActive();
|
||||||
|
bool displayPerf = _expanded && Menu::getInstance()->isOptionChecked(MenuOption::DisplayDebugTimingDetails);
|
||||||
|
if (displayPerf && performanceTimerIsActive) {
|
||||||
PerformanceTimer::tallyAllTimerRecords(); // do this even if we're not displaying them, so they don't stack up
|
PerformanceTimer::tallyAllTimerRecords(); // do this even if we're not displaying them, so they don't stack up
|
||||||
|
|
||||||
if (_expanded && Menu::getInstance()->isOptionChecked(MenuOption::DisplayDebugTimingDetails)) {
|
|
||||||
|
|
||||||
columnOneWidth = _generalStatsWidth + _pingStatsWidth + _geoStatsWidth; // 3 columns wide...
|
columnOneWidth = _generalStatsWidth + _pingStatsWidth + _geoStatsWidth; // 3 columns wide...
|
||||||
// we will also include room for 1 line per timing record and a header of 4 lines
|
// we will also include room for 1 line per timing record and a header of 4 lines
|
||||||
lines += 4;
|
lines += 4;
|
||||||
|
@ -276,7 +277,7 @@ void Stats::display(
|
||||||
|
|
||||||
|
|
||||||
// TODO: the display of these timing details should all be moved to JavaScript
|
// TODO: the display of these timing details should all be moved to JavaScript
|
||||||
if (_expanded && Menu::getInstance()->isOptionChecked(MenuOption::DisplayDebugTimingDetails)) {
|
if (displayPerf && performanceTimerIsActive) {
|
||||||
bool onlyDisplayTopTen = Menu::getInstance()->isOptionChecked(MenuOption::OnlyDisplayTopTen);
|
bool onlyDisplayTopTen = Menu::getInstance()->isOptionChecked(MenuOption::OnlyDisplayTopTen);
|
||||||
// Timing details...
|
// Timing details...
|
||||||
verticalOffset += STATS_PELS_PER_LINE * 4; // skip 3 lines to be under the other columns
|
verticalOffset += STATS_PELS_PER_LINE * 4; // skip 3 lines to be under the other columns
|
||||||
|
|
|
@ -27,6 +27,8 @@ public:
|
||||||
static void drawBackground(unsigned int rgba, int x, int y, int width, int height);
|
static void drawBackground(unsigned int rgba, int x, int y, int width, int height);
|
||||||
|
|
||||||
void toggleExpanded();
|
void toggleExpanded();
|
||||||
|
bool isExpanded() { return _expanded; }
|
||||||
|
|
||||||
void checkClick(int mouseX, int mouseY, int mouseDragStartedX, int mouseDragStartedY, int horizontalOffset);
|
void checkClick(int mouseX, int mouseY, int mouseDragStartedX, int mouseDragStartedY, int horizontalOffset);
|
||||||
void resetWidth(int width, int horizontalOffset);
|
void resetWidth(int width, int horizontalOffset);
|
||||||
void display(const float* color, int horizontalOffset, float fps, int inPacketsPerSecond, int outPacketsPerSecond,
|
void display(const float* color, int horizontalOffset, float fps, int inPacketsPerSecond, int outPacketsPerSecond,
|
||||||
|
|
|
@ -79,26 +79,47 @@ void PerformanceTimerRecord::tallyResult(const quint64& now) {
|
||||||
// PerformanceTimer
|
// PerformanceTimer
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
std::atomic<bool> PerformanceTimer::_isActive(false);
|
||||||
QHash<QThread*, QString> PerformanceTimer::_fullNames;
|
QHash<QThread*, QString> PerformanceTimer::_fullNames;
|
||||||
QMap<QString, PerformanceTimerRecord> PerformanceTimer::_records;
|
QMap<QString, PerformanceTimerRecord> PerformanceTimer::_records;
|
||||||
|
|
||||||
|
|
||||||
PerformanceTimer::PerformanceTimer(const QString& name) :
|
PerformanceTimer::PerformanceTimer(const QString& name) {
|
||||||
_start(0),
|
if (_isActive) {
|
||||||
_name(name)
|
_name = name;
|
||||||
{
|
|
||||||
QString& fullName = _fullNames[QThread::currentThread()];
|
QString& fullName = _fullNames[QThread::currentThread()];
|
||||||
fullName.append("/");
|
fullName.append("/");
|
||||||
fullName.append(_name);
|
fullName.append(_name);
|
||||||
_start = usecTimestampNow();
|
_start = usecTimestampNow();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PerformanceTimer::~PerformanceTimer() {
|
PerformanceTimer::~PerformanceTimer() {
|
||||||
|
if (_isActive && _start != 0) {
|
||||||
quint64 elapsedusec = (usecTimestampNow() - _start);
|
quint64 elapsedusec = (usecTimestampNow() - _start);
|
||||||
QString& fullName = _fullNames[QThread::currentThread()];
|
QString& fullName = _fullNames[QThread::currentThread()];
|
||||||
PerformanceTimerRecord& namedRecord = _records[fullName];
|
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
|
||||||
|
bool PerformanceTimer::isActive() {
|
||||||
|
return _isActive;
|
||||||
|
}
|
||||||
|
|
||||||
|
// static
|
||||||
|
void PerformanceTimer::setActive(bool active) {
|
||||||
|
if (active != _isActive) {
|
||||||
|
_isActive.store(active);
|
||||||
|
if (!active) {
|
||||||
|
_fullNames.clear();
|
||||||
|
_records.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
qDebug() << "PerformanceTimer has been turned" << ((active) ? "on" : "off");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
#include "SharedUtil.h"
|
#include "SharedUtil.h"
|
||||||
#include "SimpleMovingAverage.h"
|
#include "SimpleMovingAverage.h"
|
||||||
|
|
||||||
|
#include <atomic>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
@ -76,14 +77,18 @@ public:
|
||||||
PerformanceTimer(const QString& name);
|
PerformanceTimer(const QString& name);
|
||||||
~PerformanceTimer();
|
~PerformanceTimer();
|
||||||
|
|
||||||
|
static bool isActive();
|
||||||
|
static void setActive(bool active);
|
||||||
|
|
||||||
static const PerformanceTimerRecord& getTimerRecord(const QString& name) { return _records[name]; };
|
static const PerformanceTimerRecord& getTimerRecord(const QString& name) { return _records[name]; };
|
||||||
static const QMap<QString, PerformanceTimerRecord>& getAllTimerRecords() { return _records; };
|
static const QMap<QString, PerformanceTimerRecord>& getAllTimerRecords() { return _records; };
|
||||||
static void tallyAllTimerRecords();
|
static void tallyAllTimerRecords();
|
||||||
static void dumpAllTimerRecords();
|
static void dumpAllTimerRecords();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
quint64 _start;
|
quint64 _start = 0;
|
||||||
QString _name;
|
QString _name;
|
||||||
|
static std::atomic<bool> _isActive;
|
||||||
static QHash<QThread*, QString> _fullNames;
|
static QHash<QThread*, QString> _fullNames;
|
||||||
static QMap<QString, PerformanceTimerRecord> _records;
|
static QMap<QString, PerformanceTimerRecord> _records;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue