Helios Engine
A modular ECS based data-oriented C++23 game engine framework
Loading...
Searching...
No Matches
helios::profile::FlamegraphBackend Class Referencefinal

Profiling backend that emits a Chrome Tracing JSON file. More...

#include <flamegraph.hpp>

Inheritance diagram for helios::profile::FlamegraphBackend:
helios::profile::Backend

Public Member Functions

 FlamegraphBackend (FlamegraphBackendConfig config={}) noexcept
 Constructs with a custom configuration.
 FlamegraphBackend (const FlamegraphBackend &)=delete
 FlamegraphBackend (FlamegraphBackend &&)=delete
 ~FlamegraphBackend () noexcept override=default
FlamegraphBackendoperator= (const FlamegraphBackend &)=delete
FlamegraphBackendoperator= (FlamegraphBackend &&)=delete
size_t ZoneStorageSize () const noexcept override
 Returns the per-zone storage size in bytes.
void Startup () noexcept override
 Opens the output file and writes the JSON array prologue.
void Shutdown () noexcept override
 Flushes all remaining events, writes the JSON array epilogue, and closes the output file.
void BeginZone (const ZoneSpec &spec, std::span< std::byte > storage) noexcept override
 Records the start of an instrumented zone.
void EndZone (std::span< std::byte > storage) noexcept override
 Records the end of an instrumented zone and enqueues a completed event.
void ZoneText (std::span< std::byte > storage, std::string_view text) noexcept override
 Attaches a text annotation to the active zone.
void ZoneValue (std::span< std::byte > storage, uint64_t value) noexcept override
 Attaches a numeric value to the active zone.
void ZoneName (std::span< std::byte > storage, std::string_view name) noexcept override
 Overrides the name of the active zone.
void FrameMark () noexcept override
 Enqueues an unnamed frame-mark instant event.
void FrameMark (CStringView name) noexcept override
 Enqueues a named frame-mark instant event.
void FrameMarkStart (CStringView name) noexcept override
 Enqueues a frame-region-start instant event.
void FrameMarkEnd (CStringView name) noexcept override
 Enqueues a frame-region-end instant event.
void Message (std::string_view text, uint32_t color) noexcept override
 Enqueues a message as an instant event.
void SetThreadName (CStringView) noexcept override
 Thread name events are not emitted in the JSON format.
void Plot (CStringView name, double value) noexcept override
 Enqueues a counter (plot) event with the given value.
void PlotConfig (CStringView, PlotFormat, bool, bool, uint32_t) noexcept override
 Plot configuration is not represented in the JSON format.
void Alloc (const void *, size_t, std::optional< CStringView >, int, std::source_location) noexcept override
 Memory allocation events are not emitted in the JSON format.
void Free (const void *, std::optional< CStringView >, int, std::source_location) noexcept override
 Memory deallocation events are not emitted in the JSON format.
void MemoryDiscard (CStringView) noexcept override
 Memory discard events are not emitted in the JSON format.
void MemoryDiscard (CStringView, int) noexcept override
 Memory discard events are not emitted in the JSON format.
std::string_view Name () const noexcept override
 Returns the backend identifier.
Public Member Functions inherited from helios::profile::Backend
virtual ~Backend () noexcept=default

Detailed Description

Profiling backend that emits a Chrome Tracing JSON file.

Collects zone begin/end, instant, and counter events into a lock-free concurrent queue. Batched JSON output is written to disk periodically (controlled by FlamegraphBackendConfig::flush_threshold) or at shutdown. The resulting file is compatible with about://tracing in Chromium-based browsers and https://ui.perfetto.dev.

Definition at line 48 of file flamegraph.hpp.

Constructor & Destructor Documentation

◆ FlamegraphBackend() [1/3]

helios::profile::FlamegraphBackend::FlamegraphBackend ( FlamegraphBackendConfig config = {})
inlineexplicitnoexcept

Constructs with a custom configuration.

Parameters
configConfiguration for output path and flush threshold

Definition at line 54 of file flamegraph.hpp.

◆ FlamegraphBackend() [2/3]

helios::profile::FlamegraphBackend::FlamegraphBackend ( const FlamegraphBackend & )
delete

◆ FlamegraphBackend() [3/3]

helios::profile::FlamegraphBackend::FlamegraphBackend ( FlamegraphBackend && )
delete

◆ ~FlamegraphBackend()

helios::profile::FlamegraphBackend::~FlamegraphBackend ( )
overridedefaultnoexcept

Member Function Documentation

◆ Alloc()

void helios::profile::FlamegraphBackend::Alloc ( const void * ,
size_t ,
std::optional< CStringView > ,
int ,
std::source_location  )
inlineoverridevirtualnoexcept

Memory allocation events are not emitted in the JSON format.

Parameters
ptrPointer to allocated memory
sizeAllocation size in bytes
nameOptional pool name
depthCallstack depth
locSource location of the allocation

Implements helios::profile::Backend.

Definition at line 192 of file flamegraph.hpp.

◆ BeginZone()

void helios::profile::FlamegraphBackend::BeginZone ( const ZoneSpec & spec,
std::span< std::byte > storage )
overridevirtualnoexcept

Records the start of an instrumented zone.

Stores the zone name and start timestamp in the per-zone storage slice allocated by the Profiler.

Parameters
specZone specification (name, source location, etc.)
storagePer-zone byte slice for this backend

Implements helios::profile::Backend.

Definition at line 55 of file flamegraph.cpp.

◆ EndZone()

void helios::profile::FlamegraphBackend::EndZone ( std::span< std::byte > storage)
overridevirtualnoexcept

Records the end of an instrumented zone and enqueues a completed event.

Computes the duration, destroys the zone state, and pushes a CompleteEvent into the lock-free queue. May trigger a batch flush if the queue size exceeds flush_threshold.

Parameters
storagePer-zone byte slice for this backend

Implements helios::profile::Backend.

Definition at line 63 of file flamegraph.cpp.

◆ FrameMark() [1/2]

void helios::profile::FlamegraphBackend::FrameMark ( )
overridevirtualnoexcept

Enqueues an unnamed frame-mark instant event.

Implements helios::profile::Backend.

Definition at line 107 of file flamegraph.cpp.

◆ FrameMark() [2/2]

void helios::profile::FlamegraphBackend::FrameMark ( CStringView name)
overridevirtualnoexcept

Enqueues a named frame-mark instant event.

Parameters
nameFrame marker name

Implements helios::profile::Backend.

Definition at line 117 of file flamegraph.cpp.

◆ FrameMarkEnd()

void helios::profile::FlamegraphBackend::FrameMarkEnd ( CStringView name)
overridevirtualnoexcept

Enqueues a frame-region-end instant event.

Parameters
nameFrame region name

Implements helios::profile::Backend.

Definition at line 137 of file flamegraph.cpp.

◆ FrameMarkStart()

void helios::profile::FlamegraphBackend::FrameMarkStart ( CStringView name)
overridevirtualnoexcept

Enqueues a frame-region-start instant event.

Parameters
nameFrame region name

Implements helios::profile::Backend.

Definition at line 127 of file flamegraph.cpp.

◆ Free()

void helios::profile::FlamegraphBackend::Free ( const void * ,
std::optional< CStringView > ,
int ,
std::source_location  )
inlineoverridevirtualnoexcept

Memory deallocation events are not emitted in the JSON format.

Parameters
ptrPointer to freed memory
nameOptional pool name
depthCallstack depth
locSource location of the deallocation

Implements helios::profile::Backend.

Definition at line 203 of file flamegraph.hpp.

◆ MemoryDiscard() [1/2]

void helios::profile::FlamegraphBackend::MemoryDiscard ( CStringView )
inlineoverridevirtualnoexcept

Memory discard events are not emitted in the JSON format.

Parameters
namePool name

Implements helios::profile::Backend.

Definition at line 210 of file flamegraph.hpp.

◆ MemoryDiscard() [2/2]

void helios::profile::FlamegraphBackend::MemoryDiscard ( CStringView ,
int  )
inlineoverridevirtualnoexcept

Memory discard events are not emitted in the JSON format.

Parameters
namePool name
depthCallstack depth

Implements helios::profile::Backend.

Definition at line 217 of file flamegraph.hpp.

◆ Message()

void helios::profile::FlamegraphBackend::Message ( std::string_view text,
uint32_t color )
overridevirtualnoexcept

Enqueues a message as an instant event.

Parameters
textMessage text
colorDisplay color (unused in JSON output)

Implements helios::profile::Backend.

Definition at line 147 of file flamegraph.cpp.

◆ Name()

std::string_view helios::profile::FlamegraphBackend::Name ( ) const
inlinenodiscardoverridevirtualnoexcept

Returns the backend identifier.

Returns
"flamegraph"

Implements helios::profile::Backend.

Definition at line 223 of file flamegraph.hpp.

◆ operator=() [1/2]

FlamegraphBackend & helios::profile::FlamegraphBackend::operator= ( const FlamegraphBackend & )
delete

◆ operator=() [2/2]

FlamegraphBackend & helios::profile::FlamegraphBackend::operator= ( FlamegraphBackend && )
delete

◆ Plot()

void helios::profile::FlamegraphBackend::Plot ( CStringView name,
double value )
overridevirtualnoexcept

Enqueues a counter (plot) event with the given value.

Emitted as a Chrome Tracing counter event (ph: "C").

Parameters
nameCounter name
valueNumeric value

Implements helios::profile::Backend.

Definition at line 158 of file flamegraph.cpp.

◆ PlotConfig()

void helios::profile::FlamegraphBackend::PlotConfig ( CStringView ,
PlotFormat ,
bool ,
bool ,
uint32_t  )
inlineoverridevirtualnoexcept

Plot configuration is not represented in the JSON format.

Parameters
nameCounter name
typePlot format type
stepWhether to use step interpolation
fillWhether to fill the area
colorDisplay color

Implements helios::profile::Backend.

Definition at line 181 of file flamegraph.hpp.

◆ SetThreadName()

void helios::profile::FlamegraphBackend::SetThreadName ( CStringView )
inlineoverridevirtualnoexcept

Thread name events are not emitted in the JSON format.

Parameters
nameThread name

Implements helios::profile::Backend.

Definition at line 163 of file flamegraph.hpp.

◆ Shutdown()

void helios::profile::FlamegraphBackend::Shutdown ( )
overridevirtualnoexcept

Flushes all remaining events, writes the JSON array epilogue, and closes the output file.

Warning
Not thread-safe. Call during single-threaded shutdown.

Reimplemented from helios::profile::Backend.

Definition at line 47 of file flamegraph.cpp.

◆ Startup()

void helios::profile::FlamegraphBackend::Startup ( )
overridevirtualnoexcept

Opens the output file and writes the JSON array prologue.

Warning
Not thread-safe. Call during single-threaded startup after Finalize().

Reimplemented from helios::profile::Backend.

Definition at line 37 of file flamegraph.cpp.

◆ ZoneName()

void helios::profile::FlamegraphBackend::ZoneName ( std::span< std::byte > storage,
std::string_view name )
overridevirtualnoexcept

Overrides the name of the active zone.

The new name is used in the emitted JSON event.

Parameters
storagePer-zone byte slice for this backend
nameNew zone name

Implements helios::profile::Backend.

Definition at line 101 of file flamegraph.cpp.

◆ ZoneStorageSize()

size_t helios::profile::FlamegraphBackend::ZoneStorageSize ( ) const
nodiscardoverridevirtualnoexcept

Returns the per-zone storage size in bytes.

Returns
Byte count (aligned to std::max_align_t) needed for the internal ZoneState.

Implements helios::profile::Backend.

Definition at line 30 of file flamegraph.cpp.

◆ ZoneText()

void helios::profile::FlamegraphBackend::ZoneText ( std::span< std::byte > storage,
std::string_view text )
overridevirtualnoexcept

Attaches a text annotation to the active zone.

Parameters
storagePer-zone byte slice for this backend
textText to attach

Implements helios::profile::Backend.

Definition at line 87 of file flamegraph.cpp.

◆ ZoneValue()

void helios::profile::FlamegraphBackend::ZoneValue ( std::span< std::byte > storage,
uint64_t value )
overridevirtualnoexcept

Attaches a numeric value to the active zone.

Parameters
storagePer-zone byte slice for this backend
valueNumeric value to attach

Implements helios::profile::Backend.

Definition at line 94 of file flamegraph.cpp.