forked from jschaub30/pid_monitor
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcreate_summary_table.py
executable file
·106 lines (93 loc) · 3.02 KB
/
create_summary_table.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
#!/usr/bin/python
'''
Input: config.json file
Output: HTML summary as "summary.html" in same directory as config.json
Summarize /usr/bin/time data from all runs into HTML table
Jeremy Schaub
$ ./create_summary_tables.py $RUNDIR/html/config.json
'''
import sys
import os
import json
import tidy.timeread
import re
def create_table(config_fn):
'''
Read run_id's from config_fn
config_fn is a json file with these fields:
'run_ids' <-- a list
'data_dir' <-- a string
'stdout_ext' <-- a string
'stderr_ext' <-- a string
'time_ext' <-- a string
Example contents of config_fn:
{
'data_dir': '../data/raw',
'stdout_ext': '.workload.stdout',
'stderr_ext': '.workload.stderr',
'time_ext': '.time'
'run_ids': ['RUN1', 'RUN2'],
}
The output of /usr/bin/time should be in:
../data/raw/RUN1.time
../data/raw/RUN2.time
The stdout files should be in:
../data/raw/RUN1.workload.stdout
../data/raw/RUN2.workload.stdout
and similar for stderr
Write summary.html in same directory as config_fn
'''
os.chdir(os.path.dirname(config_fn))
config_fn = os.path.basename(config_fn)
with open(config_fn, 'r') as fid:
blob = fid.read()
config = json.loads(blob)
ids = config['run_ids']
html_rows = []
csv_rows = []
fields = ['run_id', 'count', 'min_sec', 'median_sec', 'max_sec', 'spark_event_log']
csv_fields = ['run_id', 'count', 'median_sec']
run_ids = dict()
ids_in_order = []
for run_id in ids:
m = re.search("^(.*)-ITER([0-9]*)", run_id)
if m.groups(0)[0] in run_ids:
run_ids[m.groups(0)[0]] += 1
else:
run_ids[m.groups(0)[0]] = 1
ids_in_order.append(m.groups(0)[0])
for run_id in ids_in_order:
meas = time_measurement(run_id, run_ids[run_id], config=config)
html_rows.append(meas.rowhtml(fields=fields))
csv_rows.append(meas.rowcsv(fields=csv_fields))
table = html_table(fields, html_rows)
sys.stdout.write(table)
header = meas.headercsv(fields=csv_fields)
table = csv_table(header, csv_rows)
with open('summary.csv', 'w') as fid:
fid.write(table)
def html_table(fields, rows):
header_row = '<tr>\n<th>%s</th>\n</tr>\n' % ('</th>\n<th>'.join(fields))
table = '<table>\n' + header_row
for row in rows:
table += row
table += '</table>\n'
return table
def csv_table(header, rows):
table = header + '\n'
for row in rows:
table += row
return table
def time_measurement(run_id, run_count, config=None):
'''
Create a measurement instance that summarizes the run
Add fields that link to the time, stdout and stderr files
'''
data_dir = config['data_dir']
time_fn = os.path.join(data_dir, run_id + config['time_ext'])
meas = tidy.timeread.TimeMeasurement()
meas.parse(time_fn, run_id, run_count)
meas.addfield('run_id', run_id)
return meas
if __name__ == '__main__':
create_table(sys.argv[1])