21 #include "utils/synchronised.hpp"
51 Q_COMBINE_DIFFUSE_COLOR,
69 double getTimeMilliseconds();
71 #define MAX_ANALYZED_FPS 1000
72 #define ENABLE_PROFILER
74 #ifdef ENABLE_PROFILER
75 #define PROFILER_PUSH_CPU_MARKER(name, r, g, b) \
76 profiler.pushCPUMarker(name, video::SColor(0xFF, r, g, b))
78 #define PROFILER_POP_CPU_MARKER() \
79 profiler.popCPUMarker()
81 #define PROFILER_SYNC_FRAME() \
82 profiler.synchronizeFrame()
84 #define PROFILER_DRAW() \
87 #define PROFILER_PUSH_CPU_MARKER(name, r, g, b)
88 #define PROFILER_POP_CPU_MARKER()
89 #define PROFILER_SYNC_FRAME()
90 #define PROFILER_DRAW()
120 Marker() { m_start = 0; m_duration = 0; m_layer = 0; }
123 Marker(
double start,
size_t layer=0)
124 : m_start(start), m_duration(0), m_layer(layer)
128 Marker(
const Marker& ref)
129 : m_start(ref.m_start), m_duration(ref.m_duration),
138 double getEnd()
const {
return m_start+m_duration; }
143 size_t getLayer()
const {
return m_layer; }
152 m_start = start; m_layer = layer;
158 m_duration += (end - m_start);
178 EventData(video::SColor colour,
int max_size)
180 m_all_markers.resize(max_size);
185 void setStart(
size_t frame,
double start,
int layer)
187 assert(frame < m_all_markers.capacity());
188 m_all_markers[frame].setStart(start, layer);
194 assert(frame < m_all_markers.capacity());
195 m_all_markers[frame].setEnd(end);
198 const Marker& getMarker(
int n)
const {
return m_all_markers[n]; }
199 Marker& getMarker(
int n) {
return m_all_markers[n]; }
257 int m_slow_frames[MAX_ANALYZED_FPS];
260 int m_time_spent_in_slow_frames[MAX_ANALYZED_FPS];
263 int m_time_waited_in_slow_frames[MAX_ANALYZED_FPS];
302 WAITING_FOR_UNFREEZE,
305 FreezeState m_freeze_state;
309 void drawBackground();
316 void pushCPUMarker(
const char* name=
"N/A",
317 const video::SColor& color=video::SColor());
321 void synchronizeFrame();
323 void onClick(
const core::vector2di& mouse_pos);
324 void computeStableFPS();
325 void startBenchmark();
329 bool isFrozen()
const {
return m_freeze_state == FROZEN; }
331 void setDrawing(
bool drawing) { m_drawing = drawing; }
333 int getTotalFrametime() {
return m_total_frametime; }
334 int getTotalFrames() {
return m_total_frames; }
335 int getFPSMetricsHigh() {
return m_fps_metrics_high; }
336 int getFPSMetricsMid() {
return m_fps_metrics_mid; }
337 int getFPSMetricsLow() {
return m_fps_metrics_low; }
The data for one event.
Definition: profiler.hpp:168
void setStart(size_t frame, double start, int layer)
Records the start of an event for a given frame.
Definition: profiler.hpp:185
std::vector< Marker > m_all_markers
Vector of all buffered markers.
Definition: profiler.hpp:174
video::SColor getColour() const
Returns the colour for this event.
Definition: profiler.hpp:202
video::SColor m_colour
Colour to use in the on-screen display.
Definition: profiler.hpp:171
void setEnd(size_t frame, double end)
Records the end of an event for a given frame.
Definition: profiler.hpp:192
Definition: profiler.hpp:105
void setStart(double start, size_t layer=0)
Sets start time and layer for this event.
Definition: profiler.hpp:150
double m_start
An event that is started (pushed) stores the start time in this variable.
Definition: profiler.hpp:109
double m_duration
Duration of the event in this frame (accumulated if this event should be recorded more than once).
Definition: profiler.hpp:114
double getEnd() const
Returns the end time of this event marker.
Definition: profiler.hpp:138
double getDuration() const
Returns the duration of this event.
Definition: profiler.hpp:141
double getStart() const
Returns the start time of this event marker.
Definition: profiler.hpp:135
void setEnd(double end)
Sets the end time of this event.
Definition: profiler.hpp:156
size_t m_layer
Distance of marker from root (for nested events), used to adjust vertical height when drawing.
Definition: profiler.hpp:117
void clear()
Called when an entry in the cyclic buffer is reused.
Definition: profiler.hpp:147
class that allows run-time graphical profiling through the use of markers.
Definition: profiler.hpp:101
std::vector< int > m_gpu_times
Buffer for the GPU times (in ms).
Definition: profiler.hpp:231
int m_fps_metrics_mid
Store the highest FPS with <12% time in slow frames and < 2% time waited beyond maximum duration.
Definition: profiler.hpp:269
double m_time_between_sync
Time between now and last sync, used to scale the GUI bar.
Definition: profiler.hpp:289
std::vector< ThreadData > m_all_threads_data
Data structure containing all currently buffered markers.
Definition: profiler.hpp:228
std::vector< std::string > m_all_event_names
List of all event names.
Definition: profiler.hpp:294
Synchronised< bool > m_lock
We don't need the bool, but easiest way to get a lock for the whole instance (since we need to avoid ...
Definition: profiler.hpp:243
int m_fps_metrics_low
Store the highest FPS with < 1% time in slow frames and <0.1% time waited beyond maximum duration.
Definition: profiler.hpp:272
int m_total_frames
Stores the frame count.
Definition: profiler.hpp:254
bool m_drawing
True if the profiler UI should be rendered.
Definition: profiler.hpp:278
std::map< std::string, EventData > AllEventData
The mapping of event names to the corresponding EventData.
Definition: profiler.hpp:208
int m_max_frames
The maximum number of frames to be buffered.
Definition: profiler.hpp:282
int m_fps_metrics_high
Store the highest FPS with <50% time in slow frames and < 10% time waited beyond maximum duration.
Definition: profiler.hpp:266
double m_time_last_sync
Time of last sync.
Definition: profiler.hpp:286
std::atomic< int > m_threads_used
Counts the threads used.
Definition: profiler.hpp:234
int m_current_frame
Index of the current frame in the buffer.
Definition: profiler.hpp:237
bool m_has_wrapped_around
True if the circular buffer has wrapped around.
Definition: profiler.hpp:275
int m_total_frametime
Stores the total duration of the frames analyzed (in µs), once FPS metrics are computed.
Definition: profiler.hpp:251
std::vector< int > m_frame_times
Stores the frame times (in µs), once FPS metrics are computed.
Definition: profiler.hpp:246
Definition: profiler.hpp:211
std::vector< std::string > m_ordered_headings
This stores the event names in the order in which they occur.
Definition: profiler.hpp:219
std::vector< std::string > m_event_stack
Stack of events to detect nesting.
Definition: profiler.hpp:213