VoltAir
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Groups Pages
DebugMetricsMonitor.h
1 /*
2  * Copyright (C) 2014 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef DEBUGMETRICSMONITOR_H
18 #define DEBUGMETRICSMONITOR_H
19 
20 #include <QObject>
21 #include <QTime>
22 #include <QVariant>
23 
32 class DebugMetricsMonitor : public QObject {
33  Q_OBJECT
34 
39  Q_PROPERTY(float fps READ getFps NOTIFY fpsChanged)
54  Q_PROPERTY(float instantFps READ getInstantFps)
58 #ifdef DOXYGEN
59  Q_PROPERTY(long int memoryUsage READ getMemoryUsage NOTIFY memoryUsageChanged)
60 #else
61  Q_PROPERTY(long memoryUsage READ getMemoryUsage NOTIFY memoryUsageChanged)
62 #endif
63 
72  Q_PROPERTY(bool loggingMetrics READ isLoggingMetrics WRITE setLoggingMetrics
74 
75 public:
80  explicit DebugMetricsMonitor(QObject* parent = 0);
81 
85  float getFps() const { return mFps; }
89  int getFpsAverageWindowSizeMs() const { return mFpsAverageWindowSizeMs; }
94  void setFpsAverageWindowSizeMs(int value);
98  int getFpsRefreshIntervalMs() const { return mFpsRefreshIntervalMs; }
103  void setFpsRefreshIntervalMs(int value);
107  float getInstantFps() const { return mInstantFps; }
111  long getMemoryUsage() const { return mMemoryUsage; }
115  int getMemoryUsageRefreshIntervalMs() const { return mMemoryUsageRefreshIntervalMs; }
120  void setMemoryUsageRefreshIntervalMs(int value);
124  bool isLoggingMetrics() const { return mLoggingMetrics; }
129  void setLoggingMetrics(bool value);
130 
131 public slots:
137  void update();
138 
139 signals:
143  void fpsChanged();
155  void memoryUsageChanged();
163  void loggingMetricsChanged();
164 
165 private:
166  void updateFps();
167  void updateMemoryUsage();
168 
169  float mFps = 0.0f;
170  int mFpsAverageWindowSizeMs = 1000;
171  int mFpsRefreshIntervalMs = 100;
172  float mInstantFps = 0.0f;
173  QTime mFpsRefreshTime;
174  int mFpsCounterCount = 0;
175  QTime mFpsCounterTimer;
176  QTime mInstantFpsCounterTimer;
177 
178  long mMemoryUsage = 0;
179  int mMemoryUsageRefreshIntervalMs = 1000;
180  QTime mMemoryUsageRefreshTime;
181 
182  bool mLoggingMetrics = true;
183 };
184 
185 #endif // DEBUGMETRICSMONITOR_H
int getFpsRefreshIntervalMs() const
Returns fpsRefreshIntervalMs.
Definition: DebugMetricsMonitor.h:98
void fpsRefreshIntervalMsChanged()
Emitted when fpsRefreshIntervalMs changes.
void memoryUsageRefreshIntervalMsChanged()
Emitted when memoryUsageRefreshIntervalMs changes.
float instantFps
The most immediate, non-averaged measurement of the number of frames rendered per second that is upda...
Definition: DebugMetricsMonitor.h:54
float fps
Average number of frames rendered per second, averaged over fpsAverageWindowSizeMs milliseconds and u...
Definition: DebugMetricsMonitor.h:39
Tracks and provides mechanisms for reporting various debug metrics.
Definition: DebugMetricsMonitor.h:32
void setFpsRefreshIntervalMs(int value)
Sets fpsRefreshIntervalMs.
int getFpsAverageWindowSizeMs() const
Returns fpsAverageWindowSizeMs.
Definition: DebugMetricsMonitor.h:89
void setMemoryUsageRefreshIntervalMs(int value)
Sets memoryUsageRefreshIntervalMs.
void fpsChanged()
Emitted when fps changes.
void setFpsAverageWindowSizeMs(int value)
Sets fpsAverageWindowSizeMs.
int fpsAverageWindowSizeMs
Size of window, in milliseconds, over which to average fps.
Definition: DebugMetricsMonitor.h:44
long getMemoryUsage() const
Returns memoryUsage.
Definition: DebugMetricsMonitor.h:111
int getMemoryUsageRefreshIntervalMs() const
Returns memoryUsageRefreshIntervalMs.
Definition: DebugMetricsMonitor.h:115
DebugMetricsMonitor(QObject *parent=0)
Constructs a DebugMetricsMonitor.
long int memoryUsage
Amount of memory, in bytes, used by the application.
Definition: DebugMetricsMonitor.h:59
void memoryUsageChanged()
Emitted when memoryUsage changes.
bool isLoggingMetrics() const
Returns loggingMetrics.
Definition: DebugMetricsMonitor.h:124
float getInstantFps() const
Returns instantFps.
Definition: DebugMetricsMonitor.h:107
void loggingMetricsChanged()
Emitted when loggingMetrics changes.
int memoryUsageRefreshIntervalMs
Length of interval, in milliseconds, after which to refresh the memoryUsage metric.
Definition: DebugMetricsMonitor.h:67
void fpsAverageWindowSizeMsChanged()
Emitted when fpsAverageWindowSizeMs changes.
int fpsRefreshIntervalMs
Length of interval, in milliseconds, after which to refresh the fps metric.
Definition: DebugMetricsMonitor.h:49
bool loggingMetrics
Whether or not DebugMetricsMonitor logs debug information to qDebug.
Definition: DebugMetricsMonitor.h:73
QObject * parent() const
float getFps() const
Returns fps.
Definition: DebugMetricsMonitor.h:85
void setLoggingMetrics(bool value)
Sets loggingMetrics.
void update()
Updates the DebugMetricsMonitor metrics if more than their refresh interval times have passed since t...