MythTV master
mythopenglperf.cpp
Go to the documentation of this file.
1// C++
2#include <utility>
3
4// MythTV
6#include "mythopenglperf.h"
7
8
13 QVector<QString> Names,
14 int SampleCount)
15 : m_name(std::move(Name)),
16 m_totalSamples(SampleCount),
17 m_timerNames(std::move(Names))
18{
19 while (m_timerData.size() < m_timerNames.size())
20 m_timerData.append(0);
21
22 setSampleCount(m_timerNames.size() + 1);
23 if (!create())
24 {
25 LOG(VB_GENERAL, LOG_WARNING, m_name + "Failed to initialise OpenGL timers");
26 m_timersReady = false;
27 return;
28 }
29
30 LOG(VB_GENERAL, LOG_INFO, m_name + QString("Created %1 GL timers- averaging over %2 samples")
31 .arg(sampleCount()).arg(m_totalSamples));
32}
33
35{
36 return m_timersRunning;
37}
38
40{
41 if (m_timersReady && isCreated())
42 {
44 recordSample();
45 }
46}
47
49{
50 if (!(isCreated() && isResultAvailable()))
51 {
52 m_timersReady = false;
53 return;
54 }
55
56 // retrieve the samples
57 QVector<GLuint64> samples = waitForIntervals();
58
59 // ensure we have the correct number
60 if (samples.size() != m_timerData.size())
61 {
62 LOG(VB_GENERAL, LOG_ERR, m_name + "Incorrect sample count %1 %2 %3");
63 reset();
65 return;
66 }
67
68 // increment our running totals
69 for (int i = 0; i < samples.size(); ++i)
70 m_timerData[i] += samples[i];
72
73 // log and reset when necessary
75 {
76 QStringList results;
77 GLuint64 total = 0;
78 for (int i = 0; i < m_timerData.size(); ++i)
79 {
80 results.append(m_timerNames[i] + QString::number((m_timerData[i] / 1000000000.0) / m_sampleCount, '0', 4));
81 total += m_timerData[i];
82 m_timerData[i] = 0;
83 }
84 LOG(VB_GPUVIDEO, LOG_INFO, m_name + results.join(" ") +
85 QString(" Total fps: %1").arg(1000000000.0 / (static_cast<double>(total) / m_sampleCount)));
86 m_sampleCount = 0;
87 }
88
89 // clear timers
90 m_timersReady = true;
92 reset();
93}
void RecordSample(void)
QVector< GLuint64 > m_timerData
MythOpenGLPerf(QString Name, QVector< QString > Names, int SampleCount=30)
int GetTimersRunning(void) const
QVector< QString > m_timerNames
void LogSamples(void)
static const std::array< const uint64_t, 4 > samples
Definition: element.cpp:46
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
STL namespace.