EdgePi-Cloud / edgepi-python-sdk

Python SDK to control EdgePi, an industrial PC/PLC/IoT device powered by Raspberry Pi CM4
MIT License
5 stars 3 forks source link

Improve performance of DIN reads #423

Closed EarthenSky closed 1 month ago

EarthenSky commented 1 month ago

All 8 digital inputs can be read in less than 1ms on average (1000hz)

Changes

TODOs

github-actions[bot] commented 1 month ago

Code Coverage

Package Line Rate Branch Rate Health
adc 92% 89%
calibration 100% 100%
dac 100% 97%
digital_input 100% 100%
digital_output 98% 95%
eeprom 83% 63%
eeprom.protobuf_assets.eeprom_data_classes 97% 52%
eeprom.protobuf_assets.generated_pb2 77% 50%
gpio 98% 94%
led 0% 0%
peripherals 75% 28%
pwm 96% 95%
reg_helper 97% 85%
relay 100% 100%
tc 98% 98%
utilities 100% 100%
Summary 92% (3132 / 3398) 81% (660 / 814)
github-actions[bot] commented 1 month ago

Code Coverage

Package Line Rate Branch Rate Health
adc 91% 88%
calibration 100% 100%
dac 100% 97%
digital_input 100% 100%
digital_output 98% 95%
eeprom 83% 63%
eeprom.protobuf_assets.eeprom_data_classes 97% 52%
eeprom.protobuf_assets.generated_pb2 77% 50%
gpio 98% 94%
led 0% 0%
peripherals 75% 28%
pwm 96% 95%
reg_helper 97% 85%
relay 100% 100%
tc 98% 98%
utilities 100% 100%
Summary 92% (3131 / 3398) 81% (659 / 814)
github-actions[bot] commented 1 month ago

Code Coverage

Package Line Rate Branch Rate Health
adc 91% 88%
calibration 100% 100%
dac 100% 97%
digital_input 100% 100%
digital_output 98% 95%
eeprom 83% 63%
eeprom.protobuf_assets.eeprom_data_classes 97% 52%
eeprom.protobuf_assets.generated_pb2 77% 50%
gpio 98% 94%
led 0% 0%
peripherals 75% 28%
pwm 96% 95%
reg_helper 97% 85%
relay 100% 100%
tc 98% 98%
utilities 100% 100%
Summary 92% (3131 / 3398) 81% (659 / 814)
github-actions[bot] commented 1 month ago

Code Coverage

Package Line Rate Branch Rate Health
adc 91% 88%
calibration 100% 100%
dac 100% 97%
digital_input 100% 100%
digital_output 98% 95%
eeprom 83% 63%
eeprom.protobuf_assets.eeprom_data_classes 97% 52%
eeprom.protobuf_assets.generated_pb2 77% 50%
gpio 98% 94%
led 0% 0%
peripherals 75% 28%
pwm 96% 95%
reg_helper 97% 85%
relay 100% 100%
tc 98% 98%
utilities 100% 100%
Summary 92% (3129 / 3396) 81% (657 / 812)
github-actions[bot] commented 1 month ago

Code Coverage

Package Line Rate Branch Rate Health
adc 91% 88%
calibration 100% 100%
dac 100% 97%
digital_input 100% 100%
digital_output 98% 95%
eeprom 83% 63%
eeprom.protobuf_assets.eeprom_data_classes 97% 52%
eeprom.protobuf_assets.generated_pb2 77% 50%
gpio 98% 94%
led 0% 0%
peripherals 75% 28%
pwm 96% 95%
reg_helper 97% 85%
relay 100% 100%
tc 98% 98%
utilities 100% 100%
Summary 92% (3129 / 3396) 81% (657 / 812)
github-actions[bot] commented 1 month ago

Code Coverage

Package Line Rate Branch Rate Health
adc 91% 88%
calibration 100% 100%
dac 100% 97%
digital_input 100% 100%
digital_output 98% 95%
eeprom 83% 63%
eeprom.protobuf_assets.eeprom_data_classes 97% 52%
eeprom.protobuf_assets.generated_pb2 77% 50%
gpio 98% 94%
led 0% 0%
peripherals 75% 28%
pwm 96% 95%
reg_helper 97% 85%
relay 100% 100%
tc 98% 98%
utilities 100% 100%
Summary 92% (3129 / 3396) 81% (657 / 812)
EarthenSky commented 1 month ago

test if representing DIN pins as int instead of string constants has a big impact in performance (I suspect not)

A trace shows that using strings is actually negligibly faster!? Wild results, but I suppose the casting string to int takes longer than hashing the string into the table (probably optimized into an address lookup or smt, though python has surprised me)

Here's a wall time trace of the new digital_input_state call breakdown (0.13ms per call) Screenshot 2024-08-13 111629

EarthenSky commented 1 month ago

And for completion's sake, here's a trace of digital_input_state_batch (reading 8 pins, takes 0.6ms)

Screenshot 2024-08-13 112146

Notice that posix.open & posix.close are only called once, yet elapse roughly the same time as opening the pin & reading it.

github-actions[bot] commented 1 month ago

Code Coverage

Package Line Rate Branch Rate Health
adc 91% 88%
calibration 100% 100%
dac 100% 97%
digital_input 100% 91%
digital_output 98% 95%
eeprom 83% 63%
eeprom.protobuf_assets.eeprom_data_classes 97% 52%
eeprom.protobuf_assets.generated_pb2 77% 50%
gpio 98% 94%
led 0% 0%
peripherals 75% 28%
pwm 96% 95%
reg_helper 97% 85%
relay 100% 100%
tc 98% 98%
utilities 100% 100%
Summary 92% (3125 / 3391) 81% (655 / 811)
github-actions[bot] commented 1 month ago

Code Coverage

Package Line Rate Branch Rate Health
adc 91% 88%
calibration 100% 100%
dac 100% 97%
digital_input 100% 91%
digital_output 98% 95%
eeprom 83% 63%
eeprom.protobuf_assets.eeprom_data_classes 97% 52%
eeprom.protobuf_assets.generated_pb2 77% 50%
gpio 98% 94%
led 0% 0%
peripherals 75% 28%
pwm 96% 95%
reg_helper 97% 85%
relay 100% 100%
tc 98% 98%
utilities 100% 100%
Summary 92% (3125 / 3391) 81% (655 / 811)
github-actions[bot] commented 1 month ago

Code Coverage

Package Line Rate Branch Rate Health
adc 91% 88%
calibration 100% 100%
dac 100% 97%
digital_input 100% 91%
digital_output 98% 95%
eeprom 83% 63%
eeprom.protobuf_assets.eeprom_data_classes 97% 52%
eeprom.protobuf_assets.generated_pb2 77% 50%
gpio 98% 94%
led 0% 0%
peripherals 75% 28%
pwm 96% 95%
reg_helper 97% 85%
relay 100% 100%
tc 98% 98%
utilities 100% 100%
Summary 92% (3125 / 3391) 81% (655 / 811)
farzadpanahi commented 1 month ago

@EarthenSky please add Performance section to readme and add a table like to show relevant numbers like: DIN | 1000 Hz | <public-func-name-here> | <link-to-example-file>

also add a examples dir if it doesn't exists and add example files there

github-actions[bot] commented 1 month ago

Code Coverage

Package Line Rate Branch Rate Health
adc 91% 88%
calibration 100% 100%
dac 100% 97%
digital_input 100% 91%
digital_output 98% 95%
eeprom 83% 63%
eeprom.protobuf_assets.eeprom_data_classes 97% 52%
eeprom.protobuf_assets.generated_pb2 77% 50%
gpio 98% 94%
led 0% 0%
peripherals 75% 28%
pwm 96% 95%
reg_helper 97% 85%
relay 100% 100%
tc 98% 98%
utilities 100% 100%
Summary 92% (3125 / 3391) 81% (655 / 811)
github-actions[bot] commented 1 month ago

Code Coverage

Package Line Rate Branch Rate Health
adc 91% 88%
calibration 100% 100%
dac 100% 97%
digital_input 100% 91%
digital_output 98% 95%
eeprom 83% 63%
eeprom.protobuf_assets.eeprom_data_classes 97% 52%
eeprom.protobuf_assets.generated_pb2 77% 50%
gpio 98% 94%
led 0% 0%
peripherals 75% 28%
pwm 96% 95%
reg_helper 97% 85%
relay 100% 100%
tc 98% 98%
utilities 100% 100%
Summary 92% (3125 / 3391) 81% (655 / 811)
github-actions[bot] commented 1 month ago

Code Coverage

Package Line Rate Branch Rate Health
adc 91% 88%
calibration 100% 100%
dac 100% 97%
digital_input 100% 91%
digital_output 98% 95%
eeprom 83% 63%
eeprom.protobuf_assets.eeprom_data_classes 97% 52%
eeprom.protobuf_assets.generated_pb2 77% 50%
gpio 98% 94%
led 0% 0%
peripherals 75% 28%
pwm 96% 95%
reg_helper 97% 85%
relay 100% 100%
tc 98% 98%
utilities 100% 100%
Summary 92% (3125 / 3391) 81% (655 / 811)
github-actions[bot] commented 1 month ago

Code Coverage

Package Line Rate Branch Rate Health
adc 91% 88%
calibration 100% 100%
dac 100% 97%
digital_input 100% 91%
digital_output 98% 95%
eeprom 83% 63%
eeprom.protobuf_assets.eeprom_data_classes 97% 52%
eeprom.protobuf_assets.generated_pb2 77% 50%
gpio 98% 94%
led 0% 0%
peripherals 75% 28%
pwm 96% 95%
reg_helper 97% 85%
relay 100% 100%
tc 98% 98%
utilities 100% 100%
Summary 92% (3125 / 3391) 81% (655 / 811)
github-actions[bot] commented 1 month ago

Code Coverage

Package Line Rate Branch Rate Health
adc 91% 88%
calibration 100% 100%
dac 100% 97%
digital_input 100% 91%
digital_output 98% 95%
eeprom 83% 63%
eeprom.protobuf_assets.eeprom_data_classes 97% 52%
eeprom.protobuf_assets.generated_pb2 77% 50%
gpio 98% 94%
led 0% 0%
peripherals 75% 28%
pwm 96% 95%
reg_helper 97% 85%
relay 100% 100%
tc 98% 98%
utilities 100% 100%
Summary 92% (3125 / 3391) 81% (655 / 811)