]> git.mxchange.org Git - simgear.git/commitdiff
* Fixed memory leak in RenderTexture.cpp (tiny, but still...)
authordurk <durk>
Sun, 14 Oct 2007 13:46:13 +0000 (13:46 +0000)
committerdurk <durk>
Sun, 14 Oct 2007 13:46:13 +0000 (13:46 +0000)
* Added Timestamping debugging code to SGSubsystems (ported from plib
  branch).

simgear/screen/RenderTexture.cpp
simgear/structure/subsystem_mgr.cxx
simgear/structure/subsystem_mgr.hxx

index 661ab69399381f7fb90a3abb829789f86c67545b..dacd85e466147bf72601f77c7ad227606c5c0e02 100644 (file)
@@ -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];
index 3be9096233ac67f9258c19a9e5b594e2c7398c8b..2adf0e7841176c00bbe93bb5e960c929fb0a8437 100644 (file)
@@ -1,5 +1,6 @@
 
 #include <simgear/debug/logstream.hxx>
+#include <simgear/timing/timestamp.hxx>
 
 #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));
+}
+
 \f
 ////////////////////////////////////////////////////////////////////////
 // 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();
+}
+
+
 \f
 ////////////////////////////////////////////////////////////////////////
 // Implementation of SGSubsystemMgr.
index c13c25d9ae0da4cfa78c9802bccd3f0fb49e6c35..a4844903c4f2e897cf9efa00d7292fdb7cea9860 100644 (file)
@@ -38,10 +38,31 @@ SG_USING_STD(string);
 SG_USING_STD(vector);
 #endif
 
+#include <string>
 #include <map>
+#include <vector>
 SG_USING_STD(map);
+SG_USING_STD(vector);
+SG_USING_STD(string);
 
 #include <simgear/props/props.hxx>
+#include <simgear/timing/timestamp.hxx>
+
+
+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<TimingInfo> eventTimeVec;
+typedef vector<TimingInfo>::iterator eventTimeVecIterator;
 
 
 \f
@@ -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;