scripts: Adopted ctx.py-related changes in other result scripts

- Adopted higher-level collect data structures:

  - high-level DwarfEntry/DwarfInfo class
  - high-level SymInfo class
  - high-level LineInfo class

  Note these had to be moved out of function scope due to pickling
  issues in perf.py/perfbd.py. These were only function-local to
  minimize scope leak so this fortunately was an easy change.

- Adopted better list-default patterns in Result types:

    def __new__(..., children=None):
        return Result(..., children if children is not None else [])

  A classic python footgun.

- Adopted notes rendering, though this is only used by ctx.py at the
  moment.

- Reverted to sorting children entries, for now.

  Unfortunately there's no easy way to sort the result entries in
  perf.py/perfbd.py before folding. Folding is going to make a mess
  of more complicated children anyways, so another solution is
  needed...

And some other shared miscellany.
This commit is contained in:
Christopher Haster
2024-12-01 16:59:51 -06:00
parent b4c79c53d2
commit 512cf5ad4b
9 changed files with 805 additions and 510 deletions

View File

@@ -129,12 +129,11 @@ class StackResult(co.namedtuple('StackResult', [
_types = {'frame': RInt, 'limit': RInt}
__slots__ = ()
def __new__(cls, file='', function='',
frame=0, limit=0,
children=[]):
def __new__(cls, file='', function='', frame=0, limit=0,
children=None):
return super().__new__(cls, file, function,
RInt(frame), RInt(limit),
children)
children if children is not None else [])
def __add__(self, other):
return StackResult(self.file, self.function,
@@ -527,6 +526,9 @@ def table(Result, results, diff_results=None, *,
types[k].ratio(
getattr(r, k, None),
getattr(diff_r, k, None)))))
# append any notes
if hasattr(r, 'notes'):
entry[-1][1].extend(r.notes)
return entry
# recursive entry helper, only used by some scripts