scripts: treemap.py/codemap.py: Use parts of name for char defaults

So by default, instead of just using "." for tiles, we use interesting
parts of the tile's name:

- For treemap.py, we use the first character of the last by-field (so
  "lfs.c,lfsr_file_write,1234" -> "1").

- For codemap.py, we use the first character of the non-subsystem part
  of the function name (so "lfsr_file_write" -> "w").

This nice thing about this, is the resulting treemap is somewhat
understandable even without colors:

  $ ./scripts/codemap.py lfs.o lfs_util.o lfs.ci lfs_util.ci -W60 -H8
  code 35528 stack 2440 ctx 636
  ffffffoooffaaaaaaaaaaaacccccccccttttccccrrrrpgffmmrraifmmcss
  ffffffwwwttaaaaaaaaaaaacccccccccttttccccrprrpcscmmoommrrcepp
  ffffffwwwttaaaaaaaaalllcccccccccttttccccrpppccscmmsrmmrrrrss
  ccccssrrfclaaaaanneeasscccccccccgpppccccrpppsgsummstmmrrlfgf
  ccccssrrfccaaaaanneeaaaccccccsaagpppcccccrrrfrrcccrrfiiilucs
  ccccssrrtfcfffffaapplcccccccclssgnnllllcrrffrrrccccifssscmcm
  ccccssrrtrdfffffaapppapcccfffllsgnnllllcrrrffrrcccorfsssicnu

Ok, so maybe the word "somewhat" is doing a lot of heavy lifting...
This commit is contained in:
Christopher Haster
2025-03-11 03:24:32 -05:00
parent 3d53f5393d
commit 59ffbde3ad
2 changed files with 22 additions and 26 deletions

View File

@@ -23,7 +23,6 @@ import subprocess as sp
# we don't actually need that many chars/colors thanks to the # we don't actually need that many chars/colors thanks to the
# 4-colorability of all 2d maps # 4-colorability of all 2d maps
CHARS = ['.']
COLORS = ['34', '31', '32', '35', '33', '36'] COLORS = ['34', '31', '32', '35', '33', '36']
CHARS_DOTS = " .':" CHARS_DOTS = " .':"
@@ -740,7 +739,7 @@ def main(paths, *,
chars_.extend((char[0], c) for c in psplit(char[1])) chars_.extend((char[0], c) for c in psplit(char[1]))
else: else:
chars_.extend(psplit(char)) chars_.extend(psplit(char))
chars_ = Attr(chars_, defaults=CHARS) chars_ = Attr(chars_)
colors_ = Attr(colors, defaults=COLORS) colors_ = Attr(colors, defaults=COLORS)
@@ -948,9 +947,16 @@ def main(paths, *,
# assign colors/chars/labels to code tiles # assign colors/chars/labels to code tiles
for i, t in enumerate(code.leaves()): for i, t in enumerate(code.leaves()):
t.color = subsystems[t.attrs['subsystem']]['color'] t.color = subsystems[t.attrs['subsystem']]['color']
t.char = punescape( if (i, (t.attrs['name'],)) in chars_:
chars_[i, (t.attrs['name'],)], t.char = punescape(
t.attrs['attrs'] | t.attrs)[0] # limit to 1 char chars_[i, (t.attrs['name'],)],
t.attrs['attrs'] | t.attrs)[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]
else:
t.char = (t.attrs['subsystem'].rstrip('_').rsplit('_', 1)[-1]
or '')[0]
if (i, (t.attrs['name'],)) in labels_: if (i, (t.attrs['name'],)) in labels_:
t.label = punescape( t.label = punescape(
labels_[i, (t.attrs['name'],)], labels_[i, (t.attrs['name'],)],
@@ -1087,16 +1093,11 @@ def main(paths, *,
y__ = canvas.height - (y__+height__) y__ = canvas.height - (y__+height__)
canvas.rect(x__, y__, width__, height__, canvas.rect(x__, y__, width__, height__,
# default to first letter in each label/key # default to first letter of the last part of the key
char=(True if braille or dots char=(True if braille or dots
else t.label[0] else t.char if getattr(t, 'char', None)
if chars is None else t.key[len(by)-1][0] if t.key and t.key[len(by)-1]
and t.label is not None else chars_[0]),
else t.key[-1][0]
if chars is None
and t.key
and t.key[-1]
else t.char if t.char is not None else chars_[0]),
color=t.color if t.color is not None else colors_[0]) color=t.color if t.color is not None else colors_[0])
if label: if label:

View File

@@ -20,7 +20,6 @@ import shutil
# we don't actually need that many chars/colors thanks to the # we don't actually need that many chars/colors thanks to the
# 4-colorability of all 2d maps # 4-colorability of all 2d maps
CHARS = ['.']
COLORS = ['34', '31', '32', '35', '33', '36'] COLORS = ['34', '31', '32', '35', '33', '36']
CHARS_DOTS = " .':" CHARS_DOTS = " .':"
@@ -754,7 +753,7 @@ def main(csv_paths, *,
chars_.extend((char[0], c) for c in psplit(char[1])) chars_.extend((char[0], c) for c in psplit(char[1]))
else: else:
chars_.extend(psplit(char)) chars_.extend(psplit(char))
chars_ = Attr(chars_, defaults=CHARS) chars_ = Attr(chars_)
colors_ = Attr(colors, defaults=COLORS) colors_ = Attr(colors, defaults=COLORS)
@@ -836,7 +835,8 @@ def main(csv_paths, *,
# and chars/labels for bottom of tree # and chars/labels for bottom of tree
for i, t in enumerate(tile.leaves()): for i, t in enumerate(tile.leaves()):
t.char = punescape(chars_[i, t.key], t.attrs)[0] # limit to 1 char if (i, t.key) in chars_:
t.char = punescape(chars_[i, t.key], t.attrs)[0] # limit to 1 char
if (i, t.key) in labels_: if (i, t.key) in labels_:
t.label = punescape(labels_[i, t.key], t.attrs) t.label = punescape(labels_[i, t.key], t.attrs)
@@ -970,16 +970,11 @@ def main(csv_paths, *,
y__ = canvas.height - (y__+height__) y__ = canvas.height - (y__+height__)
canvas.rect(x__, y__, width__, height__, canvas.rect(x__, y__, width__, height__,
# default to first letter in each label/key # default to first letter of the last part of the key
char=(True if braille or dots char=(True if braille or dots
else t.label[0] else t.char if getattr(t, 'char', None)
if chars is None else t.key[len(by)-1][0] if t.key and t.key[len(by)-1]
and t.label is not None else chars_[0]),
else t.key[-1][0]
if chars is None
and t.key
and t.key[-1]
else t.char if t.char is not None else chars_[0]),
color=t.color if t.color is not None else colors_[0]) color=t.color if t.color is not None else colors_[0])
if label: if label: