Skip to content

Commit

Permalink
Fixed some confusion in tracebd.py around buffered lines with headers
Browse files Browse the repository at this point in the history
Also limited block_size/block_count updates to only happen when the
configured value is None. This matches dbgbmap.py.

Basically just a cleanup of some bugs after the rework related to
matching dbgbmap.py. Unfortunately these scripts have too much surface
area and no tests...
  • Loading branch information
geky committed Nov 13, 2023
1 parent 195d8c5 commit 7243c0f
Showing 1 changed file with 64 additions and 46 deletions.
110 changes: 64 additions & 46 deletions scripts/tracebd.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ def __init__(self, *,
block_count=1,
block_window=None,
off_window=None,
width=None,
width=1,
height=1,
pixels=None):
# default width to block_window or block_size
Expand Down Expand Up @@ -758,8 +758,8 @@ def main(path='-', *,

# create our block device representation
bmap = Bmap(
block_size=block_size,
block_count=block_count,
block_size=block_size if block_size is not None else 1,
block_count=block_count if block_count is not None else 1,
block_window=block_window,
off_window=off_window)

Expand Down Expand Up @@ -840,34 +840,40 @@ def parse(line):

if m.group('create'):
# update our block size/count
block_size = int(m.group('block_size'), 0)
block_count = int(m.group('block_count'), 0)
block_size_ = int(m.group('block_size'), 0)
block_count_ = int(m.group('block_count'), 0)

if reset:
bmap = Bmap(
block_size=block_size,
block_count=block_count,
block_size=block_size_,
block_count=block_count_,
block_window=bmap.block_window,
off_window=bmap.off_window,
width=bmap.width,
height=bmap.height)
else:
if (block_size != bmap.block_size
or block_count != bmap.block_count):
bmap.resize(
block_size=block_size,
block_count=block_count)
elif ((block_size is None
and block_size_ != bmap.block_size)
or (block_count is None
and block_count_ != bmap.block_count)):
bmap.resize(
block_size=block_size if block_size is not None
else block_size_,
block_count=block_count if block_count is not None
else block_count_)
return True

elif m.group('read') and read:
block = int(m.group('read_block'), 0)
off = int(m.group('read_off'), 0)
size = int(m.group('read_size'), 0)

if block >= bmap.block_count or off+size > bmap.block_size:
if ((block_size is None and off+size > bmap.block_size)
or (block_count is None and block >= bmap.block_count)):
bmap.resize(
block_size=max(off+size, bmap.block_size),
block_count=max(block+1, bmap.block_count))
block_size=block_size if block_size is not None
else max(off+size, bmap.block_size),
block_count=block_count if block_count is not None
else max(block+1, bmap.block_count))

bmap.read(block, off, size)
readed += size
Expand All @@ -878,10 +884,13 @@ def parse(line):
off = int(m.group('prog_off'), 0)
size = int(m.group('prog_size'), 0)

if block >= bmap.block_count or off+size > bmap.block_size:
if ((block_size is None and off+size > bmap.block_size)
or (block_count is None and block >= bmap.block_count)):
bmap.resize(
block_size=max(off+size, bmap.block_size),
block_count=max(block+1, bmap.block_count))
block_size=block_size if block_size is not None
else max(off+size, bmap.block_size),
block_count=block_count if block_count is not None
else max(block+1, bmap.block_count))

bmap.prog(block, off, size)
proged += size
Expand All @@ -891,10 +900,13 @@ def parse(line):
block = int(m.group('erase_block'), 0)
size = int(m.group('erase_size'), 0)

if block >= bmap.block_count or size > bmap.block_size:
if ((block_size is None and size > bmap.block_size)
or (block_count is None and block >= bmap.block_count)):
bmap.resize(
block_size=max(off+size, bmap.block_size),
block_count=max(block+1, bmap.block_count))
block_size=block_size if block_size is not None
else max(size, bmap.block_size),
block_count=block_count if block_count is not None
else max(block+1, bmap.block_count))

bmap.erase(block, size)
erased += size
Expand All @@ -914,8 +926,30 @@ def writeln(s=''):
f.write('\n')
f.writeln = writeln

# don't forget we've scaled this for braille/dots!
for row in range(
m.ceil(bmap.height/4) if braille
else m.ceil(bmap.height/2) if dots
else bmap.height):
line = bmap.draw(row,
read=read,
prog=prog,
erase=erase,
wear=wear,
block_cycles=block_cycles,
color=color,
dots=dots,
braille=braille,
hilbert=hilbert,
lebesgue=lebesgue,
**args)
if line:
f.writeln(line)

# print some information about read/prog/erases
if not no_header:
#
# cat implies no-header, because a header wouldn't really make sense
if not no_header and not cat:
# compute total ops
total = readed+proged+erased

Expand All @@ -929,8 +963,12 @@ def writeln(s=''):
/ max(len(bmap.pixels), 1))
worst = max((p.wear for p in bmap.pixels), default=0)

f.writeln('bd %dx%d%s%s%s%s' % (
block_size, block_count,
# a bit of a hack here, but this forces our header to always be
# at row zero
if len(f.lines) == 0:
f.lines.append('')
f.lines[0] = 'bd %dx%d%s%s%s%s' % (
bmap.block_size, bmap.block_count,
', %6s read' % ('%.1f%%' % (100*readed / max(total, 1)))
if read else '',
', %6s prog' % ('%.1f%%' % (100*proged / max(total, 1)))
Expand All @@ -940,27 +978,7 @@ def writeln(s=''):
', %13s wear' % ('%.1fσ (%.1f%%)' % (
worst / max(stddev, 1),
100*stddev / max(worst, 1)))
if wear else ''))

# don't forget we've scaled this for braille/dots!
for row in range(
m.ceil(bmap.height/4) if braille
else m.ceil(bmap.height/2) if dots
else bmap.height):
line = bmap.draw(row,
read=read,
prog=prog,
erase=erase,
wear=wear,
block_cycles=block_cycles,
color=color,
dots=dots,
braille=braille,
hilbert=hilbert,
lebesgue=lebesgue,
**args)
if line:
f.writeln(line)
if wear else '')

bmap.clear()
readed = 0
Expand Down

0 comments on commit 7243c0f

Please sign in to comment.