demotool/profiling.hh

64 lines
1.4 KiB
C++
Raw Normal View History

2017-10-01 11:37:04 +02:00
#pragma once
#ifndef REAL_BUILD
# define REAL_BUILD
# include "externals.hh"
# include "utilities.hh"
# undef REAL_BUILD
#endif
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
static T_Profiler Profiler;
void clear( );
void startFrame( );
void start( __rd__ std::string const& section );
void end( __rd__ std::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( ); }
std::string const& nameOf(
__rd__ const uint32_t section ) const
{ return sections_[ section ]; }
2017-10-01 12:48:55 +02:00
float durationOf( __rd__ const uint32_t section ) const
{ return secDurations_[ section ]; }
float startOf( __rd__ const uint32_t section ) const
{ return secStarts_[ section ]; }
2017-10-01 11:37:04 +02:00
private:
using T_SamplesList_ = std::vector< T_ProfilerSamples >;
using T_Data_ = std::vector< T_SamplesList_ >;
uint32_t find( __rd__ std::string const& section ) const;
2017-10-01 12:48:55 +02:00
float computeDuration(
__rd__ const uint32_t section ) const;
uint32_t previous_;
uint32_t current_;
2017-10-01 11:37:04 +02:00
std::vector< std::string > sections_;
2017-10-01 12:48:55 +02:00
std::vector< uint32_t > chain_;
std::vector< uint32_t > parents_;
2017-10-01 11:37:04 +02:00
T_Data_ samples_;
std::vector< uint64_t > starts_;
2017-10-01 12:48:55 +02:00
std::vector< float > secDurations_;
std::vector< float > secStarts_;
2017-10-01 11:37:04 +02:00
};
2017-10-01 12:48:55 +02:00