-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add functions to gather occupancy info
- Loading branch information
1 parent
c889dae
commit f35038a
Showing
1 changed file
with
27 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |