2017-11-12 21:47:22 -04:00
|
|
|
#include "PerfInfo.h"
|
|
|
|
|
|
|
|
#include <DataFlash/DataFlash.h>
|
2015-05-29 23:12:49 -03:00
|
|
|
|
2012-11-18 12:16:07 -04:00
|
|
|
//
|
|
|
|
// high level performance monitoring
|
|
|
|
//
|
|
|
|
// we measure the main loop time
|
|
|
|
//
|
|
|
|
|
2015-05-04 19:09:12 -03:00
|
|
|
// 400hz loop update rate
|
2017-11-12 21:47:22 -04:00
|
|
|
#define OVERTIME_THRESHOLD_MICROS 3000
|
2012-11-18 12:16:07 -04:00
|
|
|
|
2017-11-12 21:47:22 -04:00
|
|
|
// reset - reset all records of loop time to zero
|
|
|
|
void AP::PerfInfo::reset()
|
2012-11-18 12:16:07 -04:00
|
|
|
{
|
2017-11-12 21:47:22 -04:00
|
|
|
loop_count = 0;
|
|
|
|
max_time = 0;
|
|
|
|
min_time = 0;
|
|
|
|
long_running = 0;
|
|
|
|
log_dropped = DataFlash_Class::instance()->num_dropped();
|
|
|
|
sigma_time = 0;
|
|
|
|
sigmasquared_time = 0;
|
2012-11-18 12:16:07 -04:00
|
|
|
}
|
|
|
|
|
2017-11-12 21:47:22 -04:00
|
|
|
// ignore_loop - ignore this loop from performance measurements (used to reduce false positive when arming)
|
|
|
|
void AP::PerfInfo::ignore_this_loop()
|
2015-02-09 10:07:18 -04:00
|
|
|
{
|
2017-11-12 21:47:22 -04:00
|
|
|
ignore_loop = true;
|
2015-02-09 10:07:18 -04:00
|
|
|
}
|
|
|
|
|
2017-11-12 21:47:22 -04:00
|
|
|
// check_loop_time - check latest loop time vs min, max and overtime threshold
|
|
|
|
void AP::PerfInfo::check_loop_time(uint32_t time_in_micros)
|
2012-11-18 12:16:07 -04:00
|
|
|
{
|
2017-11-12 21:47:22 -04:00
|
|
|
loop_count++;
|
2015-02-09 10:07:18 -04:00
|
|
|
|
|
|
|
// exit if this loop should be ignored
|
2017-11-12 21:47:22 -04:00
|
|
|
if (ignore_loop) {
|
|
|
|
ignore_loop = false;
|
2015-02-09 10:07:18 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-11-12 21:47:22 -04:00
|
|
|
if( time_in_micros > max_time) {
|
|
|
|
max_time = time_in_micros;
|
2012-11-18 12:16:07 -04:00
|
|
|
}
|
2017-11-12 21:47:22 -04:00
|
|
|
if( min_time == 0 || time_in_micros < min_time) {
|
|
|
|
min_time = time_in_micros;
|
2015-02-15 19:02:53 -04:00
|
|
|
}
|
2017-11-12 21:47:22 -04:00
|
|
|
if( time_in_micros > OVERTIME_THRESHOLD_MICROS ) {
|
|
|
|
long_running++;
|
2012-11-18 12:16:07 -04:00
|
|
|
}
|
2017-11-12 21:47:22 -04:00
|
|
|
sigma_time += time_in_micros;
|
|
|
|
sigmasquared_time += time_in_micros * time_in_micros;
|
2012-11-18 12:16:07 -04:00
|
|
|
}
|
|
|
|
|
2017-11-12 21:47:22 -04:00
|
|
|
// get_num_loops: return number of loops used for recording performance
|
|
|
|
uint16_t AP::PerfInfo::get_num_loops() const
|
2012-11-18 12:16:07 -04:00
|
|
|
{
|
2017-11-12 21:47:22 -04:00
|
|
|
return loop_count;
|
2012-11-18 12:16:07 -04:00
|
|
|
}
|
|
|
|
|
2017-11-12 21:47:22 -04:00
|
|
|
// get_max_time - return maximum loop time (in microseconds)
|
|
|
|
uint32_t AP::PerfInfo::get_max_time() const
|
2012-11-18 12:16:07 -04:00
|
|
|
{
|
2017-11-12 21:47:22 -04:00
|
|
|
return max_time;
|
2012-11-18 12:16:07 -04:00
|
|
|
}
|
|
|
|
|
2017-11-12 21:47:22 -04:00
|
|
|
// get_min_time - return minumum loop time (in microseconds)
|
|
|
|
uint32_t AP::PerfInfo::get_min_time() const
|
2015-02-15 19:02:53 -04:00
|
|
|
{
|
2017-11-12 21:47:22 -04:00
|
|
|
return min_time;
|
2015-02-15 19:02:53 -04:00
|
|
|
}
|
|
|
|
|
2017-11-12 21:47:22 -04:00
|
|
|
// get_num_long_running - get number of long running loops
|
|
|
|
uint16_t AP::PerfInfo::get_num_long_running() const
|
2012-11-18 12:16:07 -04:00
|
|
|
{
|
2017-11-12 21:47:22 -04:00
|
|
|
return long_running;
|
2014-03-08 02:16:28 -04:00
|
|
|
}
|
2016-04-21 03:42:25 -03:00
|
|
|
|
2017-11-12 21:47:22 -04:00
|
|
|
// get_num_dropped - get number of dropped log messages
|
|
|
|
uint32_t AP::PerfInfo::get_num_dropped() const
|
2016-04-21 03:42:25 -03:00
|
|
|
{
|
2017-11-12 21:47:22 -04:00
|
|
|
return log_dropped;
|
2016-04-21 03:42:25 -03:00
|
|
|
}
|
2015-11-04 01:42:05 -04:00
|
|
|
|
2017-11-12 21:47:22 -04:00
|
|
|
// get_avg_time - return average loop time (in microseconds)
|
|
|
|
uint32_t AP::PerfInfo::get_avg_time() const
|
2015-11-04 01:42:05 -04:00
|
|
|
{
|
2017-11-12 21:47:22 -04:00
|
|
|
return (sigma_time / loop_count);
|
2015-11-04 01:42:05 -04:00
|
|
|
}
|
|
|
|
|
2017-11-12 21:47:22 -04:00
|
|
|
// get_stddev_time - return stddev of average loop time (in us)
|
|
|
|
uint32_t AP::PerfInfo::get_stddev_time() const
|
2015-11-04 01:42:05 -04:00
|
|
|
{
|
2017-11-12 21:47:22 -04:00
|
|
|
return sqrt((sigmasquared_time - (sigma_time*sigma_time)/loop_count) / loop_count);
|
2015-11-04 01:42:05 -04:00
|
|
|
}
|