We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent c889dae commit d9bbcddCopy full SHA for d9bbcdd
1 file changed
util/analyze/lib/func_stats.py
@@ -0,0 +1,27 @@
1
+#!/usr/bin/env python3
2
+
3
+import re
4
+from itertools import chain
5
+from typing import 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) -> Iterable[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