Profiler: hierarchy (+start values)
This commit is contained in:
parent
b5d7d3775b
commit
22a5a9b836
3 changed files with 72 additions and 8 deletions
16
main.cc
16
main.cc
|
@ -72,8 +72,10 @@ T_Main::T_Main( )
|
|||
|
||||
void T_Main::mainLoop( )
|
||||
{
|
||||
T_Profiler::Profiler.clear( );
|
||||
auto& p( T_Profiler::Profiler );
|
||||
p.clear( );
|
||||
while ( !done ) {
|
||||
p.startFrame( );
|
||||
T_Profiler::Profiler.start( "Full frame" );
|
||||
startIteration( );
|
||||
if ( !done ) {
|
||||
|
@ -84,11 +86,13 @@ void T_Main::mainLoop( )
|
|||
T_Profiler::Profiler.end( "Full frame" );
|
||||
SDL_GL_SwapWindow( window );
|
||||
|
||||
auto const& p( T_Profiler::Profiler );
|
||||
p.endFrame( );
|
||||
const auto n( p.sections( ) );
|
||||
for ( auto i = 0u ; i < n ; i ++ ) {
|
||||
printf( "%s: %fms\n" , p.nameOf( i ).c_str( ) ,
|
||||
p.resultOf( i ) );
|
||||
printf( "%s: %fms (start %fms)\n" ,
|
||||
p.nameOf( i ).c_str( ) ,
|
||||
p.durationOf( i ) ,
|
||||
p.startOf( i ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -176,10 +180,10 @@ void T_Main::makeUI( )
|
|||
|
||||
void T_Main::render( )
|
||||
{
|
||||
T_Profiler::Profiler.start( "Effects" );
|
||||
T_Profiler::Profiler.start( "Render" );
|
||||
raymarcher->render( );
|
||||
bloomPass->render( );
|
||||
glFinish( ); T_Profiler::Profiler.end( "Effects" );
|
||||
glFinish( ); T_Profiler::Profiler.end( "Render" );
|
||||
|
||||
glUseProgram( 0 );
|
||||
ImGui::Render( );
|
||||
|
|
46
profiling.cc
46
profiling.cc
|
@ -8,6 +8,10 @@
|
|||
|
||||
T_Profiler T_Profiler::Profiler;
|
||||
|
||||
constexpr uint32_t T_Profiler::Samples;
|
||||
constexpr uint32_t T_Profiler::History;
|
||||
constexpr uint32_t T_Profiler::Invalid;
|
||||
|
||||
|
||||
void T_Profiler::clear( )
|
||||
{
|
||||
|
@ -18,6 +22,32 @@ void T_Profiler::clear( )
|
|||
|
||||
void T_Profiler::startFrame( )
|
||||
{
|
||||
previous_ = Invalid;
|
||||
current_ = Invalid;
|
||||
}
|
||||
|
||||
void T_Profiler::endFrame( )
|
||||
{
|
||||
const auto n( sections_.size( ) );
|
||||
while ( secDurations_.size( ) < n ) {
|
||||
secDurations_.push_back( 0 );
|
||||
secStarts_.push_back( 0 );
|
||||
}
|
||||
|
||||
for ( auto i = 0u ; i < n ; i ++ ) {
|
||||
const float d = computeDuration( i );
|
||||
secDurations_[ i ] = d;
|
||||
if ( parents_[ i ] != Invalid ) {
|
||||
assert( parents_[ i ] < i );
|
||||
secStarts_[ i ] = secStarts_[ parents_[ i ] ];
|
||||
} else if ( chain_[ i ] != Invalid ) {
|
||||
assert( chain_[ i ] < i );
|
||||
secStarts_[ i ] = secStarts_[ chain_[ i ] ]
|
||||
+ secDurations_[ chain_[ i ] ];
|
||||
} else {
|
||||
secStarts_[ i ] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void T_Profiler::start(
|
||||
|
@ -29,8 +59,19 @@ void T_Profiler::start(
|
|||
sections_.push_back( section );
|
||||
samples_.push_back( T_SamplesList_{ } );
|
||||
starts_.push_back( 0u );
|
||||
chain_.push_back( Invalid );
|
||||
parents_.push_back( Invalid );
|
||||
}
|
||||
|
||||
chain_[ pos ] = previous_;
|
||||
if ( current_ != Invalid ) {
|
||||
parents_[ pos ] = current_;
|
||||
previous_ = Invalid;
|
||||
} else {
|
||||
parents_[ pos ] = Invalid;
|
||||
}
|
||||
current_ = pos;
|
||||
|
||||
struct timespec ts;
|
||||
clock_gettime( CLOCK_MONOTONIC , &ts );
|
||||
starts_[ pos ] = ts.tv_sec * 1000000000 + ts.tv_nsec;
|
||||
|
@ -63,9 +104,12 @@ void T_Profiler::end(
|
|||
}
|
||||
samples[ 0 ].sum += float( duration ) * 1e-6;
|
||||
samples[ 0 ].nSamples ++;
|
||||
|
||||
previous_ = pos;
|
||||
current_ = Invalid;
|
||||
}
|
||||
|
||||
float T_Profiler::resultOf(
|
||||
float T_Profiler::computeDuration(
|
||||
__rd__ const uint32_t section ) const
|
||||
{
|
||||
auto const& samples( samples_[ section ] );
|
||||
|
|
18
profiling.hh
18
profiling.hh
|
@ -18,6 +18,7 @@ struct T_Profiler
|
|||
{
|
||||
static constexpr uint32_t Samples = 4;
|
||||
static constexpr uint32_t History = 4;
|
||||
static constexpr uint32_t Invalid = 0xffffffff;
|
||||
static T_Profiler Profiler;
|
||||
|
||||
void clear( );
|
||||
|
@ -25,6 +26,7 @@ struct T_Profiler
|
|||
void startFrame( );
|
||||
void start( __rd__ std::string const& section );
|
||||
void end( __rd__ std::string const& section );
|
||||
void endFrame( );
|
||||
|
||||
uint32_t sections( ) const noexcept
|
||||
{ return sections_.size( ); }
|
||||
|
@ -33,15 +35,29 @@ struct T_Profiler
|
|||
__rd__ const uint32_t section ) const
|
||||
{ return sections_[ section ]; }
|
||||
|
||||
float resultOf( __rd__ const uint32_t section ) const;
|
||||
float durationOf( __rd__ const uint32_t section ) const
|
||||
{ return secDurations_[ section ]; }
|
||||
float startOf( __rd__ const uint32_t section ) const
|
||||
{ return secStarts_[ section ]; }
|
||||
|
||||
private:
|
||||
using T_SamplesList_ = std::vector< T_ProfilerSamples >;
|
||||
using T_Data_ = std::vector< T_SamplesList_ >;
|
||||
|
||||
uint32_t find( __rd__ std::string const& section ) const;
|
||||
float computeDuration(
|
||||
__rd__ const uint32_t section ) const;
|
||||
|
||||
uint32_t previous_;
|
||||
uint32_t current_;
|
||||
|
||||
std::vector< std::string > sections_;
|
||||
std::vector< uint32_t > chain_;
|
||||
std::vector< uint32_t > parents_;
|
||||
T_Data_ samples_;
|
||||
std::vector< uint64_t > starts_;
|
||||
|
||||
std::vector< float > secDurations_;
|
||||
std::vector< float > secStarts_;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue