Skip to content

bus_monitor: limit the number of rows visible in bus monitor window - #143

Open
joshanne wants to merge 1 commit into
dronecan:masterfrom
joshanne:pr/limit-rows-in-bus-monitor
Open

joshanne wants to merge 1 commit into
dronecan:masterfrom
joshanne:pr/limit-rows-in-bus-monitor

Conversation

@joshanne

Copy link
Copy Markdown
Collaborator

Summary

The bus monitor kept every frame it received, so on a busy bus its memory grew without bound. This caps the table at 200,000 rows, editable from the bus monitor toolbar.

 RealtimeLogWidget(..., max_rows=None)        # None: unlimited, as before
   _redraw
     move queued items into the table
+    _trim_rows: remove the oldest rows beyond max_rows, in one bulk removal
-  _queue: queue.Queue                        # unbounded while paused
+  _queue: collections.deque(maxlen=max_rows) # drops the oldest when full
+  SteppableSpinBox "max 200,000"             # next to the row count; lowering it trims immediately

 BusMonitorWindow
-  RealtimeLogWidget(...)
+  RealtimeLogWidget(..., max_rows=200000)
  • The queue becomes a collections.deque: with a maximum length it drops its oldest item when full, so frames queued while the display is paused are capped at the limit and the newest are kept. A queue.Queue(maxsize) would refuse new items and keep the oldest instead.
  • SteppableSpinBox steps to multiples of its step size, so the arrows go 1,000 → 10,000 → 20,000 rather than 1,000 → 11,000 → 21,000.
  • The log messages panel, the other user of RealtimeLogWidget, passes no limit and is unchanged.

Evidence

  • Before: two bus monitors left open on a live bus, measured with /proc/<pid>/smaps_rollup: 3.4 GiB after 74 minutes and 3.9 GiB after 22 minutes, still growing ~4.4 MiB/s.
    After: frames fed into a bus monitor with the limit set to 20,000 (offscreen, on this branch):

    fed   5000 rows=  5000 rss= 159 MB
    fed  10000 rows= 10000 rss= 187 MB
    fed  15000 rows= 15000 rss= 216 MB
    fed  20000 rows= 20000 rss= 243 MB
    fed  25000 rows= 20000 rss= 270 MB
    fed  30000 rows= 20000 rss= 273 MB
    fed  35000 rows= 20000 rss= 273 MB
    fed  40000 rows= 20000 rss= 273 MB
    newest row kept: True
    after lowering to 5000: 5000
    paused, queued: 5000 (limit 5000)
    
  • Spin box stepping:

    up from 1000:    [1000, 10000, 20000, 30000]
    down from 30000: [30000, 20000, 10000, 1000, 1000]
    up from 15000:   [15000, 20000, 30000]
    typed 1500 kept: 1500
    

Merge Danger

Door: two-way

Revert the commit to restore unlimited rows.

Blast Radius: bus-monitor

Only the bus monitor gets a limit. Frames older than the newest 200,000 rows are no longer shown, and are lost from the table if the display is paused for longer than that; anyone relying on scrolling back further can raise the limit in the toolbar.

🤖 Generated with Claude Code

The bus monitor kept every frame it received, so its memory grew without
bound on a busy bus, to several gigabytes after an hour.

RealtimeLogWidget takes an optional row limit: once the table grows
beyond it, the oldest rows are removed in one bulk operation per redraw.
The limit is shown next to the row count and can be edited there; a lower
limit applies immediately. Its arrows step through multiples of 10000,
down to the minimum of 1000.

The queue of items waiting to be shown is now a collections.deque instead
of a queue.Queue. A deque with a maximum length drops its oldest item when
a new one is added to it while full, so items queued while the display is
paused are capped at the row limit, keeping the newest ones, which are the
ones that would remain in the table anyway. A queue.Queue with a maximum
size refuses new items instead, which would keep the oldest ones. Items
are added and taken on the Qt main thread, and append() and popleft() are
atomic in CPython regardless, so the locking of queue.Queue is not needed.

The bus monitor uses a limit of 200000 rows. Other users of the widget
are unaffected.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@joshanne

joshanne commented Oct 23, 2026 •

Copy link
Copy Markdown
Collaborator Author

i'm adding this because if the monitor window is left open and running for a long enough amount of time, it becomes a system resource hog and ends up causing grief. This doesnt resolve the issue completely however, and there is a follow up PR. See: #146

There's an issue that was previously raised for it here: #35

A follow up PR adds ability to log traffic to a pcapng file, where it can be opened and decoded in a tool like wireshark. See: #144

@joshanne joshanne changed the title bus_monitor: limit the number of rows, 200000 by default bus_monitor: limit the number of rows visible in bus monitor window Oct 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant