Start

Theory

Reference

Examples

← All examples
Profiling · Tooling

Scoped Profiler

Nested scope timing

Times nested code paths with PROFILE_SCOPE, showing that scopes can nest inside each other the same way a real per-frame Update() would, then prints the resulting timing tree.

ProfilingTooling
console example — no window, see captured output below

Sample output

scoped_profiler output
-- Summary after 5 frames --
[INFO][20:35:50.199][LogSummary] [TimingProfiler] FrameUpdate — calls: 5, avg: 29735920ns, min: 21817700ns, max: 32020400ns
[INFO][20:35:50.200][LogSummary] [TimingProfiler] FastOperation — calls: 5, avg: 13886280ns, min: 6636000ns, max: 16007300ns
[INFO][20:35:50.200][LogSummary] [TimingProfiler] SlowOperation — calls: 5, avg: 15843240ns, min: 15166000ns, max: 16023100ns
-- Summary after ResetAll (buckets are empty, nothing logged) --

Run it yourself

build just this example
cmake --build --preset windows-debug --target scoped_profiler
# binary lands under bin/ (e.g. bin/Debug/scoped_profiler.exe on Windows)

See Installation for the full build setup.

Source

examples/scoped_profiler/main.cpp
#include <chrono>
#include <iostream>
#include <thread>
#include <ASGE/Core/Profiling/ScopedTimer.hpp>

using namespace asge::profiling;

namespace
{

void FastOperation()
{
    PROFILE_SCOPE("FastOperation");
    std::this_thread::sleep_for( std::chrono::milliseconds(1) );
}

void SlowOperation()
{
    PROFILE_SCOPE("SlowOperation");
    std::this_thread::sleep_for( std::chrono::milliseconds(10) );
}

void FrameUpdate()
{
    // A scope can wrap other scopes, just like a real per-frame update would.
    PROFILE_SCOPE("FrameUpdate");
    FastOperation();
    SlowOperation();
}

}

int main()
{
    constexpr int frames = 5;

    for ( int frame = 0; frame < frames; ++frame )
    {
        FrameUpdate();
    }

    std::cout << "-- Summary after " << frames << " frames --" << std::endl;
    TimingProfiler::Instance().LogSummary();

    TimingProfiler::Instance().ResetAll();

    std::cout << "-- Summary after ResetAll (buckets are empty, nothing logged) --" << std::endl;
    TimingProfiler::Instance().LogSummary();

    return 0;
}

Browse the full example on GitHub →