Skip to content

Commit

Permalink
Add main function to func_stats
Browse files Browse the repository at this point in the history
  • Loading branch information
Quincunx271 committed Aug 4, 2021
1 parent 0976ac6 commit da627e1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
2 changes: 1 addition & 1 deletion util/analyze/lib/block_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,4 @@ def compute_block_stats(logs: Logs):

results = utils.foreach_bench(compute_block_stats, args.logs)

args.format(result)
args.format(results)
28 changes: 27 additions & 1 deletion util/analyze/lib/func_stats.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#!/usr/bin/env python3

import argparse
import re
import sys
from itertools import chain
from typing import Iterable, List

from analyze import Block
import analyze
from analyze import Block, ioutils, utils

'''
Function-level stats (not Block, Logs, or Benchmark level)
Expand All @@ -25,3 +28,26 @@ def function_occupancy_info(logs: Iterable[Block]) -> List[int]:
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


def raw_main(argv: List[str] = []):
parser = argparse.ArgumentParser(
description='Computes the block stats for the logs')
parser.add_argument('--stat', required=True, choices=('occ',),
help='Which stat to compute')
parser.add_argument('logs', help='The logs to analyze')
ioutils.add_output_format_arg(parser)
args = analyze.parse_args(parser, 'logs')

STATS = {
'occ': ('Average Occupancy', avg_occupancy),
}
label, f = STATS[args.stat]

results = utils.foreach_bench(lambda bench: {label: f(bench)}, args.logs)

args.format(sys.stdout, results)


if __name__ == '__main__':
raw_main(sys.argv)

0 comments on commit da627e1

Please sign in to comment.