Skip to content
This repository has been archived by the owner on Jan 8, 2025. It is now read-only.

plotters_combined with PMS5003 blows up after a few minutes with MemoryError in update - replace with fixed size, circular buffer #19

Closed
kevinjwalters opened this issue Dec 22, 2020 · 5 comments

Comments

@kevinjwalters
Copy link

kevinjwalters commented Dec 22, 2020

The example https://github.com/pimoroni/EnviroPlus-FeatherWing/blob/master/examples/plotters_combined.py is robust wrt memory usage until the PMS5003 is added on a Feather nRF52840 Express. With that additional sensor and associated graph it then blows up after about 15 minutes with a MemoryError:

checksum error
checksum error
Traceback (most recent call last):
  File "code.py", line 209, in <module>
  File "lib/pimoroni_envirowing/screen/plotter.py", line 103, in update
MemoryError: memory allocation failed, allocating 1288 bytes

Press any key to enter the REPL. Use CTRL-D to reload.

Assuming this isn't a leak there's probably some efficiency measure that can improve the situation here. Pre-allocation of self.data_points and storing number of valid entries would probably help. This is the approach taken here with an implementation of a circular buffer for the width of screen plus pending extra_data awaiting being drawn via draw() (plus 1 based on how the implementation works).

A crude fix might be to allow the width of plot to be specified and simply reduce it from the default 160.

@kevinjwalters kevinjwalters changed the title plotters_combined blows up after a few minutes with MemoryError in update plotters_combined with PMS5003 blows up after a few minutes with MemoryError in update Dec 22, 2020
@kevinjwalters
Copy link
Author

Test this with interval 0.2 and passive mode to get the plot zipping along.

@kevinjwalters
Copy link
Author

kevinjwalters commented Jan 6, 2021

  • add one more test with alternating pixel positions and slow it down as it scrolls for visual inspection.

@kevinjwalters
Copy link
Author

kevinjwalters commented Jan 6, 2021

  • plotters_combined uses the feature of supplying less values than are declared by colour list

@kevinjwalters
Copy link
Author

After auto_discard addition, Feather nRF52840 Express on 6.0.0:

Four lines, 3 ramping took 20.0684 seconds
Four lines, 3 ramping took 15.576 seconds
Three flat lines took 16.8184 seconds
Three flat lines took 15.1393 seconds
Two lines, few draws took 13.2486 seconds
Two lines, few draws took 12.5482 seconds
Alternating, missing took 13.6402 seconds
Alternating, missing took 11.7799 seconds

kevinjwalters pushed a commit to kevinjwalters/EnviroPlus-FeatherWing that referenced this issue Jan 6, 2021
Default is now based on the pixel dimensions of the screen but can be specified with width, height kwargs.
kevinjwalters pushed a commit to kevinjwalters/EnviroPlus-FeatherWing that referenced this issue Jan 6, 2021
…ffer pimoroni#19.

A single list is now preallocated at a fixed size and not replaced with slices to reduce continual allocations and fragmentation.
Includes fix for calling update() several times before draw().
The full_refresh implementation now only clears the bitmap when it scrolls.
Removed the commented-out code.
kevinjwalters pushed a commit to kevinjwalters/EnviroPlus-FeatherWing that referenced this issue Jan 6, 2021
pimoroni#19.

Adding new test with some patterns and variable number of values to look for bugs around scrolling.
kevinjwalters pushed a commit to kevinjwalters/EnviroPlus-FeatherWing that referenced this issue Jan 6, 2021
…exceeded. pimoroni#19

Discarding data which cannot be stored by update() if internal buffer capacity is exceeded, exceptions can be thrown if auto_discard is set to False.
plotters_combined relies upon data being discarded by update(whatever, draw=False) for plots not on screen.
Updating plotters_test to perform 32 undrawn update() in test_twolinesfewdraws.
@kevinjwalters
Copy link
Author

plotters_combined (00e1590) now runs better on the Feather nRF52840 Express with PMS5003 attached. Goes from 53648 bytes free at end of updates to steady state of around 31088 bytes.

kevinjwalters pushed a commit to kevinjwalters/EnviroPlus-FeatherWing that referenced this issue Jan 6, 2021
@kevinjwalters kevinjwalters changed the title plotters_combined with PMS5003 blows up after a few minutes with MemoryError in update plotters_combined with PMS5003 blows up after a few minutes with MemoryError in update - replace with fixed size, circular buffer Jan 7, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants