Skip to content

Commit 943c545

Browse files
committed
Save
1 parent 2c1fec5 commit 943c545

File tree

4 files changed

+270
-605
lines changed

4 files changed

+270
-605
lines changed

Diff for: bench.py

+99-3
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,89 @@
2020
import sys
2121
import timeit
2222
import re
23+
import platform
24+
import hashlib
25+
import os
26+
import subprocess
2327

2428
import numpy as np
2529
import sklearn
2630

31+
def check_for_linux():
32+
return platform.system() == 'Linux'
33+
34+
def detect_stage(func):
35+
func = str(func)
36+
#print('##', func)
37+
if '.fit' in func or 'train_test_split' in func:
38+
return 'fit'
39+
elif '.predict' in func:
40+
return 'predict'
41+
elif '.transform' in func:
42+
return 'transform'
43+
else:
44+
print('*' * 100)
45+
raise Exception(f'Unknown stage in detect_stage(). String: {func}')
46+
47+
def prepare_output_dir(func, params):
48+
outdir = os.path.join('analysis_'+params.timestamp, 'case_'+params.hash)
49+
os.makedirs(outdir, exist_ok=True)
50+
return outdir
51+
52+
def start_ittpy_domain(func):
53+
import itt
54+
str_name = str(func)
55+
domain = itt.domain_create(str_name)
56+
itt.task_begin(domain, str_name)
57+
return domain
58+
59+
def finish_ittpy_domain(domain):
60+
import itt
61+
itt.task_end(domain)
62+
63+
def start_memory_analysis(outdir):
64+
current_proc_id = os.getpid()
65+
result_filename = 'psrecord_result'
66+
result_filename_log = os.join(outdir, result_filename+'.txt')
67+
result_filename_image = os.join(outdir, result_filename+'.png')
68+
command = f'psrecord {current_proc_id} --log {result_filename_log} --plot {result_filename_image}'
69+
subprocess.Popen(command.split(' '))
70+
# return res.stdout[:-1], res.stderr[:-1]
71+
72+
def stop_memory_analysis(outdir):
73+
pass
74+
75+
def start_emon(outdir):
76+
pass
77+
78+
def stop_emon(outdir):
79+
80+
81+
def prerun(func, params):
82+
if not check_for_linux():
83+
return
84+
prerun_result = {}
85+
if params.emon == 'True' or params.memory_analysis == 'True':
86+
outdir = prepare_output_dir(func, params)
87+
prerun_result['outdir'] = outdir
88+
if params.ittpy == 'True':
89+
domain = start_ittpy_domain()
90+
prerun_result['domain'] = domain
91+
if params.memory_analysis == 'True':
92+
start_memory_analysis(outdir)
93+
if params.emon == 'True':
94+
start_emon(outdir)
95+
return outdir
96+
97+
def postrun(func, params, outdir):
98+
if not check_for_linux():
99+
return
100+
if params.ittpy == 'True':
101+
finish_ittpy_domain()
102+
if params.memory_analysis == 'True':
103+
stop_memory_analysis(outdir)
104+
if params.emon == 'True':
105+
stop_emon(outdir)
27106

28107
def get_dtype(data):
29108
'''
@@ -186,6 +265,13 @@ def parse_args(parser, size=None, loop_types=(),
186265
parser.add_argument('--device', default='none', type=str,
187266
choices=('host', 'cpu', 'gpu', 'none'),
188267
help='Execution context device')
268+
parser.add_argument('--emon', default='False', type=str,
269+
choices=('True', 'False'),
270+
help='Should emon profiling be started')
271+
parser.add_argument('--hash', default='0', type=str,
272+
help='Hash of current case')
273+
parser.add_argument('--timestamp', default='0', type=str,
274+
help='Timestamp of start benchmarking')
189275

190276
for data in ['X', 'y']:
191277
for stage in ['train', 'test']:
@@ -271,16 +357,26 @@ def prepare_daal_threads(num_threads=-1):
271357

272358
return num_threads
273359

274-
275360
def measure_function_time(func, *args, params, **kwargs):
276-
return time_box_filter(func, *args,
361+
# print('*************')
362+
# print(str(func))
363+
# print(args)
364+
# print(params)
365+
# print(kwargs)
366+
# print('*************')
367+
368+
#meta = detect_meta()
369+
outdir = prerun(func, params)
370+
results = time_box_filter(func, *args,
277371
n_meas=params.box_filter_measurements,
278372
time_limit=params.time_limit, **kwargs)
373+
postrun(func, params, outdir)
374+
return results
279375

280376

281377
def time_box_filter(func, *args, n_meas, time_limit, **kwargs):
282378
times = []
283-
while len(times) < n_meas:
379+
while len(times) < 1:
284380
t0 = timeit.default_timer()
285381
val = func(*args, **kwargs)
286382
t1 = timeit.default_timer()

0 commit comments

Comments
 (0)