diff --git a/libraries/AP_HAL_PX4/I2CDevice.cpp b/libraries/AP_HAL_PX4/I2CDevice.cpp index 0fd225641d..ace981241c 100644 --- a/libraries/AP_HAL_PX4/I2CDevice.cpp +++ b/libraries/AP_HAL_PX4/I2CDevice.cpp @@ -87,18 +87,26 @@ I2CDevice::I2CDevice(uint8_t bus, uint8_t address) : { set_device_bus(_px4dev.map_bus_number(bus)); set_device_address(address); + asprintf(&pname, "I2C:%u:%02x", + (unsigned)bus, (unsigned)address); + perf = perf_alloc(PC_ELAPSED, pname); } I2CDevice::~I2CDevice() { printf("I2C device bus %u address 0x%02x closed\n", (unsigned)_busnum, (unsigned)_address); + perf_free(perf); + free(pname); } bool I2CDevice::transfer(const uint8_t *send, uint32_t send_len, uint8_t *recv, uint32_t recv_len) { - return _px4dev.do_transfer(_address, send, send_len, recv, recv_len); + perf_begin(perf); + bool ret = _px4dev.do_transfer(_address, send, send_len, recv, recv_len); + perf_end(perf); + return ret; } bool I2CDevice::read_registers_multiple(uint8_t first_reg, uint8_t *recv, diff --git a/libraries/AP_HAL_PX4/I2CDevice.h b/libraries/AP_HAL_PX4/I2CDevice.h index 71f3cb23bf..fd3da9660f 100644 --- a/libraries/AP_HAL_PX4/I2CDevice.h +++ b/libraries/AP_HAL_PX4/I2CDevice.h @@ -72,6 +72,8 @@ private: uint8_t _busnum; PX4_I2C _px4dev; uint8_t _address; + perf_counter_t perf; + char *pname; }; class I2CDeviceManager : public AP_HAL::I2CDeviceManager {