MythTV  master
jitterometer.h
Go to the documentation of this file.
1 #ifndef JITTEROMETER_H
2 #define JITTEROMETER_H
3 
4 #include <QVector>
5 #include <QFile>
6 #include "mythtvexp.h"
7 
8 /* Jitterometer usage. There are 2 ways to use this:
9 ------------------------------------------------------------------
10 
11  1. Every 100 iterations of the for loop, RecordCycleTime() will
12  print a report about the mean time to execute the loop, and
13  the jitter in the recorded times.
14 
15  my_jmeter = new Jitterometer("forloop", 100);
16  for ( ) {
17  ... some stuff ...
18  my_jmeter->RecordCycleTime();
19  }
20 
21 -------------------------------------------------------------------
22 
23 2. Every 42 times Weird_Operation() is run, RecordEndTime() will
24  print a report about the mean time to do a Weird_Operation(), and
25  the jitter in the recorded times.
26 
27  beer = new Jitterometer("weird operation", 42);
28  for( ) {
29  ...
30  beer->RecordStartTime();
31  Weird_Operation();
32  beer->RecordEndTime();
33  ...
34  }
35 */
36 
38 {
39  public:
40  Jitterometer(const QString &nname, int ncycles = 0);
41  ~Jitterometer();
42 
43  float GetLastFPS(void) const { return m_last_fps; }
44  float GetLastSD(void) const { return m_last_sd; }
45  QString GetLastCPUStats(void) const { return m_lastcpustats; }
46  void SetNumCycles(int cycles);
47  bool RecordCycleTime();
48  void RecordStartTime();
49  bool RecordEndTime();
50  QString GetCPUStat(void);
51 
52  private:
53  Jitterometer(const Jitterometer &) = delete; // not copyable
54  Jitterometer &operator=(const Jitterometer &) = delete; // not copyable
55 
56  int m_count {0};
58  struct timeval m_starttime;
59  bool m_starttime_valid {false};
60  QVector<uint> m_times; // array of cycle lengths, in uS
61  float m_last_fps {0};
62  float m_last_sd {0};
63  QString m_name;
64  QFile *m_cpustat {nullptr};
65  unsigned long long *m_laststats {nullptr};
66  QString m_lastcpustats;
67 };
68 
69 #endif // JITTEROMETER_H
70 
71 
QString GetLastCPUStats(void) const
Definition: jitterometer.h:45
float GetLastFPS(void) const
Definition: jitterometer.h:43
QVector< uint > m_times
Definition: jitterometer.h:60
QString m_name
Definition: jitterometer.h:63
#define MTV_PUBLIC
Definition: mythtvexp.h:15
QString m_lastcpustats
Definition: jitterometer.h:66
float GetLastSD(void) const
Definition: jitterometer.h:44