Skip to content

Commit da627e1

Browse files
committed
Add main function to func_stats
1 parent 0976ac6 commit da627e1

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

util/analyze/lib/block_stats.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,4 @@ def compute_block_stats(logs: Logs):
8888

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

91-
args.format(result)
91+
args.format(results)

util/analyze/lib/func_stats.py

100644100755
Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
#!/usr/bin/env python3
22

3+
import argparse
34
import re
5+
import sys
46
from itertools import chain
57
from typing import Iterable, List
68

7-
from analyze import Block
9+
import analyze
10+
from analyze import Block, ioutils, utils
811

912
'''
1013
Function-level stats (not Block, Logs, or Benchmark level)
@@ -25,3 +28,26 @@ def function_occupancy_info(logs: Iterable[Block]) -> List[int]:
2528
def avg_occupancy(logs: Iterable[Block]) -> float:
2629
occ_info = function_occupancy_info(logs)
2730
return sum(occ_info) / len(occ_info) if occ_info else 0.0
31+
32+
33+
def raw_main(argv: List[str] = []):
34+
parser = argparse.ArgumentParser(
35+
description='Computes the block stats for the logs')
36+
parser.add_argument('--stat', required=True, choices=('occ',),
37+
help='Which stat to compute')
38+
parser.add_argument('logs', help='The logs to analyze')
39+
ioutils.add_output_format_arg(parser)
40+
args = analyze.parse_args(parser, 'logs')
41+
42+
STATS = {
43+
'occ': ('Average Occupancy', avg_occupancy),
44+
}
45+
label, f = STATS[args.stat]
46+
47+
results = utils.foreach_bench(lambda bench: {label: f(bench)}, args.logs)
48+
49+
args.format(sys.stdout, results)
50+
51+
52+
if __name__ == '__main__':
53+
raw_main(sys.argv)

0 commit comments

Comments
 (0)