SuperTuxKart
Loading...
Searching...
No Matches
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 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 toggleStatus ()
 Switches the profiler either on or off.
 
void synchronizeFrame ()
 Saves all data for the current frame, and starts the next frame in the circular buffer.
 
void draw ()
 Draw the markers.
 
void onClick (const core::vector2di &mouse_pos)
 Handle freeze/unfreeze.
 
void writeToFile ()
 Saves the collected profile data to a file.
 
bool isFrozen () const
 

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.
 
void drawBackground ()
 Helper to draw a white background.
 

Private Attributes

std::vector< ThreadDatam_all_threads_data
 Data structure containing all currently buffered markers.
 
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.
 
bool m_has_wrapped_around
 True if the circular buffer has wrapped around.
 
int m_max_frames
 The maximum number of frames to be buffered.
 
double m_time_last_sync
 Time of last sync.
 
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.
 
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.


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