SLProject 4.0.000
ProfilerTimer Class Reference

A timer for profiling functions and scopes. More...

#include <Profiler.h>

Public Member Functions

 ProfilerTimer (const char *name)
 
 ~ProfilerTimer ()
 

Private Attributes

const char * _name
 
uint32_t _depth
 
std::chrono::time_point< std::chrono::high_resolution_clock > _startPoint
 
bool _running
 

Static Private Attributes

static constexpr uint32_t INVALID_THREAD_ID = -1
 
static thread_local uint32_t threadId = INVALID_THREAD_ID
 
static thread_local uint32_t threadDepth = 0
 

Friends

class Profiler
 

Detailed Description

A timer for profiling functions and scopes.

This class should be instantiated at the start of functions and scopes that should be profiled. The object will record the current time at it's construction and the current time at it's destruction (when the scope ends) and the depth in the call stack. The destructor automatically calls Profiler::instance().recordResult().

Constructor & Destructor Documentation

◆ ProfilerTimer()

ProfilerTimer::ProfilerTimer ( const char *  name)
explicit

Constructor for ProfilerTimer that saves the current time as the start time, the thread-local depth as the scope depth and increases the thread-local depth since we have just entered a scope. PROFILE_THREAD must be called in the current thread before this function or else the current thread can't be identified and the application exits.

Parameters
nameName of the scope

◆ ~ProfilerTimer()

ProfilerTimer::~ProfilerTimer ( )

Destructor for ProfilerTimer that creates a ProfilingResult with the scope name, the depth, the start time, the current time as the end time and the current thread ID. The ProfilingResult is then registered with the Profiler and the thread-local depth is decreased since we have just exited a scope.

Friends And Related Function Documentation

◆ Profiler

friend class Profiler
friend

Member Data Documentation

◆ _depth

uint32_t ProfilerTimer::_depth
private

◆ _name

const char* ProfilerTimer::_name
private

◆ _running

bool ProfilerTimer::_running
private

◆ _startPoint

std::chrono::time_point<std::chrono::high_resolution_clock> ProfilerTimer::_startPoint
private

◆ INVALID_THREAD_ID

constexpr uint32_t ProfilerTimer::INVALID_THREAD_ID = -1
staticconstexprprivate

◆ threadDepth

thread_local uint32_t ProfilerTimer::threadDepth = 0
staticprivate

◆ threadId

thread_local uint32_t ProfilerTimer::threadId = INVALID_THREAD_ID
staticprivate

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