Skip to content

Commit

Permalink
Add functions to gather occupancy info
Browse files Browse the repository at this point in the history
  • Loading branch information
Quincunx271 committed Aug 4, 2021
1 parent c889dae commit f35038a
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions util/analyze/lib/func_stats.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env python3

import re
from itertools import chain
from typing import Generator, Iterable, List

from analyze import Block

'''
Function-level stats (not Block, Logs, or Benchmark level)
'''

_RE_OCCUPANCY = re.compile(r'Final occupancy for function (?P<name>\S+):(?P<value>\d+)')


def _occupancy_info_in_block_log(block: Block) -> Generator[int]:
for m in _RE_OCCUPANCY.finditer(block.raw_log):
yield m['value']


def function_occupancy_info(logs: Iterable[Block]) -> List[int]:
return list(chain.from_iterable(map(_occupancy_info_in_block_log, logs)))


def avg_occupancy(logs: Iterable[Block]) -> float:
occ_info = function_occupancy_info(logs)
return sum(occ_info) / len(occ_info) if occ_info else 0.0

0 comments on commit f35038a

Please sign in to comment.