From d55b4802f11403fa7042dfb6874072cf883a8a3a Mon Sep 17 00:00:00 2001 From: Julian Oes Date: Sun, 24 Apr 2016 19:51:58 +0200 Subject: [PATCH] df_mpu9250_wrapper: add perf counters --- .../df_mpu9250_wrapper/df_mpu9250_wrapper.cpp | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/platforms/posix/drivers/df_mpu9250_wrapper/df_mpu9250_wrapper.cpp b/src/platforms/posix/drivers/df_mpu9250_wrapper/df_mpu9250_wrapper.cpp index 72159661ab..828252727c 100644 --- a/src/platforms/posix/drivers/df_mpu9250_wrapper/df_mpu9250_wrapper.cpp +++ b/src/platforms/posix/drivers/df_mpu9250_wrapper/df_mpu9250_wrapper.cpp @@ -52,6 +52,7 @@ #include #include +#include #include #include @@ -132,6 +133,14 @@ private: unsigned _publish_count; hrt_abstime _first_sample_time; + + perf_counter_t _read_counter; + perf_counter_t _error_counter; + perf_counter_t _fifo_overflow_counter; + perf_counter_t _fifo_corruption_counter; + perf_counter_t _gyro_range_hit_counter; + perf_counter_t _accel_range_hit_counter; + perf_counter_t _publish_perf; }; DfMpu9250Wrapper::DfMpu9250Wrapper(/*enum Rotation rotation*/) : @@ -147,7 +156,14 @@ DfMpu9250Wrapper::DfMpu9250Wrapper(/*enum Rotation rotation*/) : _gyro_int(MPU9250_NEVER_AUTOPUBLISH_US, true), /*_rotation(rotation)*/ _publish_count(0), - _first_sample_time(0) + _first_sample_time(0), + _read_counter(perf_alloc(PC_COUNT, "mpu9250_reads")), + _error_counter(perf_alloc(PC_COUNT, "mpu9250_errors")), + _fifo_overflow_counter(perf_alloc(PC_COUNT, "mpu9250_fifo_overflows")), + _fifo_corruption_counter(perf_alloc(PC_COUNT, "mpu9250_fifo_corruptions")), + _gyro_range_hit_counter(perf_alloc(PC_COUNT, "mpu9250_gyro_range_hits")), + _accel_range_hit_counter(perf_alloc(PC_COUNT, "mpu9250_accel_range_hits")), + _publish_perf(perf_alloc(PC_ELAPSED, "mpu9250_publish")) { // Set sane default calibration values _accel_calibration.x_scale = 1.0f; @@ -437,6 +453,13 @@ int DfMpu9250Wrapper::_publish(struct imu_sensor_data &data) gyro_val_integrated_unused, gyro_report.integral_dt); + perf_set_count(_read_counter, data.read_counter); + perf_set_count(_error_counter, data.error_counter); + perf_set_count(_fifo_overflow_counter, data.fifo_overflow_counter); + perf_set_count(_fifo_corruption_counter, data.fifo_overflow_counter); + perf_set_count(_gyro_range_hit_counter, data.gyro_range_hit_counter); + perf_set_count(_accel_range_hit_counter, data.accel_range_hit_counter); + /* If the time offset is 0, we are receiving the latest sample and can publish, * at least every 4th time because the driver is running at 1kHz but we should * only publish at 250 Hz. */