AP_Scheduler: scale perf_info with loop rate

this allows it to be used for a wide range of loop rates
This commit is contained in:
Andrew Tridgell 2018-01-31 19:03:42 +11:00
parent 875008f2a6
commit b3ed8fd3f9
2 changed files with 6 additions and 6 deletions

View File

@ -8,11 +8,8 @@
// we measure the main loop time
//
// 400hz loop update rate
#define OVERTIME_THRESHOLD_MICROS 3000
// reset - reset all records of loop time to zero
void AP::PerfInfo::reset()
void AP::PerfInfo::reset(uint16_t loop_rate_hz)
{
loop_count = 0;
max_time = 0;
@ -21,6 +18,8 @@ void AP::PerfInfo::reset()
log_dropped = DataFlash_Class::instance()->num_dropped();
sigma_time = 0;
sigmasquared_time = 0;
// 500us threshold for overtime
overtime_threshold_us = (1000000UL / loop_rate_hz) + 500;
}
// ignore_loop - ignore this loop from performance measurements (used to reduce false positive when arming)
@ -46,7 +45,7 @@ void AP::PerfInfo::check_loop_time(uint32_t time_in_micros)
if( min_time == 0 || time_in_micros < min_time) {
min_time = time_in_micros;
}
if( time_in_micros > OVERTIME_THRESHOLD_MICROS ) {
if (time_in_micros > overtime_threshold_us) {
long_running++;
}
sigma_time += time_in_micros;

View File

@ -10,7 +10,7 @@ public:
PerfInfo(const PerfInfo &other) = delete;
PerfInfo &operator=(const PerfInfo&) = delete;
void reset();
void reset(uint16_t loop_rate_hz);
void ignore_this_loop();
void check_loop_time(uint32_t time_in_micros);
uint16_t get_num_loops() const;
@ -29,6 +29,7 @@ private:
uint64_t sigmasquared_time;
uint16_t long_running;
uint32_t log_dropped;
uint32_t overtime_threshold_us;
bool ignore_loop;
};