demotool/profiling.hh

64 lines
1.3 KiB
C++
Raw Normal View History

2017-10-01 11:37:04 +02:00
#pragma once
2017-10-02 09:40:36 +02:00
#include "utilities.hh"
2017-10-01 11:37:04 +02:00
struct T_ProfilerSamples
{
float sum;
uint32_t nSamples;
};
struct T_Profiler
{
static constexpr uint32_t Samples = 4;
static constexpr uint32_t History = 4;
2017-10-01 12:48:55 +02:00
static constexpr uint32_t Invalid = 0xffffffff;
2017-10-01 11:37:04 +02:00
void clear( );
void startFrame( );
2017-11-03 11:55:26 +01:00
void start( T_String const& section );
void end( T_String const& section );
2017-10-01 12:48:55 +02:00
void endFrame( );
2017-10-01 11:37:04 +02:00
uint32_t sections( ) const noexcept
{ return sections_.size( ); }
2017-11-03 11:55:26 +01:00
T_String const& nameOf(
const uint32_t section ) const
2017-10-01 11:37:04 +02:00
{ return sections_[ section ]; }
2017-11-03 11:55:26 +01:00
float durationOf( const uint32_t section ) const
2017-10-01 12:48:55 +02:00
{ return secDurations_[ section ]; }
2017-11-03 11:55:26 +01:00
float startOf( const uint32_t section ) const
2017-10-01 12:48:55 +02:00
{ return secStarts_[ section ]; }
2017-10-01 11:37:04 +02:00
2017-10-01 14:10:00 +02:00
void makeUI( );
bool& uiEnabled( ) { return uiEnabled_; }
2017-10-01 11:37:04 +02:00
private:
2017-11-03 11:55:26 +01:00
using T_SamplesList_ = T_Array< T_ProfilerSamples >;
using T_Data_ = T_Array< T_SamplesList_ >;
2017-10-01 11:37:04 +02:00
2017-11-03 11:55:26 +01:00
uint32_t find( T_String const& section ) const;
2017-10-01 12:48:55 +02:00
float computeDuration(
2017-11-03 11:55:26 +01:00
const uint32_t section ) const;
2017-10-01 12:48:55 +02:00
uint32_t previous_;
uint32_t current_;
2017-10-01 11:37:04 +02:00
2017-11-03 11:55:26 +01:00
T_Array< T_String > sections_;
T_Array< uint32_t > chain_;
T_Array< uint32_t > parents_;
2017-10-01 11:37:04 +02:00
T_Data_ samples_;
2017-11-03 11:55:26 +01:00
T_Array< uint64_t > starts_;
2017-10-01 12:48:55 +02:00
2017-11-03 11:55:26 +01:00
T_Array< float > secDurations_;
T_Array< float > secStarts_;
2017-10-01 14:10:00 +02:00
bool uiEnabled_ = false;
2017-11-03 11:55:26 +01:00
T_Array< int > displayed_;
2017-10-01 11:37:04 +02:00
};
2017-10-01 12:48:55 +02:00