_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
_statiticsSubsystems = 0;
_statisticsFlag = 0;
_statisticsInterval = 0;
-// _statiticsMinJitter = 0;
-// _statiticsMinTime = 0;
}
void
{
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);
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();
SGPropertyNode_ptr _statiticsSubsystems;
SGPropertyNode_ptr _statisticsFlag;
SGPropertyNode_ptr _statisticsInterval;
-// SGPropertyNode_ptr _statiticsMinJitter;
-// SGPropertyNode_ptr _statiticsMinTime;
bool _isEnabled;
int _count;
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
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);
}
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 ()));
}
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));
}
double x;
double x2;
double minValue, maxValue;
- double allTimeTotal;
+ double totalTime, cumulativeTime;
-public: SampleStatistic ();
+public:
+ SampleStatistic ();
inline virtual ~ SampleStatistic ();
virtual void reset ();
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 ()
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();