X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fstructure%2Fsubsystem_mgr.cxx;h=00f17b38acefee08a24c03af5ea797e3d98b8021;hb=d219c5c4c613e4f36d8ff1ce8af674fc96dcb543;hp=3be9096233ac67f9258c19a9e5b594e2c7398c8b;hpb=a75b4af3744039072c7a03ef4ed6fcb536763937;p=simgear.git diff --git a/simgear/structure/subsystem_mgr.cxx b/simgear/structure/subsystem_mgr.cxx index 3be90962..00f17b38 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,34 @@ 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. @@ -82,7 +111,10 @@ SGSubsystemGroup::SGSubsystemGroup () SGSubsystemGroup::~SGSubsystemGroup () { for (unsigned int i = 0; i < _members.size(); i++) + { + _members[i]->printTimingStatistics(); delete _members[i]; + } } void @@ -124,7 +156,27 @@ 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 ); + _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 @@ -180,6 +232,26 @@ SGSubsystemGroup::remove_subsystem (const string &name) } } +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 { @@ -213,7 +285,8 @@ SGSubsystemGroup::Member::Member () : name(""), subsystem(0), min_step_sec(0), - elapsed_sec(0) + elapsed_sec(0), + collectTimeStats(false) { } @@ -240,6 +313,30 @@ SGSubsystemGroup::Member::update (double delta_time_sec) } +void +SGSubsystemGroup::Member::printTimingInformation(double time) +{ + if (collectTimeStats) { + SG_LOG(SG_GENERAL, SG_ALERT, "Subsystem Timing Alert : " << time << " " << name); + subsystem->printTimingInformation(); + } +} + +double SGSubsystemGroup::Member::getTimeWarningThreshold() +{ + return (timeStat.mean() + 3 * timeStat.stdDev()); +} + +void SGSubsystemGroup::Member::updateExecutionTime(double time) +{ + if (collectTimeStats) { + timeStat += time; + } +} + + + + //////////////////////////////////////////////////////////////////////// // Implementation of SGSubsystemMgr. @@ -297,6 +394,14 @@ SGSubsystemMgr::update (double delta_time_sec) } } +void +SGSubsystemMgr::collectDebugTiming(bool collect) +{ + for (int i = 0; i < MAX_GROUPS; i++) { + _groups[i].collectDebugTiming(collect); + } +} + void SGSubsystemMgr::suspend () {