performance monitor improvement

Record cumulative time consumed (all time) and current total time (current
measurement only) for subsystems.
This commit is contained in:
ThorstenB 2012-04-02 20:26:17 +02:00
parent 9ad070871a
commit 2fed46e222
5 changed files with 86 additions and 82 deletions

View File

@ -52,8 +52,6 @@ SGPerformanceMonitor::bind(void)
_statiticsSubsystems = _root->getChild("subsystems", 0, true); _statiticsSubsystems = _root->getChild("subsystems", 0, true);
_statisticsFlag = _root->getChild("enabled", 0, true); _statisticsFlag = _root->getChild("enabled", 0, true);
_statisticsInterval = _root->getChild("interval-s", 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 void
@ -62,8 +60,6 @@ SGPerformanceMonitor::unbind(void)
_statiticsSubsystems = 0; _statiticsSubsystems = 0;
_statisticsFlag = 0; _statisticsFlag = 0;
_statisticsInterval = 0; _statisticsInterval = 0;
// _statiticsMinJitter = 0;
// _statiticsMinTime = 0;
} }
void void
@ -110,12 +106,13 @@ SGPerformanceMonitor::reportTiming(const string& name, SampleStatistic* timeStat
{ {
SGPropertyNode* node = _statiticsSubsystems->getChild("subsystem",_count++,true); SGPropertyNode* node = _statiticsSubsystems->getChild("subsystem",_count++,true);
double minMs = timeStat->min() / 1000; double minMs = timeStat->min() / 1000;
double maxMs = timeStat->max() / 1000; double maxMs = timeStat->max() / 1000;
double meanMs = timeStat->mean() / 1000; double meanMs = timeStat->mean() / 1000;
double stdDevMs = timeStat->stdDev() / 1000; double stdDevMs = timeStat->stdDev() / 1000;
double totalMs = timeStat->total() / 1000; double totalMs = timeStat->total() / 1000;
int samples = timeStat->samples(); double cumulativeMs = timeStat->cumulative() / 1000;
int samples = timeStat->samples();
node->setStringValue("name", name); node->setStringValue("name", name);
node->setDoubleValue("min-ms", minMs); node->setDoubleValue("min-ms", minMs);
@ -123,6 +120,7 @@ SGPerformanceMonitor::reportTiming(const string& name, SampleStatistic* timeStat
node->setDoubleValue("mean-ms", meanMs); node->setDoubleValue("mean-ms", meanMs);
node->setDoubleValue("stddev-ms", stdDevMs); node->setDoubleValue("stddev-ms", stdDevMs);
node->setDoubleValue("total-ms", totalMs); node->setDoubleValue("total-ms", totalMs);
node->setDoubleValue("cumulative-ms", cumulativeMs);
node->setDoubleValue("count",samples); node->setDoubleValue("count",samples);
timeStat->reset(); timeStat->reset();

View File

@ -54,8 +54,6 @@ private:
SGPropertyNode_ptr _statiticsSubsystems; SGPropertyNode_ptr _statiticsSubsystems;
SGPropertyNode_ptr _statisticsFlag; SGPropertyNode_ptr _statisticsFlag;
SGPropertyNode_ptr _statisticsInterval; SGPropertyNode_ptr _statisticsInterval;
// SGPropertyNode_ptr _statiticsMinJitter;
// SGPropertyNode_ptr _statiticsMinTime;
bool _isEnabled; bool _isEnabled;
int _count; int _count;

View File

@ -36,7 +36,7 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
void SampleStatistic::error (const char *msg) 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 // 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 tval (double p, int df)
{ {
double t; double t;
int positive = p >= 0.5; int positive = p >= 0.5;
p = (positive) ? 1.0 - p : p; p = (positive) ? 1.0 - p : p;
if (p <= 0.0 || df <= 0) if (p <= 0.0 || df <= 0)
t = HUGE_VAL; t = HUGE_VAL;
else if (p == 0.5) else if (p == 0.5)
t = 0.0; t = 0.0;
else if (df == 1) else if (df == 1)
t = 1.0 / tan ((p + p) * 1.57079633); t = 1.0 / tan ((p + p) * 1.57079633);
else if (df == 2) else if (df == 2)
t = sqrt (1.0 / ((p + p) * (1.0 - p)) - 2.0); t = sqrt (1.0 / ((p + p) * (1.0 - p)) - 2.0);
else else
{ {
double ddf = df; double ddf = df;
double a = sqrt (log (1.0 / (p * p))); double a = sqrt (log (1.0 / (p * p)));
double aa = a * a; double aa = a * a;
a = a - ((2.515517 + (0.802853 * a) + (0.010328 * aa)) / a = a - ((2.515517 + (0.802853 * a) + (0.010328 * aa)) /
(1.0 + (1.432788 * a) + (0.189269 * aa) + (1.0 + (1.432788 * a) + (0.189269 * aa) +
(0.001308 * aa * a))); (0.001308 * aa * a)));
t = ddf - 0.666666667 + 1.0 / (10.0 * ddf); t = ddf - 0.666666667 + 1.0 / (10.0 * ddf);
t = sqrt (ddf * (exp (a * a * (ddf - 0.833333333) / (t * t)) - 1.0)); t = sqrt (ddf * (exp (a * a * (ddf - 0.833333333) / (t * t)) - 1.0));
} }
return (positive) ? t : -t; return (positive) ? t : -t;
} }
void SampleStatistic::reset () void SampleStatistic::reset ()
{ {
n = 0; n = 0;
x = x2 = 0.0; x = x2 = 0.0;
maxValue = -HUGE_VAL; totalTime = 0.0;
minValue = HUGE_VAL; maxValue = -HUGE_VAL;
minValue = HUGE_VAL;
} }
void SampleStatistic::operator += (double value) void SampleStatistic::operator += (double value)
{ {
n += 1; n += 1;
x += value; x += value;
allTimeTotal += value; totalTime += value;
x2 += (value * value); cumulativeTime += value;
if (minValue > value) x2 += (value * value);
minValue = value;
if (maxValue < value) if (minValue > value)
maxValue = value; minValue = value;
if (maxValue < value)
maxValue = value;
} }
double SampleStatistic::mean () const double SampleStatistic::mean () const
{ {
if (n > 0) if (n > 0)
{ {
return (x / n); return (x / n);
} }
else else
{ {
return (0.0); return (0.0);
} }
@ -103,23 +107,23 @@ double SampleStatistic::mean () const
double SampleStatistic::var () 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 double SampleStatistic::stdDev () const
{ {
if (n <= 0 || this->var () <= 0) if (n <= 0 || this->var () <= 0)
{ {
return (0); return (0);
} }
else else
{ {
return ((double) sqrt (var ())); return ((double) sqrt (var ()));
} }
@ -127,24 +131,24 @@ double SampleStatistic::stdDev () const
double SampleStatistic::confidence (int interval) const double SampleStatistic::confidence (int interval) const
{ {
int df = n - 1; int df = n - 1;
if (df <= 0) if (df <= 0)
return HUGE_VAL; return HUGE_VAL;
double t = tval (double (100 + interval) * 0.005, df); double t = tval (double (100 + interval) * 0.005, df);
if (t == HUGE_VAL) if (t == HUGE_VAL)
return t; return t;
else else
return (t * stdDev ()) / sqrt (double (n)); return (t * stdDev ()) / sqrt (double (n));
} }
double SampleStatistic::confidence (double p_value) const double SampleStatistic::confidence (double p_value) const
{ {
int df = n - 1; int df = n - 1;
if (df <= 0) if (df <= 0)
return HUGE_VAL; return HUGE_VAL;
double t = tval ((1.0 + p_value) * 0.5, df); double t = tval ((1.0 + p_value) * 0.5, df);
if (t == HUGE_VAL) if (t == HUGE_VAL)
return t; return t;
else else
return (t * stdDev ()) / sqrt (double (n)); return (t * stdDev ()) / sqrt (double (n));
} }

View File

@ -30,9 +30,10 @@ protected:
double x; double x;
double x2; double x2;
double minValue, maxValue; double minValue, maxValue;
double allTimeTotal; double totalTime, cumulativeTime;
public: SampleStatistic (); public:
SampleStatistic ();
inline virtual ~ SampleStatistic (); inline virtual ~ SampleStatistic ();
virtual void reset (); virtual void reset ();
@ -44,40 +45,43 @@ public: SampleStatistic ();
double min () const; double min () const;
double max () const; double max () const;
double total () const; double total () const;
double cumulative () const;
double confidence (int p_percentage) const; double confidence (int p_percentage) const;
double confidence (double p_value) const; double confidence (double p_value) const;
void error (const char *msg); 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 () inline SampleStatistic::SampleStatistic ()
{ {
allTimeTotal = 0; cumulativeTime = 0;
reset (); reset ();
} }
inline int SampleStatistic::samples () const inline int SampleStatistic::samples () const
{ {
return (n); return (n);
} }
inline double SampleStatistic::min () const inline double SampleStatistic::min () const
{ {
return (minValue); return (minValue);
} }
inline double SampleStatistic::max () const inline double SampleStatistic::max () const
{ {
return (maxValue); return (maxValue);
} }
inline double SampleStatistic::total () const inline double SampleStatistic::total () const
{ {
return (allTimeTotal); return (totalTime);
}
inline double SampleStatistic::cumulative () const
{
return (cumulativeTime);
} }
inline SampleStatistic::~SampleStatistic () inline SampleStatistic::~SampleStatistic ()

View File

@ -210,11 +210,11 @@ SGSubsystemGroup::update (double delta_time_sec)
delta_time_sec = _fixedUpdateTime; delta_time_sec = _fixedUpdateTime;
} }
bool recordTime = (reportTimingCb != NULL);
SGTimeStamp timeStamp; SGTimeStamp timeStamp;
while (loopCount-- > 0) { while (loopCount-- > 0) {
for (unsigned int i = 0; i < _members.size(); i++) for (unsigned int i = 0; i < _members.size(); i++)
{ {
bool recordTime = (reportTimingCb != NULL);
if (recordTime) if (recordTime)
timeStamp = SGTimeStamp::now(); timeStamp = SGTimeStamp::now();