diff --git a/scripts/codemap.py b/scripts/codemap.py index 2ad19c30..0f66d431 100755 --- a/scripts/codemap.py +++ b/scripts/codemap.py @@ -897,7 +897,7 @@ def collect_ctx(obj_paths, *, return ctx -def main_(f, paths, *, +def main_(ring, paths, *, namespace_depth=2, labels=[], chars=[], @@ -916,11 +916,11 @@ def main_(f, paths, *, label=False, no_label=False, **args): - # give f an writeln function + # give ring an writeln function def writeln(s=''): - f.write(s) - f.write('\n') - f.writeln = writeln + ring.write(s) + ring.write('\n') + ring.writeln = writeln # figure out what color should be if color == 'auto': @@ -971,25 +971,25 @@ def main_(f, paths, *, # elf/callgraph files fs = [] for path in paths: - f_ = openio(path) - if f_.buffer.peek(4)[:4] == b'\x7fELF': - for f_ in fs: - f_.close() + f = openio(path) + if f.buffer.peek(4)[:4] == b'\x7fELF': + for f in fs: + f.close() raise StopIteration() - fs.append(f_) + fs.append(f) - for f_ in fs: - with f_: + for f in fs: + with f: # csv or json? assume json starts with [ - is_json = (f_.buffer.peek(1)[:1] == b'[') + is_json = (f.buffer.peek(1)[:1] == b'[') # read csv? if not is_json: - results.extend(csv.DictReader(f_, restval='')) + results.extend(csv.DictReader(f, restval='')) # read json? else: - results.extend(json.load(f_)) + results.extend(json.load(f)) # fall back to extracting code/stack/ctx info from elf/callgraph files except StopIteration: @@ -1069,29 +1069,29 @@ def main_(f, paths, *, return f['frame'] + limit - for k, f_ in functions.items(): - if 'stack' in f_: - if mt.isinf(f_['stack']): - f_['limit'] = limitof(k, f_) + for k, f in functions.items(): + if 'stack' in f: + if mt.isinf(f['stack']): + f['limit'] = limitof(k, f) else: - f_['limit'] = f_['stack'] + f['limit'] = f['stack'] # organize into subsystems namespace_pattern = re.compile('_*[^_]+(?:_*$)?') namespace_slice = slice(namespace_depth if namespace_depth else None) subsystems = {} - for k, f_ in functions.items(): + for k, f in functions.items(): # ignore leading/trailing underscores - f_['subsystem'] = ''.join( + f['subsystem'] = ''.join( namespace_pattern.findall(k)[ namespace_slice]) - if f_['subsystem'] not in subsystems: - subsystems[f_['subsystem']] = {'name': f_['subsystem']} + if f['subsystem'] not in subsystems: + subsystems[f['subsystem']] = {'name': f['subsystem']} # include ctx in subsystems to give them different colors - for _, f_ in functions.items(): - for a in f_.get('args', []): + for _, f in functions.items(): + for a in f.get('args', []): a['subsystem'] = a['name'] if a['subsystem'] not in subsystems: @@ -1339,9 +1339,9 @@ def main_(f, paths, *, # print some summary info if not no_header: if title: - f.writeln(punescape(title, totals['attrs'] | totals)) + ring.writeln(punescape(title, totals['attrs'] | totals)) else: - f.writeln('code %d stack %s ctx %d' % ( + ring.writeln('code %d stack %s ctx %d' % ( totals.get('code', 0), (lambda s: '∞' if mt.isinf(s) else s)( totals.get('stack', 0)), @@ -1350,7 +1350,7 @@ def main_(f, paths, *, # draw canvas for row in range(canvas.height//canvas.yscale): line = canvas.draw(row) - f.writeln(line) + ring.writeln(line) if (args.get('error_on_recursion') and mt.isinf(totals.get('stack', 0))): diff --git a/scripts/dbgbmap.py b/scripts/dbgbmap.py index 2de8ac52..9eb7b3fd 100755 --- a/scripts/dbgbmap.py +++ b/scripts/dbgbmap.py @@ -4327,7 +4327,7 @@ class BmapBlock: } -def main_(f, disk, mroots=None, *, +def main_(ring, disk, mroots=None, *, trunk=None, block_size=None, block_count=None, @@ -4357,11 +4357,11 @@ def main_(f, disk, mroots=None, *, title_usage=False, padding=0, **args): - # give f an writeln function + # give ring an writeln function def writeln(s=''): - f.write(s) - f.write('\n') - f.writeln = writeln + ring.write(s) + ring.write('\n') + ring.writeln = writeln # figure out what color should be if color == 'auto': @@ -4435,14 +4435,14 @@ def main_(f, disk, mroots=None, *, None)) # we seek around a bunch, so just keep the disk open - with open(disk, 'rb') as f_: + with open(disk, 'rb') as f: # if block_size is omitted, assume the block device is one big block if block_size is None: - f_.seek(0, os.SEEK_END) - block_size = f_.tell() + f.seek(0, os.SEEK_END) + block_size = f.tell() # fetch the filesystem - bd = Bd(f_, block_size, block_count) + bd = Bd(f, block_size, block_count) lfs = Lfs.fetch(bd, mroots, trunk, # don't bother to check things if we're not reporting errors no_ck=not args.get('error_on_corrupt')) @@ -4455,8 +4455,8 @@ def main_(f, disk, mroots=None, *, if lfs.config.geometry is not None: block_count_ = lfs.config.geometry.block_count else: - f_.seek(0, os.SEEK_END) - block_count_ = mt.ceil(f_.tell() / block_size) + f.seek(0, os.SEEK_END) + block_count_ = mt.ceil(f.tell() / block_size) # flatten blocks, default to all blocks blocks_ = list( @@ -4755,7 +4755,7 @@ def main_(f, disk, mroots=None, *, # print some summary info if not no_header: if title: - f.writeln(punescape(title, { + ring.writeln(punescape(title, { 'magic': 'littlefs%s' % ( '' if lfs.ckmagic() else '?'), 'version': 'v%s.%s' % ( @@ -4799,7 +4799,7 @@ def main_(f, disk, mroots=None, *, 100*data_count / max(len(bmap), 1)), })) elif title_littlefs: - f.writeln('littlefs%s v%s.%s %sx%s %s w%s.%s, cksum %08x%s' % ( + ring.writeln('littlefs%s v%s.%s %sx%s %s w%s.%s, cksum %08x%s' % ( '' if lfs.ckmagic() else '?', lfs.version.major if lfs.version is not None else '?', lfs.version.minor if lfs.version is not None else '?', @@ -4810,7 +4810,7 @@ def main_(f, disk, mroots=None, *, lfs.cksum, '' if lfs.ckgcksum() else '?')) else: - f.writeln('bd %sx%s, %6s mdir, %6s btree, %6s data' % ( + ring.writeln('bd %sx%s, %6s mdir, %6s btree, %6s data' % ( lfs.block_size if lfs.block_size is not None else '?', lfs.block_count if lfs.block_count is not None else '?', '%.1f%%' % (100*mdir_count / max(len(bmap), 1)), @@ -4820,7 +4820,7 @@ def main_(f, disk, mroots=None, *, # draw canvas for row in range(canvas.height//canvas.yscale): line = canvas.draw(row) - f.writeln(line) + ring.writeln(line) if args.get('error_on_corrupt') and corrupted: sys.exit(2) diff --git a/scripts/plot.py b/scripts/plot.py index 107a21e5..8df22cff 100755 --- a/scripts/plot.py +++ b/scripts/plot.py @@ -1152,7 +1152,7 @@ class Grid: return grid -def main_(f, csv_paths, *, +def main_(ring, csv_paths, *, by=None, x=None, y=None, @@ -1187,11 +1187,11 @@ def main_(f, csv_paths, *, subplot={}, subplots=[], **args): - # give f an writeln function + # give ring an writeln function def writeln(s=''): - f.write(s) - f.write('\n') - f.writeln = writeln + ring.write(s) + ring.write('\n') + ring.writeln = writeln # figure out what color should be if color == 'auto': @@ -1643,14 +1643,14 @@ def main_(f, csv_paths, *, # draw title? for line in title_: - f.writeln('%*s%s' % ( + ring.writeln('%*s%s' % ( sum(xmargin[:2]), '', line.center(width_-xmargin[1]))) # draw legend_above? if legend_above and legend_: for i in range(0, len(legend_), legend_cols): - f.writeln('%*s%s' % ( + ring.writeln('%*s%s' % ( max( sum(xmargin[:2]) + (width_-xmargin[1] @@ -1665,7 +1665,7 @@ def main_(f, csv_paths, *, for row in range(height_): # draw ylabel? - f.write('%s ' % ''.join( + ring.write('%s ' % ''.join( ('%*s%s%*s' % ( ymargin[-1], '', line.center(height_-sum(ymargin)), @@ -1688,11 +1688,11 @@ def main_(f, csv_paths, *, if subrow < s.ymargin[-1]: # draw subtitle? if subrow < len(s.title_): - f.write('%*s%s' % ( + ring.write('%*s%s' % ( sum(s.xmargin[:2]), '', s.title_[subrow].center(s.width_))) else: - f.write('%*s%*s' % ( + ring.write('%*s%*s' % ( sum(s.xmargin[:2]), '', s.width_, '')) # draw plot? @@ -1700,7 +1700,7 @@ def main_(f, csv_paths, *, subrow = subrow-s.ymargin[-1] # draw ysublabel? - f.write('%-*s' % ( + ring.write('%-*s' % ( s.xmargin[0], '%s ' % ''.join( line.center(s.height_)[subrow] @@ -1709,25 +1709,25 @@ def main_(f, csv_paths, *, # draw yunits? if subrow == 0 and s.yticklabels_ != []: - f.write('%*s' % ( + ring.write('%*s' % ( s.xmargin[1], ((si2 if s.y2 else si)(s.ylim_[1]) + s.yunits if s.yticklabels_ is None else s.yticklabels_[1]) + ' ')) elif subrow == s.height_-1 and s.yticklabels_ != []: - f.write('%*s' % ( + ring.write('%*s' % ( s.xmargin[1], ((si2 if s.y2 else si)(s.ylim_[0]) + s.yunits if s.yticklabels_ is None else s.yticklabels_[0]) + ' ')) else: - f.write('%*s' % ( + ring.write('%*s' % ( s.xmargin[1], '')) # draw plot! - f.write(s.plot_.draw(subrow)) + ring.write(s.plot_.draw(subrow)) # footer else: @@ -1735,7 +1735,7 @@ def main_(f, csv_paths, *, # draw xunits? if subrow < (1 if s.xticklabels_ != [] else 0): - f.write('%*s%-*s%*s%*s' % ( + ring.write('%*s%-*s%*s%*s' % ( sum(s.xmargin[:2]), '', (5 if s.x2 else 4) + len(s.xunits) if s.xticklabels_ is None @@ -1756,11 +1756,11 @@ def main_(f, csv_paths, *, # draw xsublabel? elif (subrow < s.ymargin[1] or subrow-s.ymargin[1] >= len(s.xlabel_)): - f.write('%*s%*s' % ( + ring.write('%*s%*s' % ( sum(s.xmargin[:2]), '', s.width_, '')) else: - f.write('%*s%s' % ( + ring.write('%*s%s' % ( sum(s.xmargin[:2]), '', s.xlabel_[subrow-s.ymargin[1]] .center(s.width_))) @@ -1770,23 +1770,23 @@ def main_(f, csv_paths, *, and row >= ymargin[-1] and row-ymargin[-1] < len(legend_)): j = row-ymargin[-1] - f.write(' %s%s%s' % ( + ring.write(' %s%s%s' % ( '\x1b[%sm' % legend_[j][1] if color else '', legend_[j][0], '\x1b[m' if color else '')) - f.writeln() + ring.writeln() # draw xlabel? for line in xlabel_: - f.writeln('%*s%s' % ( + ring.writeln('%*s%s' % ( sum(xmargin[:2]), '', line.center(width_-xmargin[1]))) # draw legend below? if legend_below and legend_: for i in range(0, len(legend_), legend_cols): - f.writeln('%*s%s' % ( + ring.writeln('%*s%s' % ( max( sum(xmargin[:2]) + (width_-xmargin[1] diff --git a/scripts/tailpipe.py b/scripts/tailpipe.py index 8e33afaa..ebceed67 100755 --- a/scripts/tailpipe.py +++ b/scripts/tailpipe.py @@ -134,7 +134,6 @@ def main(path='-', *, lock = th.Lock() event = th.Event() - # TODO adopt f -> ring name in all scripts? def main_(ring): try: while True: diff --git a/scripts/tracebd.py b/scripts/tracebd.py index 9252a862..d5789836 100755 --- a/scripts/tracebd.py +++ b/scripts/tracebd.py @@ -1697,7 +1697,6 @@ def main(path='-', *, else: curve = ft.lru_cache(16)(lambda w, h: list(naive_curve(w, h))) - # TODO adopt f -> ring name in all scripts? def draw__(ring, width, height): nonlocal bmap # still waiting on bd init diff --git a/scripts/treemap.py b/scripts/treemap.py index 5d2f3131..439355aa 100755 --- a/scripts/treemap.py +++ b/scripts/treemap.py @@ -908,7 +908,7 @@ def partition_squarify(children, total, x, y, width, height, *, i = j -def main_(f, csv_paths, *, +def main_(ring, csv_paths, *, by=None, fields=None, defines=[], @@ -930,11 +930,11 @@ def main_(f, csv_paths, *, label=False, no_label=False, **args): - # give f an writeln function + # give ring an writeln function def writeln(s=''): - f.write(s) - f.write('\n') - f.writeln = writeln + ring.write(s) + ring.write('\n') + ring.writeln = writeln # figure out what color should be if color == 'auto': @@ -1215,19 +1215,19 @@ def main_(f, csv_paths, *, stat['mean'], stat['stddev'], stat['min'], stat['max']) if title and not no_stats: - f.writeln('%s%*s%s' % ( + ring.writeln('%s%*s%s' % ( title_, max(width_-len(stat_)-len(title_), 0), ' ', stat_)) elif title: - f.writeln(title_) + ring.writeln(title_) elif not no_stats: - f.writeln(stat_) + ring.writeln(stat_) # draw canvas for row in range(canvas.height//canvas.yscale): line = canvas.draw(row) - f.writeln(line) + ring.writeln(line) def main(csv_paths, *,