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  struct timeval m_starttime {0,0};
66  bool m_starttimeValid {false};
67  QVector<uint> m_times; // array of cycle lengths, in uS
68  float m_lastFps {0};
69  float m_lastSd {0};
70  QString m_name;
71  QFile *m_cpuStat {nullptr};
72  unsigned long long *m_lastStats {nullptr};
73  QString m_lastCpuStats;
74 };
75 
76 #endif // JITTEROMETER_H
77 
78 
Jitterometer::m_numCycles
int m_numCycles
Definition: jitterometer.h:64
Jitterometer::Jitterometer
Jitterometer(const Jitterometer &)=delete
mythtvexp.h
Jitterometer::GetLastFPS
float GetLastFPS(void) const
Definition: jitterometer.h:53
Jitterometer::operator=
Jitterometer & operator=(const Jitterometer &)=delete
Jitterometer::m_starttime
Definition: jitterometer.h:65
Jitterometer::GetLastSD
float GetLastSD(void) const
Definition: jitterometer.h:54
Jitterometer
Definition: jitterometer.h:44
MTV_PUBLIC
#define MTV_PUBLIC
Definition: mythtvexp.h:15
Jitterometer::m_name
QString m_name
Definition: jitterometer.h:70
Jitterometer::m_times
QVector< uint > m_times
Definition: jitterometer.h:67
Jitterometer::GetLastCPUStats
QString GetLastCPUStats(void) const
Definition: jitterometer.h:55
Jitterometer::m_lastCpuStats
QString m_lastCpuStats
Definition: jitterometer.h:73