-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy path_reproduce.py
142 lines (126 loc) · 3.18 KB
/
_reproduce.py
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
#!/usr/bin/env python3
import subprocess
from collections import namedtuple
from pathlib import Path
import json
import datetime
# (Run experiments once to save time)
TIMEOUT = 60 # 60s
LIMIT = 0.1 # display "<0.1s" for negligible time
RUN = 1 # run = 10 in the experiments
Subject = namedtuple('Subject', 'name configs')
# Same as Table 2
SUBJECTS = [
Subject(
'fork-buf',
configs=[
'N=1',
'N=2',
'N=3',
]
),
Subject(
'cond-var',
configs=[
'N=1; T_p=1; T_c=1',
'N=1; T_p=1; T_c=2',
'N=2; T_p=1; T_c=2',
'N=2; T_p=2; T_c=1',
]
),
Subject(
'xv6-log',
configs=[
'N=2',
'N=4',
'N=8',
'N=10',
]
),
Subject(
'tocttou',
configs=[
'P=2',
'P=3',
'P=4',
'P=5',
]
),
Subject(
'parallel-inc',
configs=[
'N=1; T=2',
'N=2; T=2',
'N=2; T=3',
'N=3; T=3',
]
),
Subject(
'fs-crash',
configs=[
'N=2',
'N=4',
'N=8',
'N=10',
]
),
]
def run(conf, src, n=RUN):
src = conf + '\n\n' + src
PROFILING = '''
import atexit, psutil, sys
def mem():
import os
process = psutil.Process(os.getpid())
mem_info = process.memory_info()
print(mem_info.rss, file=sys.stderr)
atexit.register(mem)
'''
def run_once(src, profiling=False):
if profiling:
src = PROFILING + src
p = subprocess.run(
['python3', 'mosaic.py', '--check', '/dev/stdin'],
input=src.encode(),
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
timeout=TIMEOUT
)
assert p.returncode == 0
return p
# First run, for warm up and memory statistics
p = run_once(src, profiling=True)
G = json.loads(p.stdout)
V = G['vertices']
mem = int(p.stderr) / 1024 / 1024
size, times = len(V), []
# Repeated runs
for _ in range(n):
t1 = datetime.datetime.now()
run_once(src, profiling=False)
t2 = datetime.datetime.now()
runtime = (t2 - t1).total_seconds()
times.append(runtime)
return (size, mem, times)
def evaluate(subj):
src = Path(__file__).parent \
.glob(f'**/{subj.name}.py').__next__() \
.read_text()
LOC = len(src.strip().splitlines())
print(f' {subj.name} ({LOC} LOC) '.center(62, '-'))
for conf in subj.configs:
try:
states, mem, ts = run(conf, src)
avg = sum(ts) / len(ts)
per = int(states / avg)
if avg < LIMIT:
time_text = f'<{LIMIT}s'
else:
time_text = f'{avg:.1f}s ({per} st/s)'
except subprocess.TimeoutExpired:
time_text = f'Timeout (>{TIMEOUT}s)'
print(f'{conf:>20}{time_text:>42}')
else:
print(f'{conf:>20}{states:>10}{time_text:>20}{mem:>10.2f}MB')
for _, subj in enumerate(SUBJECTS):
evaluate(subj)