MythTV  master
mythopenglperf.cpp
Go to the documentation of this file.
1 // C++
2 #include <utility>
3 
4 // MythTV
5 #include "mythlogging.h"
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(static_cast<int>(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();
64  m_timersRunning = 0;
65  return;
66  }
67 
68  // increment our running totals
69  for (int i = 0; i < samples.size(); ++i)
70  m_timerData[i] += samples[i];
71  m_sampleCount++;
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;
91  m_timersRunning = 0;
92  reset();
93 }
MythOpenGLPerf::m_totalSamples
int m_totalSamples
Definition: mythopenglperf.h:48
MythOpenGLPerf::m_timersReady
bool m_timersReady
Definition: mythopenglperf.h:49
samples
static uint64_t samples[4]
Definition: element.cpp:45
arg
arg(title).arg(filename).arg(doDelete))
MythOpenGLPerf::GetTimersRunning
int GetTimersRunning(void) const
Definition: mythopenglperf.cpp:34
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:23
MythOpenGLPerf::LogSamples
void LogSamples(void)
Definition: mythopenglperf.cpp:48
MythOpenGLPerf::m_timerNames
QVector< QString > m_timerNames
Definition: mythopenglperf.h:52
MythOpenGLPerf::MythOpenGLPerf
MythOpenGLPerf(QString Name, QVector< QString > Names, int SampleCount=30)
Definition: mythopenglperf.cpp:12
hardwareprofile.os_detect.results
results
Definition: os_detect.py:296
mythlogging.h
mythopenglperf.h
MythOpenGLPerf::m_timersRunning
int m_timersRunning
Definition: mythopenglperf.h:50
MythOpenGLPerf::m_sampleCount
int m_sampleCount
Definition: mythopenglperf.h:47
m_name
const char * m_name
Definition: ParseText.cpp:329
Name
Definition: channelsettings.cpp:47
MythOpenGLPerf::RecordSample
void RecordSample(void)
Definition: mythopenglperf.cpp:39
MythOpenGLPerf::m_timerData
QVector< GLuint64 > m_timerData
Definition: mythopenglperf.h:51
MythOpenGLPerf::m_name
QString m_name
Definition: mythopenglperf.h:46