demotool/ui-profiling.hh
2017-11-23 23:31:24 +01:00

65 lines
1.3 KiB
C++

#pragma once
#ifndef REAL_BUILD
# include "externals.hh"
#endif
struct T_ProfilerSamples
{
float sum;
uint32_t nSamples;
};
struct T_Profiler
{
static constexpr uint32_t Samples = 4;
static constexpr uint32_t History = 4;
static constexpr uint32_t Invalid = 0xffffffff;
void clear( );
void startFrame( );
void start( T_String const& section );
void end( T_String const& section );
void endFrame( );
uint32_t sections( ) const noexcept
{ return sections_.size( ); }
T_String const& nameOf(
const uint32_t section ) const
{ return sections_[ section ]; }
float durationOf( const uint32_t section ) const
{ return secDurations_[ section ]; }
float startOf( const uint32_t section ) const
{ return secStarts_[ section ]; }
void makeUI( );
bool& uiEnabled( ) { return uiEnabled_; }
private:
using T_SamplesList_ = T_Array< T_ProfilerSamples >;
using T_Data_ = T_Array< T_SamplesList_ >;
uint32_t find( T_String const& section ) const;
float computeDuration(
const uint32_t section ) const;
uint32_t previous_;
uint32_t current_;
T_Array< T_String > sections_;
T_Array< uint32_t > chain_;
T_Array< uint32_t > parents_;
T_Data_ samples_;
T_Array< uint64_t > starts_;
T_Array< float > secDurations_;
T_Array< float > secStarts_;
bool uiEnabled_ = false;
T_Array< int > displayed_;
};