Menu

[22d97c]: / benchmarks / run.py  Maximize  Restore  History

Download this file

406 lines (382 with data), 12.8 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
import os
import re
import sys
import time
import json
import os.path
import subprocess
from collections import namedtuple
class TestProfile(namedtuple("TestProfile", 'target, args, repeat')):
@property
def setup(self): return None
@property
def run_profile(self):
return [self.target] + list(self.args)
@property
def data_file(self):
return self.target
@property
def data_key(self):
return self.run_profile
class CompileProfile(TestProfile):
@property
def run_profile(self):
return ['dac', '-B', self.target]
@property
def data_file(self):
return 'dac'
class CompileIncProfile(TestProfile):
@property
def run_profile(self):
return ['dac', '-B', '-i', self.target]
@property
def data_file(self):
return 'dac_i'
class CProfile(TestProfile): pass
class PyProfile(TestProfile):
@property
def run_profile(self):
return ['python3', self.target] + list(self.args)
class DAProfile(TestProfile):
@property
def setup(self):
dafile, _ = self.target
return ['dac', '-i', dafile]
@property
def run_profile(self):
dafile, incfile = self.target
prof = ['dar', '-i']
if incfile is not None:
prof += ['-m', incfile]
prof.append(dafile)
prof += self.args
return prof
@property
def data_file(self):
dafile, _ = self.target
return dafile
class DALoopProfile(TestProfile):
@property
def setup(self):
return ['dac', self.target]
@property
def run_profile(self):
return ['dar', self.target] + list(self.args)
class ErlProfile(TestProfile):
@property
def run_profile(self):
path_components = self.target.split(os.sep)
mod = path_components[-1]
indir = os.sep.join(path_components[:-1])
return ['erl', '-noshell', '-pa', indir, '-run', mod, 'start'] + \
list(self.args)
targets = [
ErlProfile(
target='lamutex/Erlang/lamutex',
args=(range(25, 150+1, 25), '30'),
repeat=10),
ErlProfile(
target='lamutex/Erlang/lamutex',
args=('10', range(100, 1000+1, 100)),
repeat=10),
DAProfile(
target=('lamutex/orig.da', None),
args=(range(5, 20+1, 2), '5'),
repeat=10),
DAProfile(
target=('lamutex/orig.da', "lamutex_orig_inc_inc"),
args=(range(5, 20+1, 2), '5'),
repeat=10),
DAProfile(
target=('lamutex/orig.da', None),
args=(range(25, 150+1, 25), '5'),
repeat=10),
DAProfile(
target=('lamutex/orig.da', "lamutex_orig_inc_inc"),
args=(range(25, 150+1, 25), '5'),
repeat=10),
DAProfile(
target=('lamutex/orig.da', "orig_inc_invts"),
args=(range(25, 150+1, 25), '5'),
repeat=10),
DAProfile(
target=('lamutex/orig.da', None),
args=('10', range(100, 1000+1, 100)),
repeat=5),
DAProfile(
target=('lamutex/orig.da', "lamutex_orig_inc_inc"),
args=('10', range(100, 1000+1, 100)),
repeat=5),
DAProfile(
target=('lamutex/orig.da', "orig_inc_invts"),
args=('10', range(100, 1000+1, 100)),
repeat=5),
DAProfile(
target=('lamutex/spec.da', None),
args=(range(5, 20+1, 2), '5'),
repeat=10),
# --------------------------------------------------
CProfile(
target='lamutex/C/lamport',
args=(range(25, 150+1, 25), '5'),
repeat=10),
CProfile(
target='lamutex/C/lamport',
args=(range(25, 150+1, 25), '30'),
repeat=10),
CProfile(
target='lamutex/C/lamport',
args=('10', range(100, 1000+1, 100)),
repeat=10),
PyProfile(
target='lamutex/Python/lamutex.py',
args=('10', range(100, 1000+1, 100)),
repeat=5),
PyProfile(
target='lamutex/Python/lamutex.py',
args=('5', range(10, 100+1, 10)),
repeat=5),
PyProfile(
target='lamutex/Python/lamutex.py',
args=(range(5, 20+1, 2), '5'),
repeat=10),
PyProfile(
target='lamutex/Python/lamutex.py',
args=(range(15, 150+1, 20), '5'),
repeat=10),
PyProfile(
target='lamutex/Python/lamutex.py',
args=(range(25, 150+1, 25), '5'),
repeat=10),
# ==================================================
DALoopProfile(
target='lamutex/orig.da',
args=(range(25, 150+1, 25), '5'),
repeat=10),
DALoopProfile(
target='lamutex/orig.da',
args=('10', range(100, 1000+1, 100)),
repeat=10),
# --------------------------------------------------
DAProfile(
target=('lamutex/spec.da', "spec_inc_inc"),
args=(range(5, 20+1, 2), '5'),
repeat=10),
DAProfile(
target=('lamutex/spec.da', None),
args=(range(15, 150+1, 20), '5'),
repeat=10),
DAProfile(
target=('lamutex/spec.da', None),
args=(range(25, 150+1, 25), '5'),
repeat=10),
DAProfile(
target=('lamutex/spec.da', "spec_inc_inc"),
args=(range(15, 150+1, 20), '5'),
repeat=10),
DAProfile(
target=('lamutex/spec.da', "spec_inc_inc"),
args=(range(25, 150+1, 25), '5'),
repeat=10),
DAProfile(
target=('lamutex/spec.da', None),
args=('5', range(10, 100+1, 10)),
repeat=5),
# DAProfile(
# target=('lamutex/spec.da', None),
# args=('5', range(100, 1000+1, 100)),
# repeat=5),
DAProfile(
target=('lamutex/spec.da', "spec_inc_inc"),
args=('5', range(10, 100+1, 10)),
repeat=5),
DAProfile(
target=('lamutex/spec.da', "spec_inc_inc"),
args=('5', range(100, 1000+1, 100)),
repeat=5),
# ==================================================
# DAProfile(
# target=('2pcommit/spec.da', None),
# args=(range(5, 20+1, 2), '0'),
# repeat=10),
# DAProfile(
# target=('2pcommit/spec.da', "tpcommit_inc_inc"),
# args=(range(5, 20+1, 2), '0'),
# repeat=10),
DAProfile(
target=('2pcommit/spec.da', None),
args=(range(25, 150+1, 25), '0'),
repeat=10),
DAProfile(
target=('2pcommit/spec.da', "tpcommit_inc_inc"),
args=(range(25, 150+1, 25), '0'),
repeat=10),
DALoopProfile(
target='2pcommit/spec.da',
args=(range(25, 150+1, 25), '0'),
repeat=10),
# ==================================================
DAProfile(
target=('clpaxos/spec.da', None),
args=(range(5, 20+1, 2), '5'),
repeat=10),
DAProfile(
target=('clpaxos/spec.da', "clpaxos_inc_inc"),
args=(range(5, 20+1, 2), '5'),
repeat=10),
# ==================================================
DAProfile(
target=('lapaxos/orig.da', None),
args=('5', range(25, 150+1, 25)),
repeat=10),
DAProfile(
target=('lapaxos/orig.da', "lapaxos_inc_inc"),
args=('5', range(25, 150+1, 25)),
repeat=10),
DAProfile(
target=('lapaxos/orig.da', "lapaxos_inc_dem"),
args=('5', range(25, 150+1, 25)),
repeat=10),
DALoopProfile(
target='lapaxos/orig.da',
args=('5', range(25, 150+1, 25)),
repeat=10)
# DAProfile(
# target=('clpaxos/spec.da', None),
# args=('10', range(25, 150+1, 25)),
# repeat=10),
# DAProfile(
# target=('clpaxos/oopsla.da', None),
# args=('10', range(25, 150+1, 25)),
# repeat=10),
# DAProfile(
# target=('clpaxos/oopsla.da', "oopsla_inc_inc"),
# args=('10', range(25, 150+1, 25)),
# repeat=10),
# DAProfile(
# target=('clpaxos/spec.da', "clpaxos_inc_inc"),
# args=('10', range(25, 150+1, 25)),
# repeat=10),
# DAProfile(
# target=('clpaxos/spec.da', None),
# args=('5', '10', range(5, 20+1, 2)),
# repeat=10),
# DAProfile(
# target=('clpaxos/spec.da', "clpaxos_inc_inc"),
# args=('5', '10', range(5, 20+1, 2)),
# repeat=10),
]
compile_targets = [
"../examples/vrpaxos/orig.da",
"../examples/crleader/orig.da",
"../examples/dscrash/orig.da",
"../examples/dscrash/spec.da",
"../examples/ratoken/spec.da",
"../examples/raft/orig.da",
"../examples/lamutex/orig.da",
"../examples/lamutex/spec.da",
"../examples/pingpong/ping.da",
"../examples/hsleader/orig.da",
"../examples/ramutex/orig.da",
"../examples/sktoken/orig.da",
"../examples/clpaxos/spec.da",
"../examples/lapaxos/orig.da",
"../examples/2pcommit/orig.da",
]
for ct in compile_targets:
targets.append(CompileProfile(target=ct, args=None, repeat=10))
targets.append(CompileIncProfile(target=ct, args=None, repeat=10))
class DistAlgoError(subprocess.CalledProcessError):
def __str__(self):
return ('Command {} returned non-zero exit status {}\n'
'stderr output:\n{}'.format(
self.cmd, self.returncode, self.output))
def parse_output(s):
"""Parse a string of standard output text for the "OUTPUT: <JSON>"
line and return the parsed JSON object.
"""
m = re.search(r'^###OUTPUT: (.*)', s, re.MULTILINE)
if m is None:
return None
return json.loads(m.group(1))
# Adapted from IncOQ:
def launch(run_args):
"""Launch the specified run profile in a subprocess that
captures/parses standard output and error. Return a JSON object
obtained by parsing stdout for a line "OUTPUT: <JSON>", where
<JSON> is JSON-encoded data.
"""
child = subprocess.Popen(
run_args, bufsize=-1,
# To debug, comment out this line to make stdout/stderr
# the same standard out and error streams as the parent.
# Alternatively (if the process terminates), uncomment
# the print statements below.
# In the future, maybe use something like
# http://stackoverflow.com/questions/375427/non-blocking-read-on-a-subprocess-pipe-in-python
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
#cwd=dirname,
#env=env,
universal_newlines=True)
stdout, stderr = child.communicate()
# print(stderr)
# print(stdout)
if child.returncode != 0:
raise subprocess.CalledProcessError(child.returncode, run_args, stderr)
results = parse_output(stdout)
return results
def run_all_tests(resultsdir):
for config in targets:
expanded = []
resultsfile = os.path.join(resultsdir,
config.data_file.replace('/', '_') + '.json')
varidx = varange = None
try:
with open(resultsfile, "r") as rf:
results = json.load(rf)
if isinstance(results, list):
print("Found existing results.")
else:
print("ERROR: results corrupted!", file=sys.stderr)
exit(1)
except Exception as e:
results = []
# Expand arg ranges
for idx, param in enumerate(config.run_profile):
if isinstance(param, range):
varidx = idx
varange = param
# Only support one range parameter
break
if varidx is not None:
arglist = config.run_profile
for n in varange:
arglist[varidx] = str(n)
expanded.append(list(arglist))
else:
expanded.append(config.run_profile)
need_setup = config.setup
for item in expanded:
existing = len([(config, res, ts)
for config, res, ts in results if config == item])
if existing > 0:
print("** Found %d results for %r" % (existing, item))
if config.repeat > existing and need_setup:
launch(need_setup)
need_setup = None
for i in range(existing, config.repeat):
print("> Running iteration %d for %r" % (i, item))
results.append((item, launch(item), time.time()))
# Save right away:
with open(resultsfile, "w") as wf:
json.dump(results, wf)
def main():
output_dir = sys.argv[1] if len(sys.argv) > 1 else "results"
if not os.path.exists(output_dir):
os.mkdir(output_dir)
if not os.path.isdir(output_dir):
sys.stderr.write("Error: %s is not a directory!" % output_dir)
exit(1)
run_all_tests(output_dir)
if __name__ == "__main__":
main()
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.