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