2015-05-29 23:12:49 -03:00
|
|
|
#include "Copter.h"
|
|
|
|
|
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
|
|
|
|
#define PERF_INFO_OVERTIME_THRESHOLD_MICROS 3000
|
2012-11-18 12:16:07 -04:00
|
|
|
|
2015-02-15 19:02:53 -04:00
|
|
|
static uint16_t perf_info_loop_count;
|
2017-07-15 02:37:15 -03:00
|
|
|
static uint32_t perf_info_max_time; // in microseconds
|
|
|
|
static uint32_t perf_info_min_time; // in microseconds
|
2015-11-04 01:42:05 -04:00
|
|
|
static uint64_t perf_info_sigma_time;
|
|
|
|
static uint64_t perf_info_sigmasquared_time;
|
2015-02-15 19:02:53 -04:00
|
|
|
static uint16_t perf_info_long_running;
|
2016-04-21 03:42:25 -03:00
|
|
|
static uint32_t perf_info_log_dropped;
|
2015-02-15 19:02:53 -04:00
|
|
|
static bool perf_ignore_loop = false;
|
2012-11-18 12:16:07 -04:00
|
|
|
|
|
|
|
// perf_info_reset - reset all records of loop time to zero
|
2015-05-29 23:12:49 -03:00
|
|
|
void Copter::perf_info_reset()
|
2012-11-18 12:16:07 -04:00
|
|
|
{
|
|
|
|
perf_info_loop_count = 0;
|
|
|
|
perf_info_max_time = 0;
|
2015-02-15 19:02:53 -04:00
|
|
|
perf_info_min_time = 0;
|
2012-11-18 12:16:07 -04:00
|
|
|
perf_info_long_running = 0;
|
2016-04-21 03:42:25 -03:00
|
|
|
perf_info_log_dropped = DataFlash.num_dropped();
|
2015-11-04 01:42:05 -04:00
|
|
|
perf_info_sigma_time = 0;
|
|
|
|
perf_info_sigmasquared_time = 0;
|
2012-11-18 12:16:07 -04:00
|
|
|
}
|
|
|
|
|
2015-02-09 10:07:18 -04:00
|
|
|
// perf_ignore_loop - ignore this loop from performance measurements (used to reduce false positive when arming)
|
2015-05-29 23:12:49 -03:00
|
|
|
void Copter::perf_ignore_this_loop()
|
2015-02-09 10:07:18 -04:00
|
|
|
{
|
|
|
|
perf_ignore_loop = true;
|
|
|
|
}
|
|
|
|
|
2012-11-18 12:16:07 -04:00
|
|
|
// perf_info_check_loop_time - check latest loop time vs min, max and overtime threshold
|
2015-05-29 23:12:49 -03:00
|
|
|
void Copter::perf_info_check_loop_time(uint32_t time_in_micros)
|
2012-11-18 12:16:07 -04:00
|
|
|
{
|
|
|
|
perf_info_loop_count++;
|
2015-02-09 10:07:18 -04:00
|
|
|
|
|
|
|
// exit if this loop should be ignored
|
|
|
|
if (perf_ignore_loop) {
|
|
|
|
perf_ignore_loop = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-11-18 12:16:07 -04:00
|
|
|
if( time_in_micros > perf_info_max_time) {
|
|
|
|
perf_info_max_time = time_in_micros;
|
|
|
|
}
|
2015-02-15 19:02:53 -04:00
|
|
|
if( perf_info_min_time == 0 || time_in_micros < perf_info_min_time) {
|
|
|
|
perf_info_min_time = time_in_micros;
|
|
|
|
}
|
2012-11-18 12:16:07 -04:00
|
|
|
if( time_in_micros > PERF_INFO_OVERTIME_THRESHOLD_MICROS ) {
|
|
|
|
perf_info_long_running++;
|
|
|
|
}
|
2015-11-04 01:42:05 -04:00
|
|
|
perf_info_sigma_time += time_in_micros;
|
|
|
|
perf_info_sigmasquared_time += time_in_micros * time_in_micros;
|
2012-11-18 12:16:07 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// perf_info_get_long_running_percentage - get number of long running loops as a percentage of the total number of loops
|
2015-05-29 23:12:49 -03:00
|
|
|
uint16_t Copter::perf_info_get_num_loops()
|
2012-11-18 12:16:07 -04:00
|
|
|
{
|
|
|
|
return perf_info_loop_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
// perf_info_get_max_time - return maximum loop time (in microseconds)
|
2015-05-29 23:12:49 -03:00
|
|
|
uint32_t Copter::perf_info_get_max_time()
|
2012-11-18 12:16:07 -04:00
|
|
|
{
|
|
|
|
return perf_info_max_time;
|
|
|
|
}
|
|
|
|
|
2015-02-15 19:02:53 -04:00
|
|
|
// perf_info_get_max_time - return maximum loop time (in microseconds)
|
2015-05-29 23:12:49 -03:00
|
|
|
uint32_t Copter::perf_info_get_min_time()
|
2015-02-15 19:02:53 -04:00
|
|
|
{
|
|
|
|
return perf_info_min_time;
|
|
|
|
}
|
|
|
|
|
2012-11-18 12:16:07 -04:00
|
|
|
// perf_info_get_num_long_running - get number of long running loops
|
2015-05-29 23:12:49 -03:00
|
|
|
uint16_t Copter::perf_info_get_num_long_running()
|
2012-11-18 12:16:07 -04:00
|
|
|
{
|
|
|
|
return perf_info_long_running;
|
2014-03-08 02:16:28 -04:00
|
|
|
}
|
2016-04-21 03:42:25 -03:00
|
|
|
|
|
|
|
// perf_info_get_num_dropped - get number of dropped log messages
|
|
|
|
uint32_t Copter::perf_info_get_num_dropped()
|
|
|
|
{
|
|
|
|
return perf_info_log_dropped;
|
|
|
|
}
|
2015-11-04 01:42:05 -04:00
|
|
|
|
|
|
|
// perf_info_get_avg_time - return average loop time (in microseconds)
|
|
|
|
uint32_t Copter::perf_info_get_avg_time()
|
|
|
|
{
|
|
|
|
return (perf_info_sigma_time / perf_info_loop_count);
|
|
|
|
}
|
|
|
|
|
|
|
|
// perf_info_get_stddev_time - return stddev of average loop time (in us)
|
|
|
|
uint32_t Copter::perf_info_get_stddev_time()
|
|
|
|
{
|
|
|
|
return sqrt((perf_info_sigmasquared_time - (perf_info_sigma_time*perf_info_sigma_time)/perf_info_loop_count) / perf_info_loop_count);
|
|
|
|
}
|