forked from score-p/scorep_binding_python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbenchmark_helper.py
More file actions
55 lines (46 loc) · 1.55 KB
/
benchmark_helper.py
File metadata and controls
55 lines (46 loc) · 1.55 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
import subprocess
import os
import shutil
import sys
import time
class BenchmarkEnv():
def __init__(self, repetitions=10):
self.env = os.environ.copy()
self.env["SCOREP_ENABLE_PROFILING"] = "false"
self.env["SCOREP_ENABLE_TRACING"] = "false"
self.env["SCOREP_PROFILING_MAX_CALLPATH_DEPTH"] = "98"
self.env["SCOREP_TOTAL_MEMORY"] = "3G"
self.exp_dir = "benchmark_dir"
self.repetitions = repetitions
shutil.rmtree(
self.exp_dir,
ignore_errors=True)
os.mkdir(self.exp_dir)
def __del__(self):
pass
# shutil.rmtree(
# self.exp_dir,
# ignore_errors=True)
def call(self, script="", ops=[], enable_scorep=True, scorep_settings=[]):
self.env["SCOREP_EXPERIMENT_DIRECTORY"] = self.exp_dir + \
"/{}-{}-{}".format(script, ops, scorep_settings)
arguments = [sys.executable]
if enable_scorep:
arguments.extend(["-m", "scorep"])
arguments.extend(scorep_settings)
arguments.append(script)
arguments.extend(ops)
runtimes = []
for i in range(self.repetitions):
begin = time.time()
print(arguments)
out = subprocess.run(
arguments,
env=self.env,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
end = time.time()
assert(out.returncode == 0)
runtime = end - begin
runtimes.append(runtime)
return runtimes