-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrun.py
88 lines (69 loc) · 2.88 KB
/
run.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import glob
import inquirer
import subprocess
import pandas as pd
import numpy as np
import re
F_DIR = os.path.dirname(os.path.realpath(__file__))
CONTRACT_DIR = os.path.join(F_DIR, 'contracts')
SCRIPT_DIR = os.path.join(F_DIR, 'scripts')
candidates = [x.split('.')[0].split('/')[-1] for x in filter(lambda x: x.count('_') == 1, glob.glob(os.path.join(CONTRACT_DIR, '*.sol')))]
questions = [
inquirer.List('contract',
message='Which contract to deploy?',
choices=candidates
),
inquirer.List('type',
message='Which type of Instrumentation?',
choices=['Origin', 'Solythesis', 'Baseline']
),
inquirer.List("exp", message='Which type of experiment to run?',
choices=['CPU/Disk Usage (6.2)', 'Transaction Per Second (6.3)'],
),
inquirer.Text('blocks',
message='How many blocks to generate? (Note that it may take excessive amount of time to generate large amount of blocks (>500).)',
validate=lambda _, x: x.strip().isnumeric()
)
]
configs = inquirer.prompt(questions)
suffix_mapping = {
'Origin': "",
"Solythesis": "_Solythesis",
"Baseline": "_baseline"
}
contract_name = configs['contract'] + suffix_mapping[configs['type']] + ".sol"
contract = os.path.join(CONTRACT_DIR, contract_name)
script = os.path.join(SCRIPT_DIR, 'replay_' + configs['contract'].split("_")[-1].lower() + '.py')
if 'Transaction' in configs['exp']:
shell = F_DIR + '/bash/run_tps_exp.sh'
else:
shell = F_DIR + '/bash/run_cpu_exp.sh'
print(shell)
subprocess.call(['bash', shell, contract, script, configs['blocks']])
print("Done!")
print("Experiment: " + configs['exp'])
print("Contract: " + configs['contract'])
print("Instrumentation Type: " + configs['type'])
if 'Transaction' in configs['exp']:
with open("/home/ubuntu/results/{}-{}.log".format(contract_name, configs['blocks'])) as f:
for line in f:
result = re.findall(r"Import completed in .+ (\d+) tx/s", line)
if result:
tps = result[0]
break
print("TPS: {} tx/s".format(tps))
else:
with open("/home/ubuntu/results/{}-{}.db.txt".format(contract_name, configs['blocks'])) as f:
for line in f:
result = re.findall(r"rocksdb\.bytes\.written COUNT : (\d*)", line)
if result:
writes = int(result[0]) / 1024 / 1024 / int(configs['blocks']) / 10
break
print("DB Writes: {} MB/s".format(writes))
res = pd.read_csv("/home/ubuntu/results/{}-{}.cpu.txt".format(contract_name, configs['blocks']), sep="\s+", header=None, dtype=np.float64, skiprows=1)
res = res[[1]]
mean = np.mean(res).values[0]
print("Average CPU Usage: {}%".format(mean))