ReXGlue SDK
Loading...
Searching...
No Matches
perf.h File Reference
#include <cstring>
#include <optional>
#include <string>
#include <string_view>
#include <rex/platform.h>
#include <rex/result.h>
#include <rex/types.h>
#include <tracy/Tracy.hpp>

Go to the source code of this file.

Classes

class  rex::platform::Profiler

Namespaces

namespace  rex
namespace  rex::platform

Macros

#define REX_PERF_APPLY(name, call)
#define REX_PERF_SET(name, value)
#define REX_PERF_INC(name)
#define REX_PERF_ADD(name, delta)
#define REX_PROFILE_SCOPE(name)
#define REX_PROFILE_SCOPE_TEXT(name, detail)
#define REX_PROFILE_THREAD(name)
#define REX_PROFILE_FIBER_ENTER(name)
#define REX_PROFILE_FIBER_LEAVE()
#define REX_PROFILE_PLOT(name, value)
#define REX_PROFILE_PLOT_F64(name, value)
#define REX_PROFILE_ALLOC(ptr, size)
#define REX_PROFILE_FREE(ptr)
#define REX_PROFILE_ALLOC_NAMED(ptr, size, pool)
#define REX_PROFILE_FREE_NAMED(ptr, pool)
#define REX_PROFILE_ALLOC_STACK(ptr, size, depth)
#define REX_PROFILE_FREE_STACK(ptr, depth)
#define REX_PROFILE_ALLOC_NAMED_STACK(ptr, size, depth, pool)
#define REX_PROFILE_FREE_NAMED_STACK(ptr, depth, pool)
#define REX_PROFILE_SCOPE_DYNAMIC(name)
#define REX_PROFILE_FRAME()
#define REX_PROFILE_IS_CONNECTED()

Enumerations

enum class  rex::platform::CounterID : u8 { kFrameTimeUs , kFps }
enum class  rex::platform::CounterType : u8 { rex::platform::kAccumulator , rex::platform::kGauge }

Functions

Result< CounterID > rex::platform::RegisterCounter (const char *name, CounterType type=CounterType::kAccumulator)
std::optional< CounterID > rex::platform::FindCounter (std::string_view name)
const char * rex::platform::GetCounterName (CounterID id)
void rex::platform::SetCounter (CounterID id, i64 value)
void rex::platform::IncrementCounter (CounterID id, i64 delta=1)
i64 rex::platform::GetCounter (CounterID id)
void rex::platform::ResetFrameCounters ()
i64 rex::platform::GetSnapshotCounter (CounterID id)
void rex::platform::InitCounters ()
void rex::platform::SetCSVLogPath (const std::string &path)
void rex::platform::WriteCSVFrame ()
void rex::platform::CloseCSV ()

Variables

constexpr size_t rex::platform::kMaxCounters = 64

Detailed Description

License
BSD 3-Clause License See LICENSE file in the project root for full license text.
Remarks
Derived from Xenia's xenia/base/debugging.h (Ben Vanik, 2014).

Macro Definition Documentation

◆ REX_PERF_ADD

#define REX_PERF_ADD ( name,
delta )
Value:
void IncrementCounter(CounterID id, i64 delta=1)
#define REX_PERF_APPLY(name, call)
Definition perf.h:108

Adds a delta to a perf counter. Compiles to nothing when counters are disabled.

Parameters
nameThe counter name in snake case, a string literal.
deltaThe signed amount to add.
REX_PERF_ADD("vertices_processed", vertex_count);
#define REX_PERF_ADD(name, delta)
Definition perf.h:151

◆ REX_PERF_APPLY

#define REX_PERF_APPLY ( name,
call )
Value:
do { \
static const auto rex_perf_found = ::rex::platform::FindCounter(name); \
if (rex_perf_found) { \
const ::rex::platform::CounterID rex_perf_id = *rex_perf_found; \
call; \
} \
} while (false)
std::optional< CounterID > FindCounter(std::string_view name)

Looks the counter up once per call site, then applies an operation. Does nothing when the name is not registered.

Parameters
nameThe snake case counter name, a string literal.
callThe operation, which sees the counter as rex_perf_id.

◆ REX_PERF_INC

#define REX_PERF_INC ( name)
Value:

Adds 1 to a perf counter. Compiles to nothing when counters are disabled.

Parameters
nameThe counter name in snake case, a string literal.
REX_PERF_INC("draw_calls");
#define REX_PERF_INC(name)
Definition perf.h:139

◆ REX_PERF_SET

#define REX_PERF_SET ( name,
value )
Value:
REX_PERF_APPLY(name, ::rex::platform::SetCounter(rex_perf_id, value))

Sets a perf counter to a value. Compiles to nothing when counters are disabled.

Parameters
nameThe counter name in snake case, a string literal.
valueEvaluated only when the counter exists.
REX_PERF_SET("fps", frames_per_second);
#define REX_PERF_SET(name, value)
Definition perf.h:127

◆ REX_PROFILE_ALLOC

#define REX_PROFILE_ALLOC ( ptr,
size )
Value:
do { \
if (TracyIsStarted) \
TracyAlloc(ptr, size); \
} while (0)

Reports an allocation to the unnamed Tracy memory pool.

Parameters
sizeThe size in bytes, evaluated only while the profiler runs.
REX_PROFILE_ALLOC(block, size);
#define REX_PROFILE_ALLOC(ptr, size)
Definition perf.h:308

◆ REX_PROFILE_ALLOC_NAMED

#define REX_PROFILE_ALLOC_NAMED ( ptr,
size,
pool )
Value:
do { \
if (TracyIsStarted) \
TracyAllocN(ptr, size, pool); \
} while (0)

Reports an allocation to a named Tracy memory pool.

Parameters
sizeThe size in bytes, evaluated only while the profiler runs.
poolThe pool name, a string literal or another pointer that stays valid and has the same value for every call of the pool.
REX_PROFILE_ALLOC_NAMED(block, size, "GPU");
#define REX_PROFILE_ALLOC_NAMED(ptr, size, pool)
Definition perf.h:338

◆ REX_PROFILE_ALLOC_NAMED_STACK

#define REX_PROFILE_ALLOC_NAMED_STACK ( ptr,
size,
depth,
pool )
Value:
do { \
if (TracyIsStarted) \
TracyAllocNS(ptr, size, depth, pool); \
} while (0)

Reports an allocation to a named pool with a call stack.

Parameters
sizeThe size in bytes, evaluated only while the profiler runs.
depthThe number of stack frames to capture, 0 captures none.
poolThe pool name, as for REX_PROFILE_ALLOC_NAMED.
REX_PROFILE_ALLOC_NAMED_STACK(block, size, 8, "GPU");
#define REX_PROFILE_ALLOC_NAMED_STACK(ptr, size, depth, pool)
Definition perf.h:401

◆ REX_PROFILE_ALLOC_STACK

#define REX_PROFILE_ALLOC_STACK ( ptr,
size,
depth )
Value:
do { \
if (TracyIsStarted) \
TracyAllocS(ptr, size, depth); \
} while (0)

Reports an allocation to the unnamed pool with a call stack.

Parameters
sizeThe size in bytes, evaluated only while the profiler runs.
depthThe number of stack frames to capture, 0 captures none.
REX_PROFILE_ALLOC_STACK(block, size, 8);
#define REX_PROFILE_ALLOC_STACK(ptr, size, depth)
Definition perf.h:369

◆ REX_PROFILE_FIBER_ENTER

#define REX_PROFILE_FIBER_ENTER ( name)
Value:
((void)sizeof(decltype(name)))

Disabled fiber macros without TRACY_FIBERS. The enter form only type checks its name.

Parameters
nameThe fiber name, never evaluated.
REX_PROFILE_FIBER_ENTER(fiber->name());
#define REX_PROFILE_FIBER_LEAVE()
Definition perf.h:264
#define REX_PROFILE_FIBER_ENTER(name)
Definition perf.h:256

◆ REX_PROFILE_FIBER_LEAVE

#define REX_PROFILE_FIBER_LEAVE ( )

Expands to nothing.

◆ REX_PROFILE_FRAME

#define REX_PROFILE_FRAME ( )
Value:
do { \
if (TracyIsStarted) \
FrameMark; \
} while (0)

Marks the end of a frame on the main Tracy frame track.

#define REX_PROFILE_FRAME()
Definition perf.h:444

◆ REX_PROFILE_FREE

#define REX_PROFILE_FREE ( ptr)
Value:
do { \
if (TracyIsStarted) \
TracyFree(ptr); \
} while (0)

Reports a free to the unnamed Tracy memory pool.

#define REX_PROFILE_FREE(ptr)
Definition perf.h:321

◆ REX_PROFILE_FREE_NAMED

#define REX_PROFILE_FREE_NAMED ( ptr,
pool )
Value:
do { \
if (TracyIsStarted) \
TracyFreeN(ptr, pool); \
} while (0)

Reports a free to a named Tracy memory pool.

Parameters
poolThe pool name given to REX_PROFILE_ALLOC_NAMED.
REX_PROFILE_FREE_NAMED(block, "GPU");
#define REX_PROFILE_FREE_NAMED(ptr, pool)
Definition perf.h:353

◆ REX_PROFILE_FREE_NAMED_STACK

#define REX_PROFILE_FREE_NAMED_STACK ( ptr,
depth,
pool )
Value:
do { \
if (TracyIsStarted) \
TracyFreeNS(ptr, depth, pool); \
} while (0)

Reports a free to a named pool with a call stack.

Parameters
depthThe number of stack frames to capture, 0 captures none.
poolThe pool name given to REX_PROFILE_ALLOC_NAMED_STACK.
#define REX_PROFILE_FREE_NAMED_STACK(ptr, depth, pool)
Definition perf.h:417

◆ REX_PROFILE_FREE_STACK

#define REX_PROFILE_FREE_STACK ( ptr,
depth )
Value:
do { \
if (TracyIsStarted) \
TracyFreeS(ptr, depth); \
} while (0)

Reports a free to the unnamed pool with a call stack.

Parameters
depthThe number of stack frames to capture, 0 captures none.
#define REX_PROFILE_FREE_STACK(ptr, depth)
Definition perf.h:384

◆ REX_PROFILE_IS_CONNECTED

#define REX_PROFILE_IS_CONNECTED ( )
Value:
(TracyIsStarted && TracyIsConnected)

Reports whether a Tracy profiler is connected.

Returns
True when a profiler is connected, always false without REXGLUE_ENABLE_PROFILING.
CaptureExtraStatistics();
}
#define REX_PROFILE_IS_CONNECTED()
Definition perf.h:461

◆ REX_PROFILE_PLOT

#define REX_PROFILE_PLOT ( name,
value )
Value:
do { \
if (TracyIsStarted) \
TracyPlot(name, static_cast<::rex::i64>(value)); \
} while (0)

Plots a value on a named Tracy graph.

Parameters
nameThe plot name, a string literal.
valueThe value, converted to a 64 bit integer.
REX_PROFILE_PLOT("GPU Queue Depth", queue.size());
#define REX_PROFILE_PLOT(name, value)
Definition perf.h:277

◆ REX_PROFILE_PLOT_F64

#define REX_PROFILE_PLOT_F64 ( name,
value )
Value:
do { \
if (TracyIsStarted) \
TracyPlot(name, static_cast<::rex::f64>(value)); \
} while (0)

Plots a floating point value on a named Tracy graph.

Parameters
nameThe plot name, a string literal.
valueThe value, converted to a 64 bit float.
REX_PROFILE_PLOT_F64("Frame Time", frame_seconds);
#define REX_PROFILE_PLOT_F64(name, value)
Definition perf.h:293

◆ REX_PROFILE_SCOPE

#define REX_PROFILE_SCOPE ( name)
Value:
ZoneNamedN(___tracy_cpu_zone, name, TracyIsStarted)

Opens a Tracy CPU zone that lasts until the end of the enclosing scope.

Parameters
nameThe zone name, a string literal.
REX_PROFILE_SCOPE("CommandProcessor::ExecutePacket");
#define REX_PROFILE_SCOPE(name)
Definition perf.h:186

◆ REX_PROFILE_SCOPE_DYNAMIC

#define REX_PROFILE_SCOPE_DYNAMIC ( name)
Value:
ZoneNamed(___tracy_cpu_zone_d, TracyIsStarted); \
const std::string_view ___tracy_zone_name_d = (name); \
ZoneNameV(___tracy_cpu_zone_d, ___tracy_zone_name_d.data(), ___tracy_zone_name_d.size())

Opens a Tracy CPU zone named at run time that lasts until the end of the enclosing scope.

Parameters
nameA std::string_view or std::string naming the zone, evaluated once.
REX_PROFILE_SCOPE_DYNAMIC(function->name());
#define REX_PROFILE_SCOPE_DYNAMIC(name)
Definition perf.h:432

◆ REX_PROFILE_SCOPE_TEXT

#define REX_PROFILE_SCOPE_TEXT ( name,
detail )
Value:
ZoneNamedN(___tracy_cpu_zone_i, name, TracyIsStarted); \
ZoneTextV(___tracy_cpu_zone_i, detail, std::strlen(detail))

Opens a Tracy CPU zone with a text annotation that lasts until the end of the enclosing scope.

Parameters
nameThe zone name, a string literal.
detailA null terminated string attached to the zone.
REX_PROFILE_SCOPE_TEXT("APU::SubmitFrame", client_name);
#define REX_PROFILE_SCOPE_TEXT(name, detail)
Definition perf.h:198

◆ REX_PROFILE_THREAD

#define REX_PROFILE_THREAD ( name)
Value:
do { \
if (TracyIsStarted) \
tracy::SetThreadName(name); \
} while (0)

Names the calling thread in the profiler.

Parameters
nameA null terminated thread name.
REX_PROFILE_THREAD("XMA Decoder");
#define REX_PROFILE_THREAD(name)
Definition perf.h:211