Magnum::DebugTools::Profiler class


Measures time passed during specified sections of each frame. It's meant to be used in rendering and event loops (e.g. Platform::Sdl2Application::drawEvent()), but it's possible to use it standalone elsewhere. Example usage:

DebugTools::Profiler p;

// Register named sections
struct {
    DebugTools::Profiler::Section ai, physics, draw, bufferSwap;
} sections; = p.addSection("AI");
sections.physics = p.addSection("Physics");
sections.draw = p.addSection("Drawing");
sections.bufferSwap = p.addSection("Buffer swap");

// Enable profiling

// Mark sections in draw function
void MyApplication::drawEvent() {

    // ... misc stuff belonging to "Other" section


    // ... AI computation


    // ... physics simulation





    // Count everything before next call to drawEvent() into "Other" section

    // Mark start of next frame

// Print statistics to debug output, showing how much time each section took

It's possible to start profiler only for certain parts of the code and then stop it again using stop(), if you are not interested in profiling the rest.

Public types

using Section = UnsignedInt
Section ID.

Public static variables

static const Section otherSection
Default section.

Public functions

void setMeasureDuration(std::size_t frames)
Set measure duration.
auto addSection(const std::string& name) -> Section
Add named section.
auto isEnabled() -> bool
Whether profiling is enabled.
void enable()
Enable profiling.
void disable()
Disable profiling.
void start(Section section)
Start profiling of given named section.
void start()
Start profiling of "other" section.
void stop()
Stop profiling.
void nextFrame()
Save data from previous frame and advance to another.
void printStatistics()
Print statistics.

Typedef documentation

typedef UnsignedInt Magnum::DebugTools::Profiler::Section

Section ID.

Function documentation

void Magnum::DebugTools::Profiler::setMeasureDuration(std::size_t frames)

Set measure duration.

Measured data are averaged through given frame count. Default value is 60.

Section Magnum::DebugTools::Profiler::addSection(const std::string& name)

Add named section.

bool Magnum::DebugTools::Profiler::isEnabled()

Whether profiling is enabled.

If the profiling is not enabled, calls to start() and stop() have no effect.

void Magnum::DebugTools::Profiler::enable()

Enable profiling.

Clears already mesaured data.

void Magnum::DebugTools::Profiler::disable()

Disable profiling.

void Magnum::DebugTools::Profiler::start(Section section)

Start profiling of given named section.

If profiling is already running, current time is saved for previous section.

void Magnum::DebugTools::Profiler::start()

Start profiling of "other" section.

Same as calling start(DebugTools::Profiler::otherSection).

void Magnum::DebugTools::Profiler::stop()

Stop profiling.

Current time is saved for previous section.

void Magnum::DebugTools::Profiler::nextFrame()

Save data from previous frame and advance to another.

Call at the end of each frame.

void Magnum::DebugTools::Profiler::printStatistics()

Print statistics.

Prints statistics about previous frame ordered by duration.

Variable documentation

static const Section Magnum::DebugTools::Profiler::otherSection

Default section.