forked from Imagelibrary/littlefs
scripts: treemaps: Fixed crashes when there's nothing to show
Crashing on invalid input isn't the _worst_ behavior, but with a few tweaks we can make these scripts more-or-less noop in such cases. This is useful when running with -k/--keep-open since intermediate file states often contain garbage. (Ironically one of the precise problems littlefs is trying to solve.) Also added a special case to treemap.py/codemap.py to not output the canvas if there's nothing to show and height is implicit. Otherwise the history mode with -n/--lines ends up filled with blank lines. Note this makes -H1 subtly different from no -H/--height, with -H1 printing a blank line if there is nothing to show. The -H1 behavior may also be useful in niche cases where you want that part of the screen cleared. --- This was found while trying to run codemap.py -k -n5 during compilation. GCC writes object files incrementally, and this was breaking our script.
This commit is contained in:
@@ -1019,6 +1019,8 @@ def main_(f, paths, *,
|
||||
# merge code/stack/ctx results
|
||||
functions = co.OrderedDict()
|
||||
for r in results:
|
||||
if 'function' not in r:
|
||||
continue
|
||||
if r['function'] not in functions:
|
||||
functions[r['function']] = {'name': r['function']}
|
||||
# code things
|
||||
@@ -1155,6 +1157,10 @@ def main_(f, paths, *,
|
||||
|
||||
# assign colors/chars/labels to code tiles
|
||||
for i, t in enumerate(code.leaves()):
|
||||
# skip the top tile, yes this can happen if we have no code
|
||||
if t.depth == 0:
|
||||
continue
|
||||
|
||||
t.color = subsystems[t.attrs['subsystem']]['color']
|
||||
|
||||
if (i, t.attrs['name']) in chars_:
|
||||
@@ -1218,6 +1224,11 @@ def main_(f, paths, *,
|
||||
((total_value * to_scale) / (width_*xscale))
|
||||
/ yscale)
|
||||
|
||||
# as a special case, if height is implicit and we have nothing to
|
||||
# show, don't print anything
|
||||
if height is None and nil_code and nil_frames and nil_ctx:
|
||||
height_ = 1 if not no_header else 0
|
||||
|
||||
# our general purpose partition function
|
||||
def partition(tile, **args):
|
||||
if tile.depth == 0:
|
||||
|
||||
Reference in New Issue
Block a user