Open 3D Engine AzCore API Reference 23.10.0
O3DE is an open-source, fully-featured, high-fidelity, modular 3D engine for building games and simulations, available to every industry.
AZ::Statistics::StatisticalProfiler< StatIdType, MutexType > Class Template Reference

#include <StatisticalProfiler.h>

Classes

struct  StatisticalAggregate
 
class  TimedScope
 

Public Member Functions

 StatisticalProfiler (const StatisticalProfiler &other)
 
 StatisticalProfiler (StatisticalProfiler &&other)
 
AZ::Statistics::StatisticsManager< StatIdType > & GetStatsManager ()
 
double SummarizePerFrameStats ()
 
void LogAndResetStats (const char *windowName)
 
void PushSample (const StatIdType &statId, double value)
 
const AZ::Statistics::NamedRunningStatisticGetStatistic (const StatIdType &statId)
 
int AddPerFrameStatisticalAggregate (const AZStd::vector< StatIdType > &statIds, const StatIdType &timePerFrameStatId, const AZStd::string &timePerFrameStatName)
 
const AZ::Statistics::NamedRunningStatisticGetFirstStatPerFrame () const
 

Protected Attributes

MutexType m_mutex
 Lock this before reading/writing to m_timeStatisticsManager, or else...
 
AZ::Statistics::StatisticsManager< StatIdType > m_statisticsManager
 
AZStd::vector< AZ::Statistics::NamedRunningStatistic * > m_statsVector
 
AZStd::vector< StatisticalAggregatem_perFrameAggregates
 

Friends

class TimedScope
 

Detailed Description

template<class StatIdType = AZStd::string, class MutexType = AZ::NullMutex>
class AZ::Statistics::StatisticalProfiler< StatIdType, MutexType >

A helper class that facilitates collecting time spent in blocks (scopes) of code and aggregating the measured times as running statistics.

See "StatisticalProfilerProxy.h" for more explanations on the meaning of Statistical Profiling.

The StatisticalProfiler was made as a template to accommodate for several performance needs... If all the code that is being profiled is single threaded and you want to identify each statistic by its string name, then the default StatisticalProfiler<> works for you. If using a map<strings, stat> is too much of what you can afford, then index your statistics with an integer or crc32 and your code profiler should be declared as StatisticalProfiler<AZ::Crc32>. For multi-threaded cases and indexing statistic with Crc32 you can have a profiler like this: StatisticalProfiler<AZ::Crc32, AZStd::mutex>. The UnitTests mentioned in the first paragraph do benchmarks of different combinations of indexing and synchronization primitives.

Even though you can create, subclass and use your own StatisticalProfiler<*,*>, there are some things to consider when working with the StatisticalProfilerProxy: The StatisticalProfilerProxy OWNS an array of StatisticalProfiler<AZStd::string, AZStd::shared_mutex>. You can "manage" one of those StatisticalProfiler by getting a reference to it and add Running statistics etc.

Member Function Documentation

◆ SummarizePerFrameStats()

template<class StatIdType = AZStd::string, class MutexType = AZ::NullMutex>
double AZ::Statistics::StatisticalProfiler< StatIdType, MutexType >::SummarizePerFrameStats ( )
inline

Should be called once per frame, it runs over all existing timed stats in m_statsForPerFrameCalculation and accumulates all the values as a single stat per frame.


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