47 #include <px4_platform_common/px4_config.h> 48 #include <px4_platform_common/micro_hal.h> 60 #include <nuttx/irq.h> 61 static irqstate_t flags;
67 flags = px4_enter_critical_section();
74 px4_leave_critical_section(flags);
78 #define PERF(name, op, count) do { \ 81 perf_counter_t p = perf_alloc(PC_ELAPSED, name); \ 82 for (int i = 0; i < count; i++) { \ 90 perf_print_counter(p); \ 97 virtual bool run_tests();
101 bool time_px4_uorb();
102 bool time_px4_uorb_direct();
111 bool MicroBenchORB::run_tests()
116 return (_tests_failed == 0);
122 const T scale = rand() / (T) RAND_MAX;
123 return min + scale * (max -
min);
128 srand(time(
nullptr));
134 lpos.timestamp = rand();
135 lpos.dist_bottom_valid = rand();
137 gyro.timestamp = rand();
142 bool MicroBenchORB::time_px4_uorb()
149 bool updated =
false;
152 PERF(
"orb_check vehicle_status", ret =
orb_check(fd_status, &updated), 1000);
153 PERF(
"orb_stat vehicle_status", ret =
orb_stat(fd_status, &time), 1000);
158 PERF(
"orb_check vehicle_local_position", ret =
orb_check(fd_lpos, &updated), 1000);
159 PERF(
"orb_stat vehicle_local_position", ret =
orb_stat(fd_lpos, &time), 1000);
160 PERF(
"orb_copy vehicle_local_position", ret =
orb_copy(
ORB_ID(vehicle_local_position), fd_lpos, &lpos), 1000);
164 PERF(
"orb_check sensor_gyro", ret =
orb_check(fd_gyro, &updated), 1000);
165 PERF(
"orb_stat sensor_gyro", ret =
orb_stat(fd_gyro, &time), 1000);
166 PERF(
"orb_copy sensor_gyro", ret =
orb_copy(
ORB_ID(sensor_gyro), fd_gyro, &gyro), 1000);
183 bool MicroBenchORB::time_px4_uorb_direct()
186 bool updated =
false;
190 PERF(
"uORB::Subscription orb_check vehicle_status", ret = vstatus.updated(), 1000);
191 PERF(
"uORB::Subscription orb_copy vehicle_status", ret = vstatus.copy(&
status), 1000);
196 PERF(
"uORB::Subscription orb_check vehicle_local_position", ret = local_pos.updated(), 1000);
197 PERF(
"uORB::Subscription orb_copy vehicle_local_position", ret = local_pos.copy(&lpos), 1000);
202 PERF(
"uORB::Subscription orb_check sensor_gyro", ret = sens_gyro.updated(), 1000);
203 PERF(
"uORB::Subscription orb_copy sensor_gyro", ret = sens_gyro.copy(&gyro), 1000);
int orb_copy(const struct orb_metadata *meta, int handle, void *buffer)
static struct vehicle_status_s status
int reset(enum LPS22HB_BUS busid)
Reset the driver.
Base class to be used for unit tests.
#define PERF(name, op, count)
int orb_exists(const struct orb_metadata *meta, int instance)
High-resolution timer with callouts and timekeeping.
int orb_subscribe(const struct orb_metadata *meta)
#define ORB_ID(_name)
Generates a pointer to the uORB metadata structure for a given topic.
int orb_stat(int handle, uint64_t *time)
ut_declare_test_c(test_microbench_uorb, MicroBenchORB) bool MicroBenchORB
int orb_unsubscribe(int handle)
constexpr _Tp min(_Tp a, _Tp b)
constexpr _Tp max(_Tp a, _Tp b)
int orb_check(int handle, bool *updated)
int test_microbench_uorb(int argc, char *argv[])
#define ut_run_test(test)
Runs a single unit test.
vehicle_local_position_s lpos
Performance measuring tools.