diff --git a/src/libs/client/exitmenu.cpp b/src/libs/client/exitmenu.cpp index 2fd83642..05d2e0e4 100644 --- a/src/libs/client/exitmenu.cpp +++ b/src/libs/client/exitmenu.cpp @@ -28,8 +28,8 @@ static void endofprog(void * /* dummy */) { - STOP_ACTIVE_PROFILES(); - PRINT_PROFILE(); + GfProfStopActiveProfiles(); + GfProfPrintReport(); GfScrShutdown(); exit(0); } diff --git a/src/libs/raceengineclient/raceengine.cpp b/src/libs/raceengineclient/raceengine.cpp index 8975a5e3..b8d5d2ca 100644 --- a/src/libs/raceengineclient/raceengine.cpp +++ b/src/libs/raceengineclient/raceengine.cpp @@ -1085,7 +1085,7 @@ ReOneStep(double deltaTimeIncrement) ReInfo->_reLastTime = 0.0; } - START_PROFILE("rbDrive*"); + GfProfStartProfile("rbDrive*"); if ((s->currentTime - ReInfo->_reLastTime) >= RCM_MAX_DT_ROBOTS) { SignalEvent(Bots); s->deltaTime = s->currentTime - ReInfo->_reLastTime; @@ -1104,7 +1104,7 @@ ReOneStep(double deltaTimeIncrement) } ReInfo->_reLastTime = s->currentTime; } - STOP_PROFILE("rbDrive*"); + GfProfStopProfile("rbDrive*"); if (GetNetwork()) @@ -1113,12 +1113,12 @@ ReOneStep(double deltaTimeIncrement) } SignalEvent(Simu); - START_PROFILE("_reSimItf.update*"); + GfProfStartProfile("_reSimItf.update*"); ReInfo->_reSimItf.update(s, deltaTimeIncrement, -1); for (i = 0; i < s->_ncars; i++) { ReManage(s->cars[i]); } - STOP_PROFILE("_reSimItf.update*"); + GfProfStopProfile("_reSimItf.update*"); ReSortCars(); @@ -1141,7 +1141,7 @@ void ReInitUpdater() if (!situationUpdater) situationUpdater = new reSituationUpdater(ReInfo); - GfssConfigureEventLog("graphics", 10000, 0.0); + GfSchedConfigureEventLog("graphics", 10000, 0.0); } void ReInitCarGraphics(void) @@ -1156,7 +1156,7 @@ void ReStart(void) { #ifdef ReMultiThreaded - GfssBeginSession(); + GfSchedBeginSession(); situationUpdater->start(); #else // ReMultiThreaded ReInfo->_reRunning = 1; @@ -1169,7 +1169,7 @@ ReStop(void) { #ifdef ReMultiThreaded situationUpdater->stop(); - GfssEndSession(); + GfSchedEndSession(); #else ReInfo->_reRunning = 0; #endif // ReMultiThreaded @@ -1184,7 +1184,7 @@ void ReShutdownUpdater() delete situationUpdater; situationUpdater = 0; } - GfssPrintReport("schedule.csv", 1.0e-4); + GfSchedPrintReport("schedule.csv", 1.0e-4); } #endif // ReMultiThreaded @@ -1220,17 +1220,17 @@ ReUpdate(void) tRmMovieCapture *capture; - START_PROFILE("ReUpdate"); + GfProfStartProfile("ReUpdate"); ReInfo->_refreshDisplay = 0; switch (ReInfo->_displayMode) { case RM_DISP_MODE_NORMAL: t = GfTimeClock(); - START_PROFILE("ReOneStep*"); + GfProfStartProfile("ReOneStep*"); while (ReInfo->_reRunning && ((t - ReInfo->_reCurTime) > RCM_MAX_DT_SIMU)) { ReOneStep(RCM_MAX_DT_SIMU); } - STOP_PROFILE("ReOneStep*"); + GfProfStopProfile("ReOneStep*"); //Send car physics to network if needed if (GetNetwork()) @@ -1279,7 +1279,7 @@ ReUpdate(void) break; } - STOP_PROFILE("ReUpdate"); + GfProfStopProfile("ReUpdate"); return RM_ASYNC; } @@ -1363,7 +1363,7 @@ int reSituationUpdater::threadLoop() realTime = GfTimeClock(); - START_PROFILE("ReOneStep*"); + GfProfStartProfile("ReOneStep*"); while (_pCurrReInfo->_reRunning && ((realTime - _pCurrReInfo->_reCurTime) > RCM_MAX_DT_SIMU)) @@ -1372,7 +1372,7 @@ int reSituationUpdater::threadLoop() ReOneStep(RCM_MAX_DT_SIMU); } - STOP_PROFILE("ReOneStep*"); + GfProfStopProfile("ReOneStep*"); // Send car physics to network if needed if (GetNetwork()) @@ -1802,13 +1802,13 @@ void reSituationUpdater::computeCurrentStep() { const double t = GfTimeClock(); - START_PROFILE("ReOneStep*"); + GfProfStartProfile("ReOneStep*"); while (_pCurrReInfo->_reRunning && ((t - _pCurrReInfo->_reCurTime) > RCM_MAX_DT_SIMU)) ReOneStep(RCM_MAX_DT_SIMU); - STOP_PROFILE("ReOneStep*"); + GfProfStopProfile("ReOneStep*"); // Send car physics to network if needed if (GetNetwork()) @@ -1821,7 +1821,7 @@ ReUpdate(void) { tRmInfo* pPrevReInfo; - START_PROFILE("ReUpdate"); + GfProfStartProfile("ReUpdate"); ReInfo->_refreshDisplay = 0; switch (ReInfo->_displayMode) { @@ -1848,9 +1848,9 @@ ReUpdate(void) SignalEvent(Graph); - GfssBeginEvent("graphics"); + GfSchedBeginEvent("graphics"); pPrevReInfo->_reGraphicItf.refresh(pPrevReInfo->s); - GfssEndEvent("graphics"); + GfSchedEndEvent("graphics"); GfelPostRedisplay(); /* Callback -> reDisplay */ break; @@ -1897,7 +1897,7 @@ ReUpdate(void) } } - STOP_PROFILE("ReUpdate"); + GfProfStopProfile("ReUpdate"); return RM_ASYNC; } diff --git a/src/libs/tgf/profiler.cpp b/src/libs/tgf/profiler.cpp index ecd39b42..fcb82d64 100644 --- a/src/libs/tgf/profiler.cpp +++ b/src/libs/tgf/profiler.cpp @@ -16,15 +16,50 @@ #ifdef PROFILER +#include + +#include +#include #include #include #include -#include - #include "tgf.h" +class ProfileInstance { + public: + ProfileInstance(const char * pname); + ~ProfileInstance(); + char name[256]; + int calls; + int openCalls; + double totalTime; + double addTime; + double subTime; + double tmpStart; + std::map mapChildren; +}; + +class Profiler { + protected: + Profiler(); + public: + ~Profiler(); + static Profiler * getInstance(); + void startProfile(const char * pname); + void stopProfile(); + void stopActiveProfiles(); + void printReport(); + private: + static Profiler * profiler; + ProfileInstance * curProfile; + double fStartTime; + std::vector vecProfiles; + std::vector stkProfiles; + std::map mapWarning; +}; + ////////////////////////////////////////////////////////// ProfileInstance::ProfileInstance(const char * pname) { @@ -123,7 +158,7 @@ bool instanceLess(const ProfileInstance * p1, const ProfileInstance * p2) { #define TRUNC(a) ( (a) < 0.001 ? 0.0 : (a) ) -void Profiler::printProfile() { +void Profiler::printReport() { double total = GfTimeClock() - fStartTime; std::cerr << "****************** PROFILE ***********************" << std::endl; std::cerr << "Total : " << total << std::endl; @@ -163,4 +198,27 @@ void Profiler::printProfile() { } } +// C interface functions //----------------------------------------------------------------- + +void GfProfStartProfile(const char* pszName) +{ + Profiler::getInstance()->startProfile(pszName); +} + +void GfProfStopProfile(const char* pszName) +{ + // TODO: Why pszName if not used ???? + Profiler::getInstance()->stopProfile(); +} + +void GfProfStopActiveProfiles() +{ + Profiler::getInstance()->stopActiveProfiles(); +} + +void GfProfPrintReport() +{ + Profiler::getInstance()->printReport(); +} + #endif /* PROFILER */ diff --git a/src/libs/tgf/schedulespy.cpp b/src/libs/tgf/schedulespy.cpp index b3511e3d..d852c89f 100755 --- a/src/libs/tgf/schedulespy.cpp +++ b/src/libs/tgf/schedulespy.cpp @@ -3,7 +3,7 @@ file : schedulespy.cpp author : Jean-Philippe Meuret (jpmeuret@free.fr) - A tool to study the way some special code sections (named "events) + A tool to study the way some special code sections (named "events" here) in the program are actually scheduled at a fine grain level. Absolute time and duration are logged in memory each time declared sections are executed. @@ -20,6 +20,8 @@ * * ***************************************************************************/ +#ifdef SCHEDULE_SPY + //#include #include #include @@ -27,8 +29,6 @@ #include "tgf.h" -#ifdef SCHEDULE_SPY - class GfScheduleEventLog { public: @@ -176,9 +176,6 @@ void GfScheduleSpy::printReport(const char* pszFileName, double fTimeResolution) // Not yet implemented. } -#endif // SCHEDULE_SPY - - // C interface functions //----------------------------------------------------------------- /* Configure an event log before using it (can be called more than once to change settings) @@ -186,53 +183,43 @@ void GfScheduleSpy::printReport(const char* pszFileName, double fTimeResolution) \param pszLogName Name/id \param nMaxEvents Maximum number of events to be logged (other ignored) \param dIgnoreDelay Delay (s) before taking Begin/EndEvent into account (from BeginSession time) */ -void GfssConfigureEventLog(const char* pszLogName, unsigned nMaxEvents, double dIgnoreDelay) +void GfSchedConfigureEventLog(const char* pszLogName, unsigned nMaxEvents, double dIgnoreDelay) { -#ifdef SCHEDULE_SPY GfScheduleSpy::self()->configureEventLog(pszLogName, nMaxEvents, dIgnoreDelay); -#endif // SCHEDULE_SPY } /* Start a new spying session @ingroup schedulespy \precondition All event logs must be configured at least once before) */ -void GfssBeginSession() +void GfSchedBeginSession() { -#ifdef SCHEDULE_SPY GfScheduleSpy::self()->beginSession(); -#endif // SCHEDULE_SPY } /* Log the beginning of an event (enter the associated code section) @ingroup schedulespy \precondition BeginSession \param pszLogName Name/id */ -void GfssBeginEvent(const char* pszLogName) +void GfSchedBeginEvent(const char* pszLogName) { -#ifdef SCHEDULE_SPY GfScheduleSpy::self()->beginEvent(pszLogName); -#endif // SCHEDULE_SPY } /* Log the end of an event (exit from the associated code section) @ingroup schedulespy \precondition BeginEvent(pszLogName) \param pszLogName Name/id */ -void GfssEndEvent(const char* pszLogName) +void GfSchedEndEvent(const char* pszLogName) { -#ifdef SCHEDULE_SPY GfScheduleSpy::self()->endEvent(pszLogName); -#endif // SCHEDULE_SPY } /* Terminate the current spying session @ingroup schedulespy \precondition BeginSession */ -void GfssEndSession() +void GfSchedEndSession() { -#ifdef SCHEDULE_SPY GfScheduleSpy::self()->endSession(); -#endif // SCHEDULE_SPY } /* Print a table log (2 columns for each event log : start time and duration) @@ -241,9 +228,9 @@ void GfssEndSession() \param fTimeResolution Time resolution to use (minimum delay between 2 event starts) \precondition EndSession */ -void GfssPrintReport(const char* pszFileName, double fTimeResolution) +void GfSchedPrintReport(const char* pszFileName, double fTimeResolution) { -#ifdef SCHEDULE_SPY GfScheduleSpy::self()->printReport(pszFileName, fTimeResolution); -#endif // SCHEDULE_SPY } + +#endif // SCHEDULE_SPY diff --git a/src/libs/tgf/tgf.h b/src/libs/tgf/tgf.h index 5fe27102..1ab909f7 100644 --- a/src/libs/tgf/tgf.h +++ b/src/libs/tgf/tgf.h @@ -606,55 +606,20 @@ struct { \ **************************************************************************/ #ifdef PROFILER -#include -#include +TGF_API void GfProfStartProfile(const char* pszName); +TGF_API void GfProfStopProfile(const char* pszName); +TGF_API void GfProfStopActiveProfiles(); +TGF_API void GfProfPrintReport(); -#define START_PROFILE(name) Profiler::getInstance()->startProfile(name) -#define STOP_PROFILE(name) Profiler::getInstance()->stopProfile() -#define STOP_ACTIVE_PROFILES() Profiler::getInstance()->stopActiveProfiles() -#define PRINT_PROFILE() Profiler::getInstance()->printProfile() +#else // PROFILER -class ProfileInstance { - public: - ProfileInstance(const char * pname); - ~ProfileInstance(); - char name[256]; - int calls; - int openCalls; - double totalTime; - double addTime; - double subTime; - double tmpStart; - std::map mapChildren; -}; +#define GfProfStartProfile(pszName) +#define GfProfStopProfile(pszName) +#define GfProfStopActiveProfiles() +#define GfProfPrintReport() -class Profiler { - protected: - Profiler(); - public: - ~Profiler(); - static Profiler * getInstance(); - void startProfile(const char * pname); - void stopProfile(); - void stopActiveProfiles(); - void printProfile(); - private: - static Profiler * profiler; - ProfileInstance * curProfile; - double fStartTime; - std::vector vecProfiles; - std::vector stkProfiles; - std::map mapWarning; -}; +#endif // PROFILER -#else /* PROFILER */ - -#define START_PROFILE(a) -#define STOP_PROFILE(a) -#define STOP_ACTIVE_PROFILES() -#define PRINT_PROFILE() - -#endif /************************************************************** * ScheduleSpy definitions. * @@ -664,12 +629,25 @@ class Profiler { * at a fine grain level (see schedulespy.cpp for details). * **************************************************************/ -TGF_API void GfssConfigureEventLog(const char* pszLogName, unsigned nMaxEvents, double dIgnoreDelay); -TGF_API void GfssBeginSession(); -TGF_API void GfssBeginEvent(const char* pszLogName); -TGF_API void GfssEndEvent(const char* pszLogName); -TGF_API void GfssEndSession(); -TGF_API void GfssPrintReport(const char* pszFileName, double fTimeResolution); +#ifdef SCHEDULE_SPY + +TGF_API void GfSchedConfigureEventLog(const char* pszLogName, unsigned nMaxEvents, double dIgnoreDelay); +TGF_API void GfSchedBeginSession(); +TGF_API void GfSchedBeginEvent(const char* pszLogName); +TGF_API void GfSchedEndEvent(const char* pszLogName); +TGF_API void GfSchedEndSession(); +TGF_API void GfSchedPrintReport(const char* pszFileName, double fTimeResolution); + +#else // SCHEDULE_SPY + +#define GfSchedConfigureEventLog(pszLogName, nMaxEvents, dIgnoreDelay) +#define GfSchedBeginSession() +#define GfSchedBeginEvent(pszLogName) +#define GfSchedEndEvent(pszLogName) +#define GfSchedEndSession() +#define GfSchedPrintReport(pszFileName, fTimeResolution) + +#endif // SCHEDULE_SPY /*******************/ diff --git a/src/modules/graphic/ssggraph/grmain.cpp b/src/modules/graphic/ssggraph/grmain.cpp index 36834e6d..2fddaa44 100644 --- a/src/modules/graphic/ssggraph/grmain.cpp +++ b/src/modules/graphic/ssggraph/grmain.cpp @@ -303,7 +303,7 @@ refresh(tSituation *s) { int i; - START_PROFILE("refresh"); + GfProfStartProfile("refresh"); nFrame++; nTotalFrame++; @@ -319,14 +319,14 @@ refresh(tSituation *s) TRACE_GL("refresh: start"); - START_PROFILE("grRefreshSound*"); + GfProfStartProfile("grRefreshSound*"); grRefreshSound(s, grScreens[0]->getCurCamera()); - STOP_PROFILE("grRefreshSound*"); + GfProfStopProfile("grRefreshSound*"); - START_PROFILE("grDrawBackground/glClear"); + GfProfStartProfile("grDrawBackground/glClear"); glDepthFunc(GL_LEQUAL); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - STOP_PROFILE("grDrawBackground/glClear"); + GfProfStopProfile("grDrawBackground/glClear"); for (i = 0; i < GR_NB_MAX_SCREEN; i++) { grScreens[i]->update(s, grFps); @@ -335,7 +335,7 @@ refresh(tSituation *s) grUpdateSmoke(s->currentTime); grTrackLightUpdate(s); - STOP_PROFILE("refresh"); + GfProfStopProfile("refresh"); return 0; } diff --git a/src/modules/graphic/ssggraph/grscreen.cpp b/src/modules/graphic/ssggraph/grscreen.cpp index 17e4614a..badf5d18 100644 --- a/src/modules/graphic/ssggraph/grscreen.cpp +++ b/src/modules/graphic/ssggraph/grscreen.cpp @@ -223,9 +223,9 @@ void cGrScreen::camDraw(tSituation *s) glDisable(GL_COLOR_MATERIAL); - START_PROFILE("dispCam->update*"); + GfProfStartProfile("dispCam->update*"); dispCam->update(curCar, s); - STOP_PROFILE("dispCam->update*"); + GfProfStopProfile("dispCam->update*"); if (dispCam->getDrawBackground()) { glDisable(GL_LIGHTING); @@ -235,11 +235,11 @@ void cGrScreen::camDraw(tSituation *s) } glEnable(GL_DEPTH_TEST); - START_PROFILE("dispCam->action*"); + GfProfStartProfile("dispCam->action*"); dispCam->action(); - STOP_PROFILE("dispCam->action*"); + GfProfStopProfile("dispCam->action*"); - START_PROFILE("grDrawCar*"); + GfProfStartProfile("grDrawCar*"); glFogf(GL_FOG_START, dispCam->getFogStart()); glFogf(GL_FOG_END, dispCam->getFogEnd()); glEnable(GL_FOG); @@ -251,9 +251,9 @@ void cGrScreen::camDraw(tSituation *s) for (i = 0; i < s->_ncars; i++) { grDrawCar(s, cars[i], curCar, dispCam->getDrawCurrent(), dispCam->getDrawDriver(), s->currentTime, dispCam); } - STOP_PROFILE("grDrawCar*"); + GfProfStopProfile("grDrawCar*"); - START_PROFILE("grDrawScene*"); + GfProfStartProfile("grDrawScene*"); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); if (mirrorFlag == 1) @@ -262,7 +262,7 @@ void cGrScreen::camDraw(tSituation *s) speedcar = 0.0f; grDrawScene(speedcar, s); //grDrawScene(); - STOP_PROFILE("grDrawScene*"); + GfProfStopProfile("grDrawScene*"); } @@ -339,18 +339,18 @@ void cGrScreen::update(tSituation *s, float Fps) glViewport (scrx, scry, scrw, scrh); } - START_PROFILE("boardCam*"); + GfProfStartProfile("boardCam*"); boardCam->action(); - STOP_PROFILE("boardCam*"); + GfProfStopProfile("boardCam*"); - START_PROFILE("grDisp**"); + GfProfStartProfile("grDisp**"); glDisable(GL_TEXTURE_2D); TRACE_GL("cGrScreen::update glDisable(GL_DEPTH_TEST)"); board->refreshBoard(s, Fps, 0, curCar); TRACE_GL("cGrScreen::update display boards"); - STOP_PROFILE("grDisp**"); + GfProfStopProfile("grDisp**"); } void cGrScreen::loadParams(tSituation *s)