From: durk Date: Sun, 14 Oct 2007 13:46:13 +0000 (+0000) Subject: * Fixed memory leak in RenderTexture.cpp (tiny, but still...) X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=25cefd91298485eb94959017b1aa17bc550d2f3f;p=simgear.git * Fixed memory leak in RenderTexture.cpp (tiny, but still...) * Added Timestamping debugging code to SGSubsystems (ported from plib branch). --- diff --git a/simgear/screen/RenderTexture.cpp b/simgear/screen/RenderTexture.cpp index 661ab693..dacd85e4 100644 --- a/simgear/screen/RenderTexture.cpp +++ b/simgear/screen/RenderTexture.cpp @@ -1335,7 +1335,7 @@ void RenderTexture::_ParseModeString(const char *modeString, tokens.push_back(buf); buf = strtok(NULL, " "); } - + free(mode); for (unsigned int i = 0; i < tokens.size(); i++) { string token = tokens[i]; diff --git a/simgear/structure/subsystem_mgr.cxx b/simgear/structure/subsystem_mgr.cxx index 3be90962..2adf0e78 100644 --- a/simgear/structure/subsystem_mgr.cxx +++ b/simgear/structure/subsystem_mgr.cxx @@ -1,5 +1,6 @@ #include +#include #include "exception.hxx" #include "subsystem_mgr.hxx" @@ -70,6 +71,32 @@ SGSubsystem::is_suspended () const } +void +SGSubsystem::printTimingInformation () +{ + SGTimeStamp startTime, endTime; + long duration; + for ( eventTimeVecIterator i = timingInfo.begin(); + i != timingInfo.end(); + i++) { + if (i == timingInfo.begin()) { + startTime = i->getTime(); + } else { + endTime = i->getTime(); + duration = (endTime - startTime); + startTime = endTime; + SG_LOG(SG_GENERAL, SG_ALERT, "- Getting to timestamp : " << i->getName() << " takes " << duration << " usec."); + } + } +} + +void SGSubsystem::stamp(string name) +{ + SGTimeStamp now; + now.stamp(); + timingInfo.push_back(TimingInfo(name, now)); +} + //////////////////////////////////////////////////////////////////////// // Implementation of SGSubsystemGroup. @@ -124,7 +151,18 @@ void SGSubsystemGroup::update (double delta_time_sec) { for (unsigned int i = 0; i < _members.size(); i++) - _members[i]->update(delta_time_sec); // indirect call + { + SGTimeStamp start, now; + start.stamp(); + _members[i]->update(delta_time_sec); // indirect call + now.stamp(); + long b = ( now - start ); + if ( b > 10000 ) { + SG_LOG(SG_GENERAL, SG_ALERT, "Subsystem Timing Alert : " << b << " " << _members[i]->name); + //int a = 1; + _members[i]->printTimingInformation(); + } + } } void @@ -240,6 +278,13 @@ SGSubsystemGroup::Member::update (double delta_time_sec) } +void +SGSubsystemGroup::Member::printTimingInformation() +{ + subsystem->printTimingInformation(); +} + + //////////////////////////////////////////////////////////////////////// // Implementation of SGSubsystemMgr. diff --git a/simgear/structure/subsystem_mgr.hxx b/simgear/structure/subsystem_mgr.hxx index c13c25d9..a4844903 100644 --- a/simgear/structure/subsystem_mgr.hxx +++ b/simgear/structure/subsystem_mgr.hxx @@ -38,10 +38,31 @@ SG_USING_STD(string); SG_USING_STD(vector); #endif +#include #include +#include SG_USING_STD(map); +SG_USING_STD(vector); +SG_USING_STD(string); #include +#include + + +class TimingInfo +{ +private: + string eventName; + SGTimeStamp time; + +public: + TimingInfo(string name, SGTimeStamp &t) { eventName = name; time = t;}; + string getName() { return eventName; }; + SGTimeStamp getTime() { return time; }; +}; + +typedef vector eventTimeVec; +typedef vector::iterator eventTimeVecIterator; @@ -235,11 +256,18 @@ public: */ virtual bool is_suspended () const; + void printTimingInformation(); + + void stamp(string name); + protected: bool _suspended; + eventTimeVec timingInfo; + //int test; + }; @@ -271,6 +299,7 @@ public: virtual void remove_subsystem (const string &name); virtual bool has_subsystem (const string &name) const; + private: struct Member { @@ -280,6 +309,7 @@ private: virtual ~Member (); virtual void update (double delta_time_sec); + void printTimingInformation(); string name; SGSubsystem * subsystem;