#include "exception.hxx"
#include "subsystem_mgr.hxx"
+#include <simgear/math/SGMath.hxx>
+
\f
////////////////////////////////////////////////////////////////////////
void
SGSubsystem::printTimingInformation ()
{
- SGTimeStamp startTime, endTime;
- long duration;
+ SGTimeStamp startTime;
for ( eventTimeVecIterator i = timingInfo.begin();
i != timingInfo.end();
i++) {
if (i == timingInfo.begin()) {
startTime = i->getTime();
} else {
- endTime = i->getTime();
- duration = (endTime - startTime);
+ SGTimeStamp endTime = i->getTime();
+ SG_LOG(SG_GENERAL, SG_ALERT, "- Getting to timestamp : "
+ << i->getName() << " takes " << endTime - startTime
+ << " sec.");
startTime = endTime;
- SG_LOG(SG_GENERAL, SG_ALERT, "- Getting to timestamp : " << i->getName() << " takes " << duration << " usec.");
}
}
}
-void SGSubsystem::stamp(string name)
+
+
+void SGSubsystem::stamp(const string& name)
{
- SGTimeStamp now;
- now.stamp();
- timingInfo.push_back(TimingInfo(name, now));
+ timingInfo.push_back(TimingInfo(name, SGTimeStamp::now()));
}
\f
SGSubsystemGroup::~SGSubsystemGroup ()
{
for (unsigned int i = 0; i < _members.size(); i++)
+ {
+ _members[i]->printTimingStatistics();
delete _members[i];
+ }
}
void
{
for (unsigned int i = 0; i < _members.size(); i++)
{
- SGTimeStamp start, now;
- start.stamp();
+ SGTimeStamp timeStamp = SGTimeStamp::now();
_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();
+ timeStamp = timeStamp - SGTimeStamp::now();
+ double b = timeStamp.toUSecs();
+ _members[i]->updateExecutionTime(b);
+ double threshold = _members[i]->getTimeWarningThreshold();
+ if (( b > threshold ) && (b > 10000)) {
+ _members[i]->printTimingInformation(b);
}
}
}
+void
+SGSubsystemGroup::collectDebugTiming(bool collect)
+{
+ for (unsigned int i = 0; i < _members.size(); i++)
+ {
+ _members[i]->collectDebugTiming(collect);
+ }
+}
+
void
SGSubsystemGroup::suspend ()
{
}
}
+void
+SGSubsystemGroup::Member::printTimingStatistics ()
+{
+ if (collectTimeStats) {
+ double minTime = timeStat.min() / 1000;
+ double maxTime = timeStat.max() / 1000;
+ double meanTime = timeStat.mean() / 1000;
+ double stddev = timeStat.stdDev() / 1000;
+
+ char buffer[256];
+ snprintf(buffer, 256, "Timing summary for %20s.\n"
+ "- mean time: %04.2f ms.\n"
+ "- min time : %04.2f ms.\n"
+ "- max time : %04.2f ms.\n"
+ "- stddev : %04.2f ms.\n", name.c_str(), meanTime, minTime, maxTime, stddev);
+ SG_LOG(SG_GENERAL, SG_ALERT, buffer);
+ }
+}
+
+
bool
SGSubsystemGroup::has_subsystem (const string &name) const
{
: name(""),
subsystem(0),
min_step_sec(0),
- elapsed_sec(0)
+ elapsed_sec(0),
+ collectTimeStats(false)
{
}
+// This shouldn't be called due to subsystem pointer ownership issues.
SGSubsystemGroup::Member::Member (const Member &)
{
- Member();
}
SGSubsystemGroup::Member::~Member ()
void
-SGSubsystemGroup::Member::printTimingInformation()
+SGSubsystemGroup::Member::printTimingInformation(double time)
+{
+ if (collectTimeStats) {
+ SG_LOG(SG_GENERAL, SG_ALERT, "Subsystem Timing Alert : " << time << " " << name);
+ subsystem->printTimingInformation();
+ }
+}
+
+double SGSubsystemGroup::Member::getTimeWarningThreshold()
{
- subsystem->printTimingInformation();
+ return (timeStat.mean() + 3 * timeStat.stdDev());
+}
+
+void SGSubsystemGroup::Member::updateExecutionTime(double time)
+{
+ if (collectTimeStats) {
+ timeStat += time;
+ }
}
+
+
\f
////////////////////////////////////////////////////////////////////////
// Implementation of SGSubsystemMgr.
}
}
+void
+SGSubsystemMgr::collectDebugTiming(bool collect)
+{
+ for (int i = 0; i < MAX_GROUPS; i++) {
+ _groups[i].collectDebugTiming(collect);
+ }
+}
+
void
SGSubsystemMgr::suspend ()
{