mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-07-16 15:10:35 +08:00
uorb tests: improve & extend latency test output
- min/max - std dev - number of missed updates
This commit is contained in:
@@ -88,9 +88,12 @@ int uORBTest::UnitTest::pubsublatency_main()
|
||||
|
||||
const unsigned maxruns = 1000;
|
||||
unsigned timingsgroup = 0;
|
||||
int current_value = t.val;
|
||||
int num_missed = 0;
|
||||
|
||||
// timings has to be on the heap to keep frame size below 2048 bytes
|
||||
unsigned *timings = new unsigned[maxruns];
|
||||
unsigned timing_min = 9999999, timing_max = 0;
|
||||
|
||||
for (unsigned i = 0; i < maxruns; i++) {
|
||||
/* wait for up to 500ms for data */
|
||||
@@ -110,13 +113,24 @@ int uORBTest::UnitTest::pubsublatency_main()
|
||||
}
|
||||
|
||||
if (pret < 0) {
|
||||
warn("poll error %d, %d", pret, errno);
|
||||
PX4_ERR("poll error %d, %d", pret, errno);
|
||||
continue;
|
||||
}
|
||||
|
||||
hrt_abstime elt = hrt_elapsed_time(&t.time);
|
||||
num_missed += t.val - current_value - 1;
|
||||
current_value = t.val;
|
||||
|
||||
unsigned elt = (unsigned)hrt_elapsed_time(&t.time);
|
||||
latency_integral += elt;
|
||||
timings[i] = elt;
|
||||
|
||||
if (elt > timing_max) {
|
||||
timing_max = elt;
|
||||
}
|
||||
|
||||
if (elt < timing_min) {
|
||||
timing_min = elt;
|
||||
}
|
||||
}
|
||||
|
||||
orb_unsubscribe(test_multi_sub);
|
||||
@@ -129,7 +143,7 @@ int uORBTest::UnitTest::pubsublatency_main()
|
||||
FILE *f = fopen(fname, "w");
|
||||
|
||||
if (f == nullptr) {
|
||||
warnx("Error opening file!\n");
|
||||
PX4_ERR("Error opening file!");
|
||||
delete[] timings;
|
||||
return PX4_ERROR;
|
||||
}
|
||||
@@ -141,9 +155,22 @@ int uORBTest::UnitTest::pubsublatency_main()
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
|
||||
float std_dev = 0.f;
|
||||
float mean = latency_integral / maxruns;
|
||||
|
||||
for (unsigned i = 0; i < maxruns; i++) {
|
||||
float diff = (float)timings[i] - mean;
|
||||
std_dev += diff * diff;
|
||||
}
|
||||
|
||||
delete[] timings;
|
||||
|
||||
warnx("mean: %8.4f us", static_cast<double>(latency_integral / maxruns));
|
||||
PX4_INFO("mean: %8.4f us", static_cast<double>(mean));
|
||||
PX4_INFO("std dev: %8.4f us", static_cast<double>(sqrtf(std_dev / (maxruns - 1))));
|
||||
PX4_INFO("min: %3i us", timing_min);
|
||||
PX4_INFO("max: %3i us", timing_max);
|
||||
PX4_INFO("missed topic updates: %i", num_missed);
|
||||
|
||||
pubsubtest_passed = true;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user