Skip to content

Drawing: log pen mode waits, full redraws and memory per Kindle - #346

Merged
9retirement6irk merged 2 commits into
mainfrom
feat/drawing-diagnostics
Nov 23, 2026
Merged

9retirement6irk merged 2 commits into
mainfrom
feat/drawing-diagnostics

Conversation

@9retirement6irk

Copy link
Copy Markdown
Owner

Diagnostics only: before the bigger drawing changes, this adds log lines that show what really happens on the drawing screen on a real Kindle Scribe, Colorsoft and K3. No behaviour change: only numbers are written (never what's drawn or written), and only while diagnostic logging is on.

What changes

All lines go through gzreader_log (Log.info), as the existing drawing: pen mode: … line does.

1. Pen mode waits (gzreader_penmode.lua, Scribe with Fast ink)

  • PenMode.enter (wait for the last ordinary update before ink) and PenMode.leave (sleep up to QUIET after ink) now also keep, for each kind: the count, the longest and a histogram (<50, 50–150, 150–300, ≥300 ms). For waits before ink they also keep how long before it the ordinary update was sent (average, min–max) and how long before it the last pause clean-up (DrawScreen:settle) ran (average). The old totals (waited_before, waited_after) don't change.
  • Waits of 200 ms or more are written as they happen, at most 20 per drawing session (the 20th says so):
    • drawing: pen mode: waited 250 ms before ink for an ordinary update (sent 100 ms before; the last pause clean-up 130 ms before) (or … clean-up not yet))
    • drawing: pen mode: waited 250 ms after ink before an ordinary update
    • The 20th line ends with (no more of these lines this time).
  • At close, one more line, just before the existing drawing: pen mode: on … line (a separate statement, so Pen mode: a pause's update waits until the pen is away #336's line after it isn't touched):
    • drawing: pen mode waits: before ink 28, longest 400 ms (ms: <50 1, 50-150 0, 150-300 26, >=300 1), the ordinary update sent 104 ms before on average (100-200), the last pause clean-up 900 ms before on average; after ink 1, longest 250 ms (ms: <50 0, 50-150 0, 150-300 1, >=300 0); 28 of 200 ms or more
  • DrawScreen:settle marks the time (PenMode.settled()) as its first line. Nothing else in settle or in DrawScreen:apply changes.
  • The waits were already counted before this PR. Only the long-wait line checks whether logging is on, and that check runs only after a wait of 200 ms or more. The extra work for each wait is a few additions.

2. Full redraws (DrawScreen:repaintCanvas)

  • Each redraw is timed with ui/time, and only while logging is on. The first 5 per session are written:
    • drawing: full redraw 1: 40 ms, 3 strokes, rotation 0 (upright), canvas BB8 1860x2480, zoom 2.00x (zoom only when zoomed; the 5th ends with (the rest only counted))
  • At close (after the pen mode lines, before the pen pressure line):
    • drawing: full redraws: 7, 280 ms in all, longest 40 ms; pages shown 3; Lua memory at most 23456 KB
  • When the screen opens:
    • drawing: opened, 3 pages, rotation 0 (upright), canvas BBRGB32 1860x2480, pen mode (or no pen mode)
  • Rotation comes from Screen:getRotationMode(). The canvas type is bb:getType(), named by matching Blitbuffer.TYPE_*. Both are wrapped in pcall, so a value nobody can read shows as ? and nothing breaks.

3. Lua memory on each page shown (DrawScreen:showPage)

  • drawing: page 2 of 3 shown, Lua memory 23456 KB, with (opening) for the first page. At most 50 lines per session (the 50th says so). The highest value goes in the close line above.
  • This only reads collectgarbage("count"). Nothing is collected.

Files: gzreader_penmode.lua, gzreader_drawscreen.lua, gzreader_changelog.lua ("next"), tools/gzreader/tests/penmode_test.lua, tools/gzreader/tests/run_tests.lua. A trial merge with #336 (git merge-tree) clashes only in the changelog, which the beta combine settles.

Tests

I haven't run the tests locally (no luajit here). CI is the check.

  • penmode_test.lua, a new block after the existing pen mode tests. It uses a fixed fake clock and stands in for wait, sleep, send and report. It checks:
    • the before/after counts, the longest and the histogram (28 waits before ink: 1 / 0 / 26 / 1; 1 wait after ink in 150–300);
    • how long before each wait the ordinary update was sent (min 100, max 200 ms) and the pause clean-up count;
    • the per-wait lines: their exact text, capped at LONG_MAX (20), the last one marked;
    • the summary line, also when there were no waits;
    • that the default report writes nothing while Log.enabled is false.
  • run_tests.lua, a new block right after "a long stroke keeps up with the pen" (away from Pen mode: a pause's update waits until the pen is away #336's lines). It uses a fake screen object and a fixed DrawScreen.clock, and checks:
    • repaintCanvas is timed and counted, and only the first 5 are written; the line has the strokes, rotation , canvas BBRGB32 1860x2480 and zoom 2.00x;
    • showPage writes the memory line ( (opening) for the first page), capped at 50;
    • the close summary line;
    • screenInfo gives ? when the screen has no getRotationMode, the canvas has no getType, either one throws an error, or either is nil;
    • nothing is timed or written with logging off;
    • source checks: no collectgarbage("collect"), and the unhook and settle lines are there.

On a device

Install the test build (Settings → Updates → Test builds). Keep diagnostic logging on (the default).

Kindle Scribe (and the Colorsoft)

  1. Open a new drawing on ruled paper. In the pen's panel, check Fast ink is on.
  2. Write two or three lines of ordinary words, at your normal speed.
  3. Erase one word with the eraser.
  4. Pinch to zoom in, write a word, then pinch back out.
  5. Add pages if needed, then switch pages 3 times (forward, back, forward).
  6. Close the drawing (Done or Close).
  7. Send the log: Settings → Privacy and diagnostics → Send to the developer (or Save to the Kindle and send GZreader/app/gzreader.log).

Kindle 3 (or another Kindle without a pen): open a drawing, draw a few strokes, erase one, switch pages 3 times, close, and send the log the same way. There won't be any pen mode lines there; the redraw and memory lines are what's wanted.

Lines to send back (or the whole log):

grep -E "drawing: (opened|full redraw|page [0-9]+ of|pen mode|closed)" gzreader.log

That covers:

  • drawing: opened, …
  • drawing: full redraw N: …
  • drawing: full redraws: …
  • drawing: page N of M shown, Lua memory … KB
  • drawing: pen mode: waited … (Scribe only)
  • drawing: pen mode waits: … (Scribe only)
  • the existing drawing: pen mode: on … and drawing: closed; …

Please also say which Kindle it was and roughly how the ink felt (late first stroke, chunks).

Diagnostics only, no behaviour change, so the drawing screen can be tuned on the Kindle Scribe, Colorsoft and K3 from real logs:
- pen mode (gzreader_penmode): each wait before ink (for the last ordinary update) and after it (QUIET) counted with its longest and a histogram (<50, 50-150, 150-300, >=300 ms); waits before ink with how long before the ordinary update and the last pause clean-up (settle) were sent; waits of 200 ms or more written as they happen, at most 20 per drawing session; one summary line at close (before the existing pen mode line).
- full redraws (repaintCanvas): timed; the first 5 written with strokes, rotation, canvas type and size, zoom; count/total/longest at close.
- each page shown: collectgarbage("count") (only read), at most 50 lines; the highest at close.
- opening: rotation and canvas type once.
Nothing is measured or built while diagnostic logging is off.

Made with goose (AI agent).
@9retirement6irk 9retirement6irk added the beta Include in the beta branch (test builds over Wi-Fi) label Nov 21, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This pull request is labelled beta but couldn't be combined into the beta branch (with main and the other beta pull requests before it): these files clash:

  • plugins/gzreader.koplugin/gzreader_changelog.lua
  • tools/gzreader/tests/run_tests.lua

It stays out of the test builds until that is settled (rebase onto main, or onto the pull request it clashes with).

Beta left #346 out: its tests went in after the same block as #342's and #343's. Moved up (above the split view tests), unchanged.

Made with goose (AI agent).
github-actions Bot added a commit that referenced this pull request Nov 21, 2026
# Conflicts:
#	plugins/gzreader.koplugin/gzreader_changelog.lua
github-actions Bot added a commit that referenced this pull request Nov 21, 2026
# Conflicts:
#	plugins/gzreader.koplugin/gzreader_changelog.lua
github-actions Bot added a commit that referenced this pull request Nov 22, 2026
# Conflicts:
#	plugins/gzreader.koplugin/gzreader_changelog.lua
github-actions Bot added a commit that referenced this pull request Nov 22, 2026
# Conflicts:
#	plugins/gzreader.koplugin/gzreader_changelog.lua
github-actions Bot added a commit that referenced this pull request Nov 22, 2026
# Conflicts:
#	plugins/gzreader.koplugin/gzreader_changelog.lua
github-actions Bot added a commit that referenced this pull request Nov 22, 2026
# Conflicts:
#	plugins/gzreader.koplugin/gzreader_changelog.lua
github-actions Bot added a commit that referenced this pull request Nov 22, 2026
# Conflicts:
#	plugins/gzreader.koplugin/gzreader_changelog.lua
github-actions Bot added a commit that referenced this pull request Nov 22, 2026
# Conflicts:
#	plugins/gzreader.koplugin/gzreader_changelog.lua
github-actions Bot added a commit that referenced this pull request Nov 22, 2026
# Conflicts:
#	plugins/gzreader.koplugin/gzreader_changelog.lua
github-actions Bot added a commit that referenced this pull request Nov 22, 2026
# Conflicts:
#	plugins/gzreader.koplugin/gzreader_changelog.lua
github-actions Bot added a commit that referenced this pull request Nov 23, 2026
# Conflicts:
#	plugins/gzreader.koplugin/gzreader_changelog.lua
github-actions Bot added a commit that referenced this pull request Nov 23, 2026
# Conflicts:
#	plugins/gzreader.koplugin/gzreader_changelog.lua
github-actions Bot added a commit that referenced this pull request Nov 23, 2026
# Conflicts:
#	plugins/gzreader.koplugin/gzreader_changelog.lua
github-actions Bot added a commit that referenced this pull request Nov 23, 2026
# Conflicts:
#	plugins/gzreader.koplugin/gzreader_changelog.lua
github-actions Bot added a commit that referenced this pull request Nov 23, 2026
# Conflicts:
#	plugins/gzreader.koplugin/gzreader_changelog.lua
github-actions Bot added a commit that referenced this pull request Nov 23, 2026
# Conflicts:
#	plugins/gzreader.koplugin/gzreader_changelog.lua
@9retirement6irk
9retirement6irk merged commit 8771f85 into main Nov 23, 2026
2 checks passed
@9retirement6irk
9retirement6irk deleted the feat/drawing-diagnostics branch November 23, 2026 03:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

beta Include in the beta branch (test builds over Wi-Fi)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant