Skip to content

Commit f35038a

Browse files
committed
Add functions to gather occupancy info
1 parent c889dae commit f35038a

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

util/analyze/lib/func_stats.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env python3
2+
3+
import re
4+
from itertools import chain
5+
from typing import Generator, Iterable, List
6+
7+
from analyze import Block
8+
9+
'''
10+
Function-level stats (not Block, Logs, or Benchmark level)
11+
'''
12+
13+
_RE_OCCUPANCY = re.compile(r'Final occupancy for function (?P<name>\S+):(?P<value>\d+)')
14+
15+
16+
def _occupancy_info_in_block_log(block: Block) -> Generator[int]:
17+
for m in _RE_OCCUPANCY.finditer(block.raw_log):
18+
yield m['value']
19+
20+
21+
def function_occupancy_info(logs: Iterable[Block]) -> List[int]:
22+
return list(chain.from_iterable(map(_occupancy_info_in_block_log, logs)))
23+
24+
25+
def avg_occupancy(logs: Iterable[Block]) -> float:
26+
occ_info = function_occupancy_info(logs)
27+
return sum(occ_info) / len(occ_info) if occ_info else 0.0

0 commit comments

Comments
 (0)