mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-31 05:51:35 +08:00
Performance counters: Add option to set otherwise estimated time interval
This commit is contained in:
@@ -272,6 +272,46 @@ perf_end(perf_counter_t handle)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
perf_set(perf_counter_t handle, int64_t elapsed)
|
||||||
|
{
|
||||||
|
if (handle == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
switch (handle->type) {
|
||||||
|
case PC_ELAPSED: {
|
||||||
|
struct perf_ctr_elapsed *pce = (struct perf_ctr_elapsed *)handle;
|
||||||
|
|
||||||
|
if (elapsed < 0) {
|
||||||
|
pce->event_overruns++;
|
||||||
|
} else {
|
||||||
|
|
||||||
|
pce->event_count++;
|
||||||
|
pce->time_total += elapsed;
|
||||||
|
|
||||||
|
if ((pce->time_least > (uint64_t)elapsed) || (pce->time_least == 0))
|
||||||
|
pce->time_least = elapsed;
|
||||||
|
|
||||||
|
if (pce->time_most < (uint64_t)elapsed)
|
||||||
|
pce->time_most = elapsed;
|
||||||
|
|
||||||
|
// maintain mean and variance of the elapsed time in seconds
|
||||||
|
// Knuth/Welford recursive mean and variance of update intervals (via Wikipedia)
|
||||||
|
float dt = elapsed / 1e6f;
|
||||||
|
float delta_intvl = dt - pce->mean;
|
||||||
|
pce->mean += delta_intvl / pce->event_count;
|
||||||
|
pce->M2 += delta_intvl * (dt - pce->mean);
|
||||||
|
|
||||||
|
pce->time_start = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
perf_cancel(perf_counter_t handle)
|
perf_cancel(perf_counter_t handle)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -111,6 +111,18 @@ __EXPORT extern void perf_begin(perf_counter_t handle);
|
|||||||
*/
|
*/
|
||||||
__EXPORT extern void perf_end(perf_counter_t handle);
|
__EXPORT extern void perf_end(perf_counter_t handle);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register a measurement
|
||||||
|
*
|
||||||
|
* This call applies to counters that operate over ranges of time; PC_ELAPSED etc.
|
||||||
|
* If a call is made without a corresponding perf_begin call. It sets the
|
||||||
|
* value provided as argument as a new measurement.
|
||||||
|
*
|
||||||
|
* @param handle The handle returned from perf_alloc.
|
||||||
|
* @param elapsed The time elapsed. Negative values lead to incrementing the overrun counter.
|
||||||
|
*/
|
||||||
|
__EXPORT extern void perf_set(perf_counter_t handle, int64_t elapsed);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cancel a performance event.
|
* Cancel a performance event.
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user