scripts: Tweaked some flags in dbgmap.py/tracebd.py

Mostly to move away from unnecessary shortform flags. Using shortform
flags for what is roughly an unbounded enum just causes too many flag
conflicts as scripts grow:

- -r/--read -> --reads
- -p/--prog -> --progs
- -e/--erase -> --erases
- -w/--wear -> --wear

- -i/--in-use -> -%/--usage
- -M/--mdirs -> --mdirs
- -B/--btrees -> --btress
- -D/--datas -> --data/--datas

I may have had too much fun forcing argparse to make -%/--usage to work.
The percent sign caused a lot of problems for argparse internally.
This commit is contained in:
Christopher Haster
2025-03-14 14:04:55 -05:00
parent 9781055d8c
commit e18cecc3fb
2 changed files with 68 additions and 63 deletions
+19 -14
View File
@@ -1135,7 +1135,7 @@ def main(disk, mroots=None, *,
# mark mroots in our bmap # mark mroots in our bmap
for block in mroot.blocks: for block in mroot.blocks:
bmap.mdir(block, bmap.mdir(block,
mroot.eoff if args.get('in_use') else block_size) mroot.eoff if args.get('usage') else block_size)
mdirs_ += 1; mdirs_ += 1;
# find any file btrees in our mroot # find any file btrees in our mroot
@@ -1174,7 +1174,7 @@ def main(disk, mroots=None, *,
# mark mdir in our bmap # mark mdir in our bmap
for block in mdir.blocks: for block in mdir.blocks:
bmap.mdir(block, bmap.mdir(block,
mdir.eoff if args.get('in_use') mdir.eoff if args.get('usage')
else block_size) else block_size)
mdirs_ += 1 mdirs_ += 1
@@ -1222,7 +1222,7 @@ def main(disk, mroots=None, *,
d, (mid_, w_, rbyd_, rid_, tags_) = x d, (mid_, w_, rbyd_, rid_, tags_) = x
for block in rbyd_.blocks: for block in rbyd_.blocks:
bmap.btree(block, bmap.btree(block,
rbyd_.eoff if args.get('in_use') rbyd_.eoff if args.get('usage')
else block_size) else block_size)
btrees_ += 1 btrees_ += 1
ppath = path ppath = path
@@ -1255,7 +1255,7 @@ def main(disk, mroots=None, *,
# mark mdir in our bmap # mark mdir in our bmap
for block in mdir_.blocks: for block in mdir_.blocks:
bmap.mdir(block, 0, bmap.mdir(block, 0,
mdir_.eoff if args.get('in_use') mdir_.eoff if args.get('usage')
else block_size) else block_size)
mdirs_ += 1 mdirs_ += 1
@@ -1280,8 +1280,8 @@ def main(disk, mroots=None, *,
size, block, off = frombptr(data) size, block, off = frombptr(data)
# mark block in our bmap # mark block in our bmap
bmap.data(block, bmap.data(block,
off if args.get('in_use') else 0, off if args.get('usage') else 0,
size if args.get('in_use') else block_size) size if args.get('usage') else block_size)
datas_ += 1 datas_ += 1
continue continue
@@ -1332,7 +1332,7 @@ def main(disk, mroots=None, *,
continue continue
for block in rbyd_.blocks: for block in rbyd_.blocks:
bmap.btree(block, bmap.btree(block,
rbyd_.eoff if args.get('in_use') rbyd_.eoff if args.get('usage')
else block_size) else block_size)
btrees_ += 1 btrees_ += 1
ppath = path ppath = path
@@ -1359,8 +1359,8 @@ def main(disk, mroots=None, *,
# mark blocks in our bmap # mark blocks in our bmap
bmap.data(block, bmap.data(block,
off if args.get('in_use') else 0, off if args.get('usage') else 0,
size if args.get('in_use') else block_size) size if args.get('usage') else block_size)
datas_ += 1 datas_ += 1
#### actual rendering begins here #### actual rendering begins here
@@ -1439,15 +1439,16 @@ if __name__ == "__main__":
for x in x.split(',')), for x in x.split(',')),
help="Show this many bytes, may be a range.") help="Show this many bytes, may be a range.")
parser.add_argument( parser.add_argument(
'-M', '--mdirs', '--mdirs',
action='store_true', action='store_true',
help="Render mdir blocks.") help="Render mdir blocks.")
parser.add_argument( parser.add_argument(
'-B', '--btrees', '--btrees',
action='store_true', action='store_true',
help="Render btree blocks.") help="Render btree blocks.")
parser.add_argument( parser.add_argument(
'-D', '--datas', '--data', '--datas',
dest='datas',
action='store_true', action='store_true',
help="Render data blocks.") help="Render data blocks.")
parser.add_argument( parser.add_argument(
@@ -1503,9 +1504,13 @@ if __name__ == "__main__":
'-Z', '--lebesgue', '-Z', '--lebesgue',
action='store_true', action='store_true',
help="Render as a space-filling Z-curve.") help="Render as a space-filling Z-curve.")
# need a special Action here because this % causes problems
class StoreTrueUsage(argparse._StoreTrueAction):
def format_usage(self):
return '-%%'
parser.add_argument( parser.add_argument(
'-i', '--in-use', '-%', '--usage',
action='store_true', action=StoreTrueUsage,
help="Show how much of each block is in use.") help="Show how much of each block is in use.")
parser.add_argument( parser.add_argument(
'-z', '--depth', '-z', '--depth',
+49 -49
View File
@@ -334,9 +334,9 @@ class Pixel(int):
return self.wear / max(max_wear, len(wear_chars)) return self.wear / max(max_wear, len(wear_chars))
def draw(self, max_wear, char=None, *, def draw(self, max_wear, char=None, *,
read=True, reads=True,
prog=True, progs=True,
erase=True, erases=True,
wear=False, wear=False,
block_cycles=None, block_cycles=None,
color=True, color=True,
@@ -378,13 +378,13 @@ class Pixel(int):
c = wear_chars[int(w * (len(wear_chars)-1))] c = wear_chars[int(w * (len(wear_chars)-1))]
f.append(wear_colors[int(w * (len(wear_colors)-1))]) f.append(wear_colors[int(w * (len(wear_colors)-1))])
if prog and self.proged: if progs and self.proged:
c = chars[1] c = chars[1]
f.append(colors[1]) f.append(colors[1])
elif erase and self.erased: elif erases and self.erased:
c = chars[2] c = chars[2]
f.append(colors[2]) f.append(colors[2])
elif read and self.readed: elif reads and self.readed:
c = chars[0] c = chars[0]
f.append(colors[0]) f.append(colors[0])
@@ -541,9 +541,9 @@ class Bmap:
self.pixels = pixels self.pixels = pixels
def draw(self, row, *, def draw(self, row, *,
read=False, reads=False,
prog=False, progs=False,
erase=False, erases=False,
wear=False, wear=False,
hilbert=False, hilbert=False,
lebesgue=False, lebesgue=False,
@@ -600,10 +600,10 @@ class Bmap:
for i in range(2*4): for i in range(2*4):
p = grid[x+(2-1-(i%2)) + ((row*4)+(4-1-(i//2)))*self.width] p = grid[x+(2-1-(i%2)) + ((row*4)+(4-1-(i//2)))*self.width]
best_p |= p best_p |= p
if ((read and p.readed) if ((reads and p.readed)
or (prog and p.proged) or (progs and p.proged)
or (erase and p.erased) or (erases and p.erased)
or (not read and not prog and not erase or (not reads and not progs and not erases
and wear and p.worn(max_wear, **args) >= 0.7)): and wear and p.worn(max_wear, **args) >= 0.7)):
byte_p |= 1 << i byte_p |= 1 << i
@@ -611,9 +611,9 @@ class Bmap:
max_wear, max_wear,
CHARS_BRAILLE[byte_p], CHARS_BRAILLE[byte_p],
braille=True, braille=True,
read=read, reads=reads,
prog=prog, progs=progs,
erase=erase, erases=erases,
wear=wear, wear=wear,
**args)) **args))
elif dots: elif dots:
@@ -624,10 +624,10 @@ class Bmap:
for i in range(2): for i in range(2):
p = grid[x + ((row*2)+(2-1-i))*self.width] p = grid[x + ((row*2)+(2-1-i))*self.width]
best_p |= p best_p |= p
if ((read and p.readed) if ((reads and p.readed)
or (prog and p.proged) or (progs and p.proged)
or (erase and p.erased) or (erases and p.erased)
or (not read and not prog and not erase or (not reads and not progs and not erases
and wear and p.worn(max_wear, **args) >= 0.7)): and wear and p.worn(max_wear, **args) >= 0.7)):
byte_p |= 1 << i byte_p |= 1 << i
@@ -635,18 +635,18 @@ class Bmap:
max_wear, max_wear,
CHARS_DOTS[byte_p], CHARS_DOTS[byte_p],
dots=True, dots=True,
read=read, reads=reads,
prog=prog, progs=progs,
erase=erase, erases=erases,
wear=wear, wear=wear,
**args)) **args))
else: else:
for x in range(self.width): for x in range(self.width):
line.append(grid[x + row*self.width].draw( line.append(grid[x + row*self.width].draw(
max_wear, max_wear,
read=read, reads=reads,
prog=prog, progs=progs,
erase=erase, erases=erases,
wear=wear, wear=wear,
**args)) **args))
@@ -661,9 +661,9 @@ def main(path='-', *,
block=None, block=None,
off=None, off=None,
size=None, size=None,
read=False, reads=False,
prog=False, progs=False,
erase=False, erases=False,
wear=False, wear=False,
reset=False, reset=False,
no_header=False, no_header=False,
@@ -689,11 +689,11 @@ def main(path='-', *,
else: else:
color = False color = False
# exclusive wear or read/prog/erase by default # exclusive wear or reads/progs/erases by default
if not read and not prog and not erase and not wear: if not reads and not progs and not erases and not wear:
read = True reads = True
prog = True progs = True
erase = True erases = True
# assume a reasonable lines/height if not specified # assume a reasonable lines/height if not specified
# #
@@ -877,7 +877,7 @@ def main(path='-', *,
else block_count_) else block_count_)
return True return True
elif m.group('read') and read: elif m.group('read') and reads:
block = int(m.group('read_block'), 0) block = int(m.group('read_block'), 0)
off = int(m.group('read_off'), 0) off = int(m.group('read_off'), 0)
size = int(m.group('read_size'), 0) size = int(m.group('read_size'), 0)
@@ -894,7 +894,7 @@ def main(path='-', *,
readed += size readed += size
return True return True
elif m.group('prog') and prog: elif m.group('prog') and progs:
block = int(m.group('prog_block'), 0) block = int(m.group('prog_block'), 0)
off = int(m.group('prog_off'), 0) off = int(m.group('prog_off'), 0)
size = int(m.group('prog_size'), 0) size = int(m.group('prog_size'), 0)
@@ -911,7 +911,7 @@ def main(path='-', *,
proged += size proged += size
return True return True
elif m.group('erase') and (erase or wear): elif m.group('erase') and (erases or wear):
block = int(m.group('erase_block'), 0) block = int(m.group('erase_block'), 0)
size = int(m.group('erase_size'), 0) size = int(m.group('erase_size'), 0)
@@ -947,9 +947,9 @@ def main(path='-', *,
else mt.ceil(bmap.height/2) if dots else mt.ceil(bmap.height/2) if dots
else bmap.height): else bmap.height):
line = bmap.draw(row, line = bmap.draw(row,
read=read, reads=reads,
prog=prog, progs=progs,
erase=erase, erases=erases,
wear=wear, wear=wear,
block_cycles=block_cycles, block_cycles=block_cycles,
color=color, color=color,
@@ -961,7 +961,7 @@ def main(path='-', *,
if line: if line:
f.writeln(line) f.writeln(line)
# print some information about read/prog/erases # print some information about reads/progs/erases
# #
# cat implies no-header, because a header wouldn't really make sense # cat implies no-header, because a header wouldn't really make sense
if not no_header and not cat: if not no_header and not cat:
@@ -969,7 +969,7 @@ def main(path='-', *,
total = readed+proged+erased total = readed+proged+erased
# compute stddev of wear using our bmap, this is a bit different # compute stddev of wear using our bmap, this is a bit different
# from read/prog/erase which ignores any bmap window, but it's # from reads/progs/erases which ignores any bmap window, but it's
# what we have # what we have
if wear: if wear:
mean = (sum(p.wear for p in bmap.pixels) mean = (sum(p.wear for p in bmap.pixels)
@@ -985,11 +985,11 @@ def main(path='-', *,
f.lines[0] = 'bd %dx%d%s%s%s%s' % ( f.lines[0] = 'bd %dx%d%s%s%s%s' % (
bmap.block_size, bmap.block_count, bmap.block_size, bmap.block_count,
', %6s read' % ('%.1f%%' % (100*readed / max(total, 1))) ', %6s read' % ('%.1f%%' % (100*readed / max(total, 1)))
if read else '', if reads else '',
', %6s prog' % ('%.1f%%' % (100*proged / max(total, 1))) ', %6s prog' % ('%.1f%%' % (100*proged / max(total, 1)))
if prog else '', if progs else '',
', %6s erase' % ('%.1f%%' % (100*erased / max(total, 1))) ', %6s erase' % ('%.1f%%' % (100*erased / max(total, 1)))
if erase else '', if erases else '',
', %13s wear' % ('%.1fσ (%.1f%%)' % ( ', %13s wear' % ('%.1fσ (%.1f%%)' % (
worst / max(stddev, 1), worst / max(stddev, 1),
100*stddev / max(worst, 1))) 100*stddev / max(worst, 1)))
@@ -1105,19 +1105,19 @@ if __name__ == "__main__":
for x in x.split(',')), for x in x.split(',')),
help="Show this many bytes, may be a range.") help="Show this many bytes, may be a range.")
parser.add_argument( parser.add_argument(
'-r', '--read', '--reads',
action='store_true', action='store_true',
help="Render reads.") help="Render reads.")
parser.add_argument( parser.add_argument(
'-p', '--prog', '--progs',
action='store_true', action='store_true',
help="Render progs.") help="Render progs.")
parser.add_argument( parser.add_argument(
'-e', '--erase', '--erases',
action='store_true', action='store_true',
help="Render erases.") help="Render erases.")
parser.add_argument( parser.add_argument(
'-w', '--wear', '--wear',
action='store_true', action='store_true',
help="Render wear.") help="Render wear.")
parser.add_argument( parser.add_argument(