SuperTuxKart
Classes | Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
Profiler Class Reference

class that allows run-time graphical profiling through the use of markers. More...

#include <profiler.hpp>

Classes

class  EventData
 The data for one event. More...
 
class  Marker
 
struct  ThreadData
 

Public Member Functions

void init ()
 It is split from the constructor so that it can be avoided allocating unnecessary memory when the profiler is never used (for example in no graphics).
 
void reset ()
 Reset profiling data held in memory, to allow starting a new clean profiling run.
 
void pushCPUMarker (const char *name="N/A", const video::SColor &color=video::SColor())
 Push a new marker that starts now.
 
void popCPUMarker ()
 Stop the last pushed marker.
 
void activate ()
 Switches the profiler on.
 
void desactivate ()
 Switches the profiler off and computes frametime analysis.
 
void synchronizeFrame ()
 Saves all data for the current frame, and starts the next frame in the circular buffer. More...
 
void draw ()
 Draw the markers.
 
void onClick (const core::vector2di &mouse_pos)
 Handle freeze/unfreeze.
 
void computeStableFPS ()
 To be called once the data for a report has been collected, computes the average FPS, and for each integer FPS value from 1 to 1000, the proportion of frames fast enough for this FPS value, the proportion of time spent in frames fast enough for this FPS value, as well as the proportion of total benchmark time spent waiting for a frame beyond the normal duration of a frame at this FPS value.
 
void startBenchmark ()
 
void writeToFile ()
 Saves the collected profile data to a file. More...
 
bool isFrozen () const
 
void setDrawing (bool drawing)
 
int getTotalFrametime ()
 
int getTotalFrames ()
 
int getFPSMetricsHigh ()
 
int getFPSMetricsMid ()
 
int getFPSMetricsLow ()
 

Private Types

enum  FreezeState { UNFROZEN , WAITING_FOR_FREEZE , FROZEN , WAITING_FOR_UNFREEZE }
 
typedef std::map< std::string, EventDataAllEventData
 The mapping of event names to the corresponding EventData.
 

Private Member Functions

int getThreadID ()
 Returns a unique index for a thread. More...
 
void drawBackground ()
 Helper to draw a white background.
 

Private Attributes

std::vector< ThreadDatam_all_threads_data
 Data structure containing all currently buffered markers. More...
 
std::vector< int > m_gpu_times
 Buffer for the GPU times (in ms).
 
std::atomic< int > m_threads_used
 Counts the threads used.
 
int m_current_frame
 Index of the current frame in the buffer.
 
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 that a synch is done which changes the current frame while another threaded uses this variable, or while a new thread is added.
 
std::vector< int > m_frame_times
 Stores the frame times (in µs), once FPS metrics are computed.
 
int m_total_frametime
 Stores the total duration of the frames analyzed (in µs), once FPS metrics are computed. More...
 
int m_total_frames
 Stores the frame count.
 
int m_slow_frames [MAX_ANALYZED_FPS]
 Store the count of slow frames for a given FPS value.
 
int m_time_spent_in_slow_frames [MAX_ANALYZED_FPS]
 Store time spent in slow frames for a given FPS value (in µs)
 
int m_time_waited_in_slow_frames [MAX_ANALYZED_FPS]
 Store time spent beyond the maximum duration of a frame for a given FPS value (in µs)
 
int m_fps_metrics_high
 Store the highest FPS with <50% time in slow frames and < 10% time waited beyond maximum duration.
 
int m_fps_metrics_mid
 Store the highest FPS with <12% time in slow frames and < 2% time waited beyond maximum duration.
 
int m_fps_metrics_low
 Store the highest FPS with < 1% time in slow frames and <0.1% time waited beyond maximum duration.
 
bool m_has_wrapped_around
 True if the circular buffer has wrapped around.
 
bool m_drawing
 True if the profiler UI should be rendered.
 
int m_max_frames
 The maximum number of frames to be buffered. More...
 
double m_time_last_sync
 Time of last sync. More...
 
double m_time_between_sync
 Time between now and last sync, used to scale the GUI bar.
 
std::vector< std::string > m_all_event_names
 List of all event names. More...
 
FreezeState m_freeze_state
 

Detailed Description

class that allows run-time graphical profiling through the use of markers.

Member Function Documentation

◆ getThreadID()

int Profiler::getThreadID ( )
private

Returns a unique index for a thread.

If the calling thread is not yet in the mapping, it will assign a new unique id to this thread.

◆ synchronizeFrame()

void Profiler::synchronizeFrame ( )

Saves all data for the current frame, and starts the next frame in the circular buffer.

Any events that are currently active (e.g. in a separate thread) will be split in two parts: the beginning (till now) in the current frame, the rest will be added to the next frame.

◆ writeToFile()

void Profiler::writeToFile ( )

Saves the collected profile data to a file.

Filename is based on the stdout name (with -profile appended).

Member Data Documentation

◆ m_all_event_names

std::vector<std::string> Profiler::m_all_event_names
private

List of all event names.

This list is sorted to make sure if the circular buffer is dumped more than once the order of events remains the same.

◆ m_all_threads_data

std::vector< ThreadData> Profiler::m_all_threads_data
private

Data structure containing all currently buffered markers.

The index is the thread id.

◆ m_max_frames

int Profiler::m_max_frames
private

The maximum number of frames to be buffered.

Used to minimise reallocations.

◆ m_time_last_sync

double Profiler::m_time_last_sync
private

Time of last sync.

All start/end times are stored relative to this time.

◆ m_total_frametime

int Profiler::m_total_frametime
private

Stores the total duration of the frames analyzed (in µs), once FPS metrics are computed.

Int overflow is not a concern unless more than 30 minutes of data is stored and analyzed.


The documentation for this class was generated from the following files: