10
10
import yaml
11
11
from running .suite import is_dry_run
12
12
from collections import defaultdict
13
+ from enum import Enum
13
14
14
15
configuration : Configuration
15
16
@@ -19,9 +20,39 @@ def setup_parser(subparsers):
19
20
f .set_defaults (which = "minheap" )
20
21
f .add_argument ("CONFIG" , type = Path )
21
22
f .add_argument ("RESULT" , type = Path )
23
+ f .add_argument ("-r" , "--retries" , type = int )
22
24
23
25
24
- def minheap_one_bm (suite : JavaBenchmarkSuite , runtime : Runtime , bm : JavaBenchmark , heap : int , minheap_dir : Path ) -> float :
26
+ class RunResult (Enum ):
27
+ Passed = 1
28
+ FailedWithOOM = 2
29
+ Failed = 3
30
+
31
+ def is_passed (self ) -> bool :
32
+ return self == RunResult .Passed
33
+
34
+
35
+ def run_bm_with_retry (suite : JavaBenchmarkSuite , runtime : Runtime , bm_with_heapsize : JavaBenchmark , minheap_dir : Path , retries : int ) -> RunResult :
36
+ def log (s ):
37
+ return print (s , end = "" , flush = True )
38
+
39
+ log (" " )
40
+ for _ in range (retries ):
41
+ output , _ = bm_with_heapsize .run (runtime , cwd = minheap_dir )
42
+ if suite .is_passed (output ):
43
+ log ("o " )
44
+ return RunResult .Passed
45
+ elif suite .is_oom (output ):
46
+ log ("x " )
47
+ return RunResult .FailedWithOOM
48
+ else :
49
+ log ("." )
50
+ continue
51
+ log (" " )
52
+ return RunResult .Failed
53
+
54
+
55
+ def minheap_one_bm (suite : JavaBenchmarkSuite , runtime : Runtime , bm : JavaBenchmark , heap : int , minheap_dir : Path , retries : int ) -> float :
25
56
lo = 2
26
57
hi = heap
27
58
mid = (lo + hi ) // 2
@@ -31,24 +62,19 @@ def minheap_one_bm(suite: JavaBenchmarkSuite, runtime: Runtime, bm: JavaBenchmar
31
62
size_str = "{}M" .format (mid )
32
63
print (size_str , end = "" , flush = True )
33
64
bm_with_heapsize = bm .attach_modifiers ([heapsize ])
34
- output , _ = bm_with_heapsize .run (
35
- runtime , cwd = minheap_dir )
36
- if suite .is_passed (output ):
37
- print (" o " , end = "" , flush = True )
65
+ result = run_bm_with_retry (
66
+ suite , runtime , bm_with_heapsize , minheap_dir , retries )
67
+ if result .is_passed ():
38
68
minh = mid
39
69
hi = mid
40
70
mid = (lo + hi ) // 2
41
71
else :
42
- if suite .is_oom (output ):
43
- print (" x " , end = "" , flush = True )
44
- else :
45
- print (" ? " , end = "" , flush = True )
46
72
lo = mid
47
73
mid = (lo + hi ) // 2
48
74
return minh
49
75
50
76
51
- def run_with_persistence (result : Dict [str , Any ], minheap_dir : Path , result_file : Optional [Path ]):
77
+ def run_with_persistence (result : Dict [str , Any ], minheap_dir : Path , result_file : Optional [Path ], retries : int ):
52
78
suites = configuration .get ("suites" )
53
79
maxheap = configuration .get ("maxheap" )
54
80
for c in configuration .get ("configs" ):
@@ -72,7 +98,7 @@ def run_with_persistence(result: Dict[str, Any], minheap_dir: Path, result_file:
72
98
print ("\t {}-{} " .format (b .suite_name , b .name ), end = "" )
73
99
mod_b = b .attach_modifiers (mods )
74
100
minheap = minheap_one_bm (
75
- suite , runtime , mod_b , maxheap , minheap_dir )
101
+ suite , runtime , mod_b , maxheap , minheap_dir , retries )
76
102
print ("minheap {}" .format (minheap ))
77
103
result [c_encoded ][suite_name ][b .name ] = minheap
78
104
if result_file :
@@ -98,11 +124,12 @@ def print_best(result: Dict[str, Dict[str, Dict[str, float]]]):
98
124
for benchmark , best_config in benchmark_configs .items ():
99
125
config_best_count [best_config ] += 1
100
126
101
- config , count = max (config_best_count .items (), key = lambda x : x [1 ])
102
- print ("{} obtained the most number of smallest minheap sizes: {}" .format (
103
- config , count ))
104
- print ("Minheap configuration to be copied to runbms config files" )
105
- print (yaml .dump (result [config ]))
127
+ if config_best_count .items ():
128
+ config , count = max (config_best_count .items (), key = lambda x : x [1 ])
129
+ print ("{} obtained the most number of smallest minheap sizes: {}" .format (
130
+ config , count ))
131
+ print ("Minheap configuration to be copied to runbms config files" )
132
+ print (yaml .dump (result [config ]))
106
133
107
134
108
135
def run (args ):
@@ -119,11 +146,14 @@ def run(args):
119
146
result = {}
120
147
else :
121
148
result = {}
149
+ retries = configuration .get ("retries" )
150
+ if args .get ("retries" ):
151
+ retries = args .get ("retries" )
122
152
with tempfile .TemporaryDirectory (prefix = "minheap-" ) as minheap_dir :
123
153
logging .info ("Temporary directory: {}" .format (minheap_dir ))
124
154
if is_dry_run ():
125
- run_with_persistence (result , minheap_dir , None )
155
+ run_with_persistence (result , minheap_dir , None , retries )
126
156
else :
127
- run_with_persistence (result , minheap_dir , result_file )
157
+ run_with_persistence (result , minheap_dir , result_file , retries )
128
158
print_best (result )
129
159
return True
0 commit comments