Use idSys::GetMilliseconds() for idTimer

The class is only used for debugging and statistical purposes.
The precision is now reduced to milliseconds, but that's only
relevant for fine grained debug timings - where the old code
was inaccurate at anyway.
This commit is contained in:
dhewg 2011-12-21 16:51:54 +01:00 committed by Daniel Gibson
parent d26cf44a29
commit 79ad74d779
12 changed files with 34 additions and 81 deletions

View file

@ -2521,7 +2521,7 @@ gameReturn_t idGameLocal::RunFrame( const usercmd_t *clientCmds ) {
timer_singlethink.Stop(); timer_singlethink.Stop();
ms = timer_singlethink.Milliseconds(); ms = timer_singlethink.Milliseconds();
if ( ms >= g_timeentities.GetFloat() ) { if ( ms >= g_timeentities.GetFloat() ) {
Printf( "%d: entity '%s': %.1f ms\n", time, ent->name.c_str(), ms ); Printf( "%d: entity '%s': %f ms\n", time, ent->name.c_str(), ms );
} }
num++; num++;
} }
@ -2595,7 +2595,7 @@ gameReturn_t idGameLocal::RunFrame( const usercmd_t *clientCmds ) {
// display how long it took to calculate the current game frame // display how long it took to calculate the current game frame
if ( g_frametime.GetBool() ) { if ( g_frametime.GetBool() ) {
Printf( "game %d: all:%.1f th:%.1f ev:%.1f %d ents \n", Printf( "game %d: all:%u th:%u ev:%u %d ents \n",
time, timer_think.Milliseconds() + timer_events.Milliseconds(), time, timer_think.Milliseconds() + timer_events.Milliseconds(),
timer_think.Milliseconds(), timer_events.Milliseconds(), num ); timer_think.Milliseconds(), timer_events.Milliseconds(), num );
} }

View file

@ -842,7 +842,7 @@ void idPVS::Init( void ) {
timer.Stop(); timer.Stop();
gameLocal.Printf( "%5.0f msec to calculate PVS\n", timer.Milliseconds() ); gameLocal.Printf( "%5u msec to calculate PVS\n", timer.Milliseconds() );
gameLocal.Printf( "%5d areas\n", numAreas ); gameLocal.Printf( "%5d areas\n", numAreas );
gameLocal.Printf( "%5d portals\n", numPortals ); gameLocal.Printf( "%5d portals\n", numPortals );
gameLocal.Printf( "%5d areas visible on average\n", totalVisibleAreas / numAreas ); gameLocal.Printf( "%5d areas visible on average\n", totalVisibleAreas / numAreas );

View file

@ -6382,7 +6382,7 @@ bool idPhysics_AF::Evaluate( int timeStepMSec, int endTimeMSec ) {
timer_total.Stop(); timer_total.Stop();
if ( af_showTimings.GetInteger() == 1 ) { if ( af_showTimings.GetInteger() == 1 ) {
gameLocal.Printf( "%12s: t %1.4f pc %2d, %1.4f ac %2d %1.4f lcp %1.4f cd %1.4f\n", gameLocal.Printf( "%12s: t %u pc %2d, %u ac %2d %u lcp %u cd %u\n",
self->name.c_str(), self->name.c_str(),
timer_total.Milliseconds(), timer_total.Milliseconds(),
numPrimary, timer_pc.Milliseconds(), numPrimary, timer_pc.Milliseconds(),
@ -6392,7 +6392,7 @@ bool idPhysics_AF::Evaluate( int timeStepMSec, int endTimeMSec ) {
else if ( af_showTimings.GetInteger() == 2 ) { else if ( af_showTimings.GetInteger() == 2 ) {
numArticulatedFigures++; numArticulatedFigures++;
if ( endTimeMSec > lastTimerReset ) { if ( endTimeMSec > lastTimerReset ) {
gameLocal.Printf( "af %d: t %1.4f pc %2d, %1.4f ac %2d %1.4f lcp %1.4f cd %1.4f\n", gameLocal.Printf( "af %d: t %u pc %2d, %u ac %2d %u lcp %u cd %u\n",
numArticulatedFigures, numArticulatedFigures,
timer_total.Milliseconds(), timer_total.Milliseconds(),
numPrimary, timer_pc.Milliseconds(), numPrimary, timer_pc.Milliseconds(),

View file

@ -977,7 +977,7 @@ bool idPhysics_RigidBody::Evaluate( int timeStepMSec, int endTimeMSec ) {
timer_total.Stop(); timer_total.Stop();
if ( rb_showTimings->integer == 1 ) { if ( rb_showTimings->integer == 1 ) {
gameLocal.Printf( "%12s: t %1.4f cd %1.4f\n", gameLocal.Printf( "%12s: t %u cd %u\n",
self->name.c_str(), self->name.c_str(),
timer_total.Milliseconds(), timer_collision.Milliseconds() ); timer_total.Milliseconds(), timer_collision.Milliseconds() );
lastTimerReset = 0; lastTimerReset = 0;
@ -985,7 +985,7 @@ bool idPhysics_RigidBody::Evaluate( int timeStepMSec, int endTimeMSec ) {
else if ( rb_showTimings->integer == 2 ) { else if ( rb_showTimings->integer == 2 ) {
numRigidBodies++; numRigidBodies++;
if ( endTimeMSec > lastTimerReset ) { if ( endTimeMSec > lastTimerReset ) {
gameLocal.Printf( "rb %d: t %1.4f cd %1.4f\n", gameLocal.Printf( "rb %d: t %u cd %u\n",
numRigidBodies, numRigidBodies,
timer_total.Milliseconds(), timer_collision.Milliseconds() ); timer_total.Milliseconds(), timer_collision.Milliseconds() );
} }

View file

@ -2644,6 +2644,6 @@ void idCompiler::CompileFile( const char *text, const char *filename, bool toCon
compile_time.Stop(); compile_time.Stop();
if ( !toConsole ) { if ( !toConsole ) {
gameLocal.Printf( "Compiled '%s': %.1f ms\n", filename, compile_time.Milliseconds() ); gameLocal.Printf( "Compiled '%s': %u ms\n", filename, compile_time.Milliseconds() );
} }
} }

View file

@ -2330,7 +2330,7 @@ gameReturn_t idGameLocal::RunFrame( const usercmd_t *clientCmds ) {
// display how long it took to calculate the current game frame // display how long it took to calculate the current game frame
if ( g_frametime.GetBool() ) { if ( g_frametime.GetBool() ) {
Printf( "game %d: all:%.1f th:%.1f ev:%.1f %d ents \n", Printf( "game %d: all:%u th:%u ev:%u %d ents \n",
time, timer_think.Milliseconds() + timer_events.Milliseconds(), time, timer_think.Milliseconds() + timer_events.Milliseconds(),
timer_think.Milliseconds(), timer_events.Milliseconds(), num ); timer_think.Milliseconds(), timer_events.Milliseconds(), num );
} }

View file

@ -842,7 +842,7 @@ void idPVS::Init( void ) {
timer.Stop(); timer.Stop();
gameLocal.Printf( "%5.0f msec to calculate PVS\n", timer.Milliseconds() ); gameLocal.Printf( "%5u msec to calculate PVS\n", timer.Milliseconds() );
gameLocal.Printf( "%5d areas\n", numAreas ); gameLocal.Printf( "%5d areas\n", numAreas );
gameLocal.Printf( "%5d portals\n", numPortals ); gameLocal.Printf( "%5d portals\n", numPortals );
gameLocal.Printf( "%5d areas visible on average\n", totalVisibleAreas / numAreas ); gameLocal.Printf( "%5d areas visible on average\n", totalVisibleAreas / numAreas );

View file

@ -6381,7 +6381,7 @@ bool idPhysics_AF::Evaluate( int timeStepMSec, int endTimeMSec ) {
timer_total.Stop(); timer_total.Stop();
if ( af_showTimings.GetInteger() == 1 ) { if ( af_showTimings.GetInteger() == 1 ) {
gameLocal.Printf( "%12s: t %1.4f pc %2d, %1.4f ac %2d %1.4f lcp %1.4f cd %1.4f\n", gameLocal.Printf( "%12s: t %u pc %2d, %u ac %2d %u lcp %u cd %u\n",
self->name.c_str(), self->name.c_str(),
timer_total.Milliseconds(), timer_total.Milliseconds(),
numPrimary, timer_pc.Milliseconds(), numPrimary, timer_pc.Milliseconds(),
@ -6391,7 +6391,7 @@ bool idPhysics_AF::Evaluate( int timeStepMSec, int endTimeMSec ) {
else if ( af_showTimings.GetInteger() == 2 ) { else if ( af_showTimings.GetInteger() == 2 ) {
numArticulatedFigures++; numArticulatedFigures++;
if ( endTimeMSec > lastTimerReset ) { if ( endTimeMSec > lastTimerReset ) {
gameLocal.Printf( "af %d: t %1.4f pc %2d, %1.4f ac %2d %1.4f lcp %1.4f cd %1.4f\n", gameLocal.Printf( "af %d: t %u pc %2d, %u ac %2d %u lcp %u cd %u\n",
numArticulatedFigures, numArticulatedFigures,
timer_total.Milliseconds(), timer_total.Milliseconds(),
numPrimary, timer_pc.Milliseconds(), numPrimary, timer_pc.Milliseconds(),

View file

@ -977,7 +977,7 @@ bool idPhysics_RigidBody::Evaluate( int timeStepMSec, int endTimeMSec ) {
timer_total.Stop(); timer_total.Stop();
if ( rb_showTimings->integer == 1 ) { if ( rb_showTimings->integer == 1 ) {
gameLocal.Printf( "%12s: t %1.4f cd %1.4f\n", gameLocal.Printf( "%12s: t %u cd %u\n",
self->name.c_str(), self->name.c_str(),
timer_total.Milliseconds(), timer_collision.Milliseconds() ); timer_total.Milliseconds(), timer_collision.Milliseconds() );
lastTimerReset = 0; lastTimerReset = 0;
@ -985,7 +985,7 @@ bool idPhysics_RigidBody::Evaluate( int timeStepMSec, int endTimeMSec ) {
else if ( rb_showTimings->integer == 2 ) { else if ( rb_showTimings->integer == 2 ) {
numRigidBodies++; numRigidBodies++;
if ( endTimeMSec > lastTimerReset ) { if ( endTimeMSec > lastTimerReset ) {
gameLocal.Printf( "rb %d: t %1.4f cd %1.4f\n", gameLocal.Printf( "rb %d: t %u cd %u\n",
numRigidBodies, numRigidBodies,
timer_total.Milliseconds(), timer_collision.Milliseconds() ); timer_total.Milliseconds(), timer_collision.Milliseconds() );
} }

View file

@ -2644,6 +2644,6 @@ void idCompiler::CompileFile( const char *text, const char *filename, bool toCon
compile_time.Stop(); compile_time.Stop();
if ( !toConsole ) { if ( !toConsole ) {
gameLocal.Printf( "Compiled '%s': %.1f ms\n", filename, compile_time.Milliseconds() ); gameLocal.Printf( "Compiled '%s': %u ms\n", filename, compile_time.Milliseconds() );
} }
} }

View file

@ -32,33 +32,6 @@ If you have questions concerning this license or the applicable additional terms
#include "idlib/Timer.h" #include "idlib/Timer.h"
double idTimer::base = -1.0;
/*
=================
idTimer::InitBaseClockTicks
=================
*/
void idTimer::InitBaseClockTicks( void ) const {
idTimer timer;
double ct, b;
int i;
base = 0.0;
b = -1.0;
for ( i = 0; i < 1000; i++ ) {
timer.Clear();
timer.Start();
timer.Stop();
ct = timer.ClockTicks();
if ( b < 0.0 || ct < b ) {
b = ct;
}
}
base = b;
}
/* /*
================= =================
idTimerReport::idTimerReport idTimerReport::idTimerReport
@ -153,10 +126,10 @@ void idTimerReport::PrintReport() {
assert( timers.Num() == names.Num() ); assert( timers.Num() == names.Num() );
idLib::common->Printf( "Timing Report for %s\n", reportName.c_str() ); idLib::common->Printf( "Timing Report for %s\n", reportName.c_str() );
idLib::common->Printf( "-------------------------------\n" ); idLib::common->Printf( "-------------------------------\n" );
float total = 0.0f; unsigned int total = 0;
for ( int i = 0; i < names.Num(); i++ ) { for ( int i = 0; i < names.Num(); i++ ) {
idLib::common->Printf( "%s consumed %5.2f seconds\n", names[i].c_str(), timers[i]->Milliseconds() * 0.001f ); idLib::common->Printf( "%s consumed %5.2f seconds\n", names[i].c_str(), 0.001f * timers[i]->Milliseconds() );
total += timers[i]->Milliseconds(); total += timers[i]->Milliseconds();
} }
idLib::common->Printf( "Total time for report %s was %5.2f\n\n", reportName.c_str(), total * 0.001f ); idLib::common->Printf( "Total time for report %s was %5.2f\n\n", reportName.c_str(), 0.001f * total );
} }

View file

@ -44,7 +44,7 @@ If you have questions concerning this license or the applicable additional terms
class idTimer { class idTimer {
public: public:
idTimer( void ); idTimer( void );
idTimer( double clockTicks ); idTimer( unsigned int ms );
~idTimer( void ); ~idTimer( void );
idTimer operator+( const idTimer &t ) const; idTimer operator+( const idTimer &t ) const;
@ -55,19 +55,15 @@ public:
void Start( void ); void Start( void );
void Stop( void ); void Stop( void );
void Clear( void ); void Clear( void );
double ClockTicks( void ) const; unsigned int Milliseconds( void ) const;
double Milliseconds( void ) const;
private: private:
static double base;
enum { enum {
TS_STARTED, TS_STARTED,
TS_STOPPED TS_STOPPED
} state; } state;
double start; unsigned int start;
double clockTicks; unsigned int ms;
void InitBaseClockTicks( void ) const;
}; };
/* /*
@ -77,7 +73,7 @@ idTimer::idTimer
*/ */
ID_INLINE idTimer::idTimer( void ) { ID_INLINE idTimer::idTimer( void ) {
state = TS_STOPPED; state = TS_STOPPED;
clockTicks = 0.0; ms = 0;
} }
/* /*
@ -85,9 +81,9 @@ ID_INLINE idTimer::idTimer( void ) {
idTimer::idTimer idTimer::idTimer
================= =================
*/ */
ID_INLINE idTimer::idTimer( double _clockTicks ) { ID_INLINE idTimer::idTimer( unsigned int _ms ) {
state = TS_STOPPED; state = TS_STOPPED;
clockTicks = _clockTicks; ms = _ms;
} }
/* /*
@ -105,7 +101,7 @@ idTimer::operator+
*/ */
ID_INLINE idTimer idTimer::operator+( const idTimer &t ) const { ID_INLINE idTimer idTimer::operator+( const idTimer &t ) const {
assert( state == TS_STOPPED && t.state == TS_STOPPED ); assert( state == TS_STOPPED && t.state == TS_STOPPED );
return idTimer( clockTicks + t.clockTicks ); return idTimer( ms + t.ms );
} }
/* /*
@ -115,7 +111,7 @@ idTimer::operator-
*/ */
ID_INLINE idTimer idTimer::operator-( const idTimer &t ) const { ID_INLINE idTimer idTimer::operator-( const idTimer &t ) const {
assert( state == TS_STOPPED && t.state == TS_STOPPED ); assert( state == TS_STOPPED && t.state == TS_STOPPED );
return idTimer( clockTicks - t.clockTicks ); return idTimer( ms - t.ms );
} }
/* /*
@ -125,7 +121,7 @@ idTimer::operator+=
*/ */
ID_INLINE idTimer &idTimer::operator+=( const idTimer &t ) { ID_INLINE idTimer &idTimer::operator+=( const idTimer &t ) {
assert( state == TS_STOPPED && t.state == TS_STOPPED ); assert( state == TS_STOPPED && t.state == TS_STOPPED );
clockTicks += t.clockTicks; ms += t.ms;
return *this; return *this;
} }
@ -136,7 +132,7 @@ idTimer::operator-=
*/ */
ID_INLINE idTimer &idTimer::operator-=( const idTimer &t ) { ID_INLINE idTimer &idTimer::operator-=( const idTimer &t ) {
assert( state == TS_STOPPED && t.state == TS_STOPPED ); assert( state == TS_STOPPED && t.state == TS_STOPPED );
clockTicks -= t.clockTicks; ms -= t.ms;
return *this; return *this;
} }
@ -148,7 +144,7 @@ idTimer::Start
ID_INLINE void idTimer::Start( void ) { ID_INLINE void idTimer::Start( void ) {
assert( state == TS_STOPPED ); assert( state == TS_STOPPED );
state = TS_STARTED; state = TS_STARTED;
start = idLib::sys->GetClockTicks(); start = idLib::sys->GetMilliseconds();
} }
/* /*
@ -158,13 +154,7 @@ idTimer::Stop
*/ */
ID_INLINE void idTimer::Stop( void ) { ID_INLINE void idTimer::Stop( void ) {
assert( state == TS_STARTED ); assert( state == TS_STARTED );
clockTicks += idLib::sys->GetClockTicks() - start; ms += idLib::sys->GetMilliseconds() - start;
if ( base < 0.0 ) {
InitBaseClockTicks();
}
if ( clockTicks > base ) {
clockTicks -= base;
}
state = TS_STOPPED; state = TS_STOPPED;
} }
@ -174,17 +164,7 @@ idTimer::Clear
================= =================
*/ */
ID_INLINE void idTimer::Clear( void ) { ID_INLINE void idTimer::Clear( void ) {
clockTicks = 0.0; ms = 0;
}
/*
=================
idTimer::ClockTicks
=================
*/
ID_INLINE double idTimer::ClockTicks( void ) const {
assert( state == TS_STOPPED );
return clockTicks;
} }
/* /*
@ -192,9 +172,9 @@ ID_INLINE double idTimer::ClockTicks( void ) const {
idTimer::Milliseconds idTimer::Milliseconds
================= =================
*/ */
ID_INLINE double idTimer::Milliseconds( void ) const { ID_INLINE unsigned int idTimer::Milliseconds( void ) const {
assert( state == TS_STOPPED ); assert( state == TS_STOPPED );
return clockTicks / ( idLib::sys->ClockTicksPerSecond() * 0.001 ); return ms;
} }