-
Couldn't load subscription status.
- Fork 381
Description
Hiya.
I've been playing with an FT232H and ili3941 display as per this guide: https://learn.adafruit.com/tft-sidekick-with-ft232h/overview
I'm finding on my Ubuntu 18.04 LTS server writing an Image to the display is resulting is high CPU. My server is an Atom J4105, it's a pretty nice low power x86 server (https://ark.intel.com/content/www/us/en/ark/products/128989/intel-celeron-j4105-processor-4m-cache-up-to-2-50-ghz.html)
import board
import digitalio
import adafruit_rgb_display.ili9341 as ili9341
from PIL import Image, ImageDraw
import time
cs_pin = digitalio.DigitalInOut(board.C0)
dc_pin = digitalio.DigitalInOut(board.C1)
disp = ili9341.ILI9341(board.SPI(), cs=cs_pin, dc=dc_pin, baudrate=64000000, width=240, height=320)
image = Image.new('RGB', (disp.width, disp.height))
draw = ImageDraw.Draw(image)
while True:
disp.image(image, 0)
time.sleep(1)
All it does is draw the same image to the display every 1 second. it doesn't recreate the image or anything, just display it.
When I watch htop the python ./test.py is just running with 25% cpu consistently.
So I ran profile with the above program, only with 1 iteration (draw the image once), here's the top results:
ncalls tottime percall cumtime percall filename:lineno(function)
149/1 0.024 0.000 3.230 3.230 {built-in method builtins.exec}
1 0.000 0.000 3.230 3.230 stats.py:1(<module>)
206 0.004 0.000 1.457 0.007 usbtools.py:54(find_all)
24 0.000 0.000 1.446 0.060 rgb.py:261(write)
204 0.002 0.000 1.426 0.007 chip.py:29(id)
46 0.000 0.000 1.273 0.028 spi_device.py:79(__enter__)
46 0.001 0.000 1.235 0.027 busio.py:102(configure)
1 0.000 0.000 1.181 1.181 ili9341.py:92(__init__)
1 0.000 0.000 1.181 1.181 rgb.py:237(__init__)
1 0.000 0.000 1.178 1.178 rgb.py:120(__init__)
1 0.000 0.000 1.178 1.178 rgb.py:128(init)
216 0.002 0.000 1.004 0.005 usbtools.py:203(_find_devices)
1 1.001 1.001 1.001 1.001 {built-in method time.sleep}
146 0.001 0.000 0.969 0.007 board.py:291(id)
There's 206 calls to usbtools.py and chip.py. I think that's the device setup, and there is an initial delay before image processing.
However when I add cProfile to just the disp.image() call, I timed 0.5 seconds to display the image! Here's the code:
import board
import digitalio
import adafruit_rgb_display.ili9341 as ili9341
from PIL import Image, ImageDraw
import time
import cProfile
cs_pin = digitalio.DigitalInOut(board.C0)
dc_pin = digitalio.DigitalInOut(board.C1)
disp = ili9341.ILI9341(board.SPI(), cs=cs_pin, dc=dc_pin, baudrate=64000000, width=240, height=320)
image = Image.new('RGB', (disp.width, disp.height))
draw = ImageDraw.Draw(image)
def do_cprofile(func):
def profiled_func(*args, **kwargs):
profile = cProfile.Profile()
try:
profile.enable()
result = func(*args, **kwargs)
profile.disable()
return result
finally:
profile.print_stats(sort='cumtime')
return profiled_func
@do_cprofile
def displayimage(disp, image):
disp.image(image, 0)
displayimage(disp, image)
And the results:
$ python3 test1.py
408521 function calls (407051 primitive calls) in 0.547 seconds
Ordered by: cumulative time
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.000 0.000 0.547 0.547 test1.py:30(displayimage)
1 0.102 0.102 0.547 0.547 rgb.py:167(image)
1 0.000 0.000 0.269 0.269 rgb.py:134(_block)
3 0.000 0.000 0.269 0.090 rgb.py:261(write)
6 0.000 0.000 0.167 0.028 spi_device.py:79(__enter__)
6 0.000 0.000 0.162 0.027 busio.py:102(configure)
24 0.000 0.000 0.162 0.007 chip.py:29(id)
24 0.001 0.000 0.161 0.007 usbtools.py:54(find_all)
76800 0.054 0.000 0.137 0.000 Image.py:1270(getpixel)
18 0.000 0.000 0.118 0.007 board.py:291(id)
24 0.000 0.000 0.109 0.005 usbtools.py:203(_find_devices)
24 0.000 0.000 0.103 0.004 libusb1.py:939(get_backend)
24 0.102 0.004 0.102 0.004 libusb1.py:703(__init__)
6 0.000 0.000 0.064 0.011 busio.py:169(write)
...
Notice that the call to basically disp.image() is take 0.54 seconds, and what looks like write operations is slow?
In all the FT232H and CircuitPython guides and samples, the performance is not discussed, and you include samples that sleep for 0.1 seconds between iterations.
Is this expected performance? The high CPU makes stat display not a good application for this hardware.
Thanks.