Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OpenGL: Add MythOpenGLPerf - an OpenGL timer
- a simple sub-class of QOpenGLTimeMonitor to record the exection time of blocks of OpenGL code - add OpenGL performance monitoring for VideoOutputOpenGL and run when - v gpu verbosity is enabled (i.e. mythfrontend -v gpu) - execution time is recorded for texture upload (when applicable), framebuffer clearing, rendering, flushing and the final framebuffer swap.
- Loading branch information
1 parent
c1bffb8
commit 733acd1
Showing
5 changed files
with
182 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// MythTV | ||
#include "mythlogging.h" | ||
#include "mythopenglperf.h" | ||
|
||
/*! \class MythOpenGLPerf | ||
* \brief A simple overload of QOpenGLTimeMonitor to record and log OpenGL execution intervals | ||
*/ | ||
MythOpenGLPerf::MythOpenGLPerf(const QString &Name, | ||
QVector<QString> Names, | ||
int SampleCount) | ||
: m_name(Name), | ||
m_totalSamples(SampleCount), | ||
m_timerNames(Names) | ||
{ | ||
while (m_timerData.size() < m_timerNames.size()) | ||
m_timerData.append(0); | ||
|
||
setSampleCount(static_cast<int>(m_timerNames.size()) + 1); | ||
if (!create()) | ||
{ | ||
LOG(VB_GENERAL, LOG_WARNING, m_name + "Failed to initialise OpenGL timers"); | ||
m_timersReady = false; | ||
return; | ||
} | ||
|
||
LOG(VB_GENERAL, LOG_INFO, m_name + QString("Created %1 GL timers- averaging over %2 samples") | ||
.arg(sampleCount()).arg(m_totalSamples)); | ||
} | ||
|
||
int MythOpenGLPerf::GetTimersRunning(void) | ||
{ | ||
return m_timersRunning; | ||
} | ||
|
||
void MythOpenGLPerf::RecordSample(void) | ||
{ | ||
if (m_timersReady && isCreated()) | ||
{ | ||
m_timersRunning++; | ||
recordSample(); | ||
} | ||
} | ||
|
||
void MythOpenGLPerf::LogSamples(void) | ||
{ | ||
if (!(isCreated() && isResultAvailable())) | ||
{ | ||
m_timersReady = false; | ||
return; | ||
} | ||
|
||
// retrieve the samples | ||
QVector<GLuint64> samples = waitForIntervals(); | ||
|
||
// ensure we have the correct number | ||
if (samples.size() != m_timerData.size()) | ||
{ | ||
LOG(VB_GENERAL, LOG_ERR, m_name + "Incorrect sample count %1 %2 %3"); | ||
reset(); | ||
m_timersRunning = 0; | ||
return; | ||
} | ||
|
||
// increment our running totals | ||
for (int i = 0; i < samples.size(); ++i) | ||
m_timerData[i] += samples[i]; | ||
m_sampleCount++; | ||
|
||
// log and reset when necessary | ||
if (m_sampleCount > m_totalSamples) | ||
{ | ||
m_sampleCount = 0; | ||
QStringList results; | ||
GLuint64 total = 0; | ||
for (int i = 0; i < m_timerData.size(); ++i) | ||
{ | ||
results.append(m_timerNames[i] + QString::number((m_timerData[i] / 1000000000.0) / m_totalSamples, '0', 4)); | ||
total += m_timerData[i]; | ||
m_timerData[i] = 0; | ||
} | ||
LOG(VB_GPU, LOG_INFO, m_name + results.join(" ") + | ||
QString(" Total fps: %1").arg(1000000000.0 / (static_cast<double>(total) / m_totalSamples))); | ||
} | ||
|
||
// clear timers | ||
m_timersReady = true; | ||
m_timersRunning = 0; | ||
reset(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#ifndef MYTHOPENGLPERF_H | ||
#define MYTHOPENGLPERF_H | ||
|
||
// Qt | ||
#include <QVector> | ||
#include <QOpenGLTimeMonitor> | ||
|
||
// MythTV | ||
#include "mythuiexp.h" | ||
|
||
class MUI_PUBLIC MythOpenGLPerf : public QOpenGLTimeMonitor | ||
{ | ||
public: | ||
MythOpenGLPerf(const QString &Name, QVector<QString> Names, int SampleCount = 30); | ||
void RecordSample (void); | ||
void LogSamples (void); | ||
int GetTimersRunning(void); | ||
|
||
private: | ||
QString m_name { }; | ||
int m_sampleCount { 0 }; | ||
int m_totalSamples { 30 }; | ||
bool m_timersReady { true }; | ||
int m_timersRunning { 0 }; | ||
QVector<GLuint64> m_timerData { 0 }; | ||
QVector<QString> m_timerNames { }; | ||
}; | ||
|
||
#endif // MYTHOPENGLPERF_H |