From: ThorstenB Date: Mon, 2 Apr 2012 18:26:17 +0000 (+0200) Subject: performance monitor improvement X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=2fed46e2229ff0a989318ed79dcda3c14c5340f9;p=simgear.git performance monitor improvement Record cumulative time consumed (all time) and current total time (current measurement only) for subsystems. --- diff --git a/simgear/structure/SGPerfMon.cxx b/simgear/structure/SGPerfMon.cxx index 43fab6d2..68bdd9f0 100644 --- a/simgear/structure/SGPerfMon.cxx +++ b/simgear/structure/SGPerfMon.cxx @@ -52,8 +52,6 @@ SGPerformanceMonitor::bind(void) _statiticsSubsystems = _root->getChild("subsystems", 0, true); _statisticsFlag = _root->getChild("enabled", 0, true); _statisticsInterval = _root->getChild("interval-s", 0, true); -// _statiticsMinJitter = _root->getChild("min-jitter-ms", 0, true); -// _statiticsMinTime = _root->getChild("min-time-ms", 0, true); } void @@ -62,8 +60,6 @@ SGPerformanceMonitor::unbind(void) _statiticsSubsystems = 0; _statisticsFlag = 0; _statisticsInterval = 0; -// _statiticsMinJitter = 0; -// _statiticsMinTime = 0; } void @@ -110,12 +106,13 @@ SGPerformanceMonitor::reportTiming(const string& name, SampleStatistic* timeStat { SGPropertyNode* node = _statiticsSubsystems->getChild("subsystem",_count++,true); - double minMs = timeStat->min() / 1000; - double maxMs = timeStat->max() / 1000; - double meanMs = timeStat->mean() / 1000; - double stdDevMs = timeStat->stdDev() / 1000; - double totalMs = timeStat->total() / 1000; - int samples = timeStat->samples(); + double minMs = timeStat->min() / 1000; + double maxMs = timeStat->max() / 1000; + double meanMs = timeStat->mean() / 1000; + double stdDevMs = timeStat->stdDev() / 1000; + double totalMs = timeStat->total() / 1000; + double cumulativeMs = timeStat->cumulative() / 1000; + int samples = timeStat->samples(); node->setStringValue("name", name); node->setDoubleValue("min-ms", minMs); @@ -123,6 +120,7 @@ SGPerformanceMonitor::reportTiming(const string& name, SampleStatistic* timeStat node->setDoubleValue("mean-ms", meanMs); node->setDoubleValue("stddev-ms", stdDevMs); node->setDoubleValue("total-ms", totalMs); + node->setDoubleValue("cumulative-ms", cumulativeMs); node->setDoubleValue("count",samples); timeStat->reset(); diff --git a/simgear/structure/SGPerfMon.hxx b/simgear/structure/SGPerfMon.hxx index d3009702..47492aa7 100644 --- a/simgear/structure/SGPerfMon.hxx +++ b/simgear/structure/SGPerfMon.hxx @@ -54,8 +54,6 @@ private: SGPropertyNode_ptr _statiticsSubsystems; SGPropertyNode_ptr _statisticsFlag; SGPropertyNode_ptr _statisticsInterval; -// SGPropertyNode_ptr _statiticsMinJitter; -// SGPropertyNode_ptr _statiticsMinTime; bool _isEnabled; int _count; diff --git a/simgear/structure/SGSmplstat.cxx b/simgear/structure/SGSmplstat.cxx index 3135cf0b..4080b05f 100644 --- a/simgear/structure/SGSmplstat.cxx +++ b/simgear/structure/SGSmplstat.cxx @@ -36,7 +36,7 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. void SampleStatistic::error (const char *msg) { - SG_LOG(SG_GENERAL, SG_ALERT, msg); + SG_LOG(SG_GENERAL, SG_ALERT, msg); } // t-distribution: given p-value and degrees of freedom, return t-value @@ -44,58 +44,62 @@ void SampleStatistic::error (const char *msg) double tval (double p, int df) { - double t; - int positive = p >= 0.5; - p = (positive) ? 1.0 - p : p; - if (p <= 0.0 || df <= 0) - t = HUGE_VAL; - else if (p == 0.5) - t = 0.0; - else if (df == 1) - t = 1.0 / tan ((p + p) * 1.57079633); - else if (df == 2) - t = sqrt (1.0 / ((p + p) * (1.0 - p)) - 2.0); - else + double t; + int positive = p >= 0.5; + p = (positive) ? 1.0 - p : p; + if (p <= 0.0 || df <= 0) + t = HUGE_VAL; + else if (p == 0.5) + t = 0.0; + else if (df == 1) + t = 1.0 / tan ((p + p) * 1.57079633); + else if (df == 2) + t = sqrt (1.0 / ((p + p) * (1.0 - p)) - 2.0); + else { - double ddf = df; - double a = sqrt (log (1.0 / (p * p))); - double aa = a * a; - a = a - ((2.515517 + (0.802853 * a) + (0.010328 * aa)) / - (1.0 + (1.432788 * a) + (0.189269 * aa) + - (0.001308 * aa * a))); - t = ddf - 0.666666667 + 1.0 / (10.0 * ddf); - t = sqrt (ddf * (exp (a * a * (ddf - 0.833333333) / (t * t)) - 1.0)); + double ddf = df; + double a = sqrt (log (1.0 / (p * p))); + double aa = a * a; + a = a - ((2.515517 + (0.802853 * a) + (0.010328 * aa)) / + (1.0 + (1.432788 * a) + (0.189269 * aa) + + (0.001308 * aa * a))); + t = ddf - 0.666666667 + 1.0 / (10.0 * ddf); + t = sqrt (ddf * (exp (a * a * (ddf - 0.833333333) / (t * t)) - 1.0)); } - return (positive) ? t : -t; + return (positive) ? t : -t; } void SampleStatistic::reset () { - n = 0; - x = x2 = 0.0; - maxValue = -HUGE_VAL; - minValue = HUGE_VAL; + n = 0; + x = x2 = 0.0; + totalTime = 0.0; + maxValue = -HUGE_VAL; + minValue = HUGE_VAL; } void SampleStatistic::operator += (double value) { - n += 1; - x += value; - allTimeTotal += value; - x2 += (value * value); - if (minValue > value) - minValue = value; - if (maxValue < value) - maxValue = value; + n += 1; + x += value; + totalTime += value; + cumulativeTime += value; + x2 += (value * value); + + if (minValue > value) + minValue = value; + + if (maxValue < value) + maxValue = value; } double SampleStatistic::mean () const { - if (n > 0) + if (n > 0) { return (x / n); } - else + else { return (0.0); } @@ -103,23 +107,23 @@ double SampleStatistic::mean () const double SampleStatistic::var () const { - if (n > 1) + if (n > 1) { - return ((x2 - ((x * x) / n)) / (n - 1)); + return ((x2 - ((x * x) / n)) / (n - 1)); } - else + else { - return (0.0); + return (0.0); } } double SampleStatistic::stdDev () const { - if (n <= 0 || this->var () <= 0) + if (n <= 0 || this->var () <= 0) { return (0); } - else + else { return ((double) sqrt (var ())); } @@ -127,24 +131,24 @@ double SampleStatistic::stdDev () const double SampleStatistic::confidence (int interval) const { - int df = n - 1; - if (df <= 0) - return HUGE_VAL; - double t = tval (double (100 + interval) * 0.005, df); - if (t == HUGE_VAL) - return t; - else - return (t * stdDev ()) / sqrt (double (n)); + int df = n - 1; + if (df <= 0) + return HUGE_VAL; + double t = tval (double (100 + interval) * 0.005, df); + if (t == HUGE_VAL) + return t; + else + return (t * stdDev ()) / sqrt (double (n)); } double SampleStatistic::confidence (double p_value) const { - int df = n - 1; - if (df <= 0) - return HUGE_VAL; - double t = tval ((1.0 + p_value) * 0.5, df); - if (t == HUGE_VAL) - return t; - else - return (t * stdDev ()) / sqrt (double (n)); + int df = n - 1; + if (df <= 0) + return HUGE_VAL; + double t = tval ((1.0 + p_value) * 0.5, df); + if (t == HUGE_VAL) + return t; + else + return (t * stdDev ()) / sqrt (double (n)); } diff --git a/simgear/structure/SGSmplstat.hxx b/simgear/structure/SGSmplstat.hxx index d8e29b3f..c32fef5d 100644 --- a/simgear/structure/SGSmplstat.hxx +++ b/simgear/structure/SGSmplstat.hxx @@ -30,9 +30,10 @@ protected: double x; double x2; double minValue, maxValue; - double allTimeTotal; + double totalTime, cumulativeTime; -public: SampleStatistic (); +public: + SampleStatistic (); inline virtual ~ SampleStatistic (); virtual void reset (); @@ -44,40 +45,43 @@ public: SampleStatistic (); double min () const; double max () const; double total () const; + double cumulative () const; double confidence (int p_percentage) const; double confidence (double p_value) const; void error (const char *msg); }; -// error handlers - -//extern void default_SampleStatistic_error_handler (const char *); -//extern one_arg_error_handler_t SampleStatistic_error_handler; - -//extern one_arg_error_handler_t -//set_SampleStatistic_error_handler (one_arg_error_handler_t f); inline SampleStatistic::SampleStatistic () { - allTimeTotal = 0; + cumulativeTime = 0; reset (); } + inline int SampleStatistic::samples () const { return (n); } + inline double SampleStatistic::min () const { return (minValue); } + inline double SampleStatistic::max () const { return (maxValue); } + inline double SampleStatistic::total () const { - return (allTimeTotal); + return (totalTime); +} + +inline double SampleStatistic::cumulative () const +{ + return (cumulativeTime); } inline SampleStatistic::~SampleStatistic () diff --git a/simgear/structure/subsystem_mgr.cxx b/simgear/structure/subsystem_mgr.cxx index 6bd7b394..df2c0ef3 100644 --- a/simgear/structure/subsystem_mgr.cxx +++ b/simgear/structure/subsystem_mgr.cxx @@ -210,11 +210,11 @@ SGSubsystemGroup::update (double delta_time_sec) delta_time_sec = _fixedUpdateTime; } + bool recordTime = (reportTimingCb != NULL); SGTimeStamp timeStamp; while (loopCount-- > 0) { for (unsigned int i = 0; i < _members.size(); i++) { - bool recordTime = (reportTimingCb != NULL); if (recordTime) timeStamp = SGTimeStamp::now();