From 38226af24ec01e8f0a20d7fd73ef838a69f6ef25 Mon Sep 17 00:00:00 2001 From: ThorstenB Date: Wed, 23 Mar 2011 23:09:02 +0100 Subject: [PATCH] Improve timing statistics Enable/disable and print statistics at run-time. Configurable intervals and filters. --- src/Main/main.cxx | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/Main/main.cxx b/src/Main/main.cxx index 677d0f36b..33bb062bb 100644 --- a/src/Main/main.cxx +++ b/src/Main/main.cxx @@ -121,6 +121,15 @@ static void fgMainLoop( void ) { static SGPropertyNode_ptr frame_signal = fgGetNode("/sim/signals/frame", true); + static SGPropertyNode_ptr _statisticsFlag + = fgGetNode("/sim/timing-statistics/enabled", true); + static SGPropertyNode_ptr _statisticsInterval + = fgGetNode("/sim/timing-statistics/interval-s", true); + static SGPropertyNode_ptr _statiticsMinJitter + = fgGetNode("/sim/timing-statistics/min-jitter-ms", true); + static SGPropertyNode_ptr _statiticsMinTime + = fgGetNode("/sim/timing-statistics/min-time-ms", true); + frame_signal->fireValueChanged(); SGCloudLayer::enable_bump_mapping = fgGetBool("/sim/rendering/bump-mapping"); @@ -206,6 +215,28 @@ static void fgMainLoop( void ) { simgear::sleepForMSec(500); } } + + // print timing statistics + static bool _lastStatisticsFlag = false; + if (_lastStatisticsFlag != _statisticsFlag->getBoolValue()) + { + // flag has changed, update subsystem manager + _lastStatisticsFlag = _statisticsFlag->getBoolValue(); + globals->get_subsystem_mgr()->collectDebugTiming(_lastStatisticsFlag); + } + if (_lastStatisticsFlag) + { + static double elapsed = 0; + elapsed += real_dt; + if (elapsed >= _statisticsInterval->getDoubleValue()) + { + // print and reset timing statistics + globals->get_subsystem_mgr()->printTimingStatistics(_statiticsMinTime->getDoubleValue(), + _statiticsMinJitter->getDoubleValue()); + elapsed = 0; + } + } + simgear::AtomicChangeListener::fireChangeListeners(); SG_LOG( SG_ALL, SG_DEBUG, "" ); -- 2.39.5