scripts: Reworked dbgbmap.py

This is a rework of dbgbmap.py to match dbgbmapd3.py, adopt the new
Rbyd/Lfs class abstractions, as well as Canvas, -k/--keep-open, etc.

Some of the main changes:

- dbgbmap.py now reports corrupt/conflict blocks, which can be useful
  for debugging.

  Note though that you will probably get false positives if running with
  -k/--keep-open while something is writing to the disk. littlefs is
  powerloss safe, not multi-write safe! Very different problem!

- dbgbmap.py now groups by blocks before mapping to the space filling
  curve. This matches dbgbmapd3.py and I think is more intuitive now
  that we have a bmap tiling algorithm.

  -%/--usage still works, but is rendered as a second space filling
  curve _inside_ the block tile. Different blocks can end up with
  slightly different sizes due to rounding, but it's not the end of the
  world.

  I wasn't originally going to keep it around, but ended up caving, so
  you can still get the original byte-level curve via -u/--contiguous.

- Like the other ascii rendering script, dbgbmap.py now supports
  -k/--keep-open and friends as a thin main wrapper. This just makes it
  a bit easier to watch a realtime bmap without needing to use watch.py.

- --mtree-only is supported, but filtering via --mdirs/--btrees/--data
  is _not_ supported. This was too much complexity for a minor feature,
  and doesn't cover other niche blocks like corrupted/conflict or parity
  in the future.

- Things are more customizable thanks to the Attr class. For an example
  you can now use the littlefs mount string as the title via
  --title-littlefs.

- Support for --to-scale and -t/--tiny mode, if you want to scale based
  on block_size.

One of the bigger differences dbgbmapd3.py -> dbgbmap.py is that
dbgbmap.py still supports -%/--usage. Should we backport -%/--usage to
dbgbmapd3.py? Uhhhh...

This ends up a funny example of raster graphics vs vector graphics. A
pixel-level space filling curve is easy with raster graphics, but with
an svg you'd need some sort of pixel -> path wrapping algorithm...

So no -%/--usage in dbgbmapd3.py for now.

Also just ripped out all of the -@/--blocks byte-level range stuff. Way
too complicated for what it was worth. -@/--blocks is limited to simple
block ranges now. High-level scripts should stick to high-level options.

One last thing to note is the adoption of "if '%' in label__" checks
before applying punescape. I wasn't sure if we should support punescape
in dbgbmap.py, since it's quite a bit less useful here, and may be
costly due to the lazy attr generation. Adding this simple check avoids
the cost and consistency question, so I adopted it in all scripts.
This commit is contained in:
Christopher Haster
2025-04-07 01:47:27 -05:00
parent 202636cccd
commit 33120bf930
11 changed files with 4956 additions and 1353 deletions

View File

@@ -1080,7 +1080,11 @@ def main_(f, paths, *,
# before tile generation, we want code and stack tiles to have the
# same color if they're in the same subsystem
for i, (k, s) in enumerate(subsystems.items()):
s['color'] = punescape(colors_[i, k], s['attrs'] | s)
color__ = colors_[i, k]
# don't punescape unless we have to
if '%' in color__:
color__ = punescape(color__, s['attrs'] | s)
s['color'] = color__
# build code heirarchy
@@ -1097,9 +1101,11 @@ def main_(f, paths, *,
for i, t in enumerate(code.leaves()):
t.color = subsystems[t.attrs['subsystem']]['color']
if (i, t.attrs['name']) in chars_:
t.char = punescape(
chars_[i, t.attrs['name']],
t.attrs['attrs'] | t.attrs)[0] # limit to 1 char
char__ = chars_[i, t.attrs['name']]
# don't punescape unless we have to
if '%' in char__:
char__ = punescape(char__, t.attrs['attrs'] | t.attrs)
t.char = char__[0] # limit to 1 char
elif len(t.attrs['subsystem']) < len(t.attrs['name']):
t.char = (t.attrs['name'][len(t.attrs['subsystem']):].lstrip('_')
or '')[0]
@@ -1107,9 +1113,11 @@ def main_(f, paths, *,
t.char = (t.attrs['subsystem'].rstrip('_').rsplit('_', 1)[-1]
or '')[0]
if (i, t.attrs['name']) in labels_:
t.label = punescape(
labels_[i, t.attrs['name']],
t.attrs['attrs'] | t.attrs)
label__ = labels_[i, t.attrs['name']]
# don't punescape unless we have to
if '%' in label__:
label__ = punescape(label__, t.attrs['attrs'] | t.attrs)
t.label = label__
else:
t.label = t.attrs['name']