-
Notifications
You must be signed in to change notification settings - Fork 2
/
logger.py
68 lines (51 loc) · 1.75 KB
/
logger.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
import json
import numpy as np
def extract_meter_values(meters, std=False):
ret = { }
for split in meters.keys():
ret[split] = { }
for field,meter in meters[split].items():
if std:
ret[split][field] = meter.value()
else:
ret[split][field] = meter.value()[0]
return ret
def render_meter_values(meter_values, N=1):
field_info = []
for split in meter_values.keys():
for field,val in meter_values[split].items():
if type(val) is tuple:
field_info.append("{:s} {:s} = ({:0.3f},{:0.3f})".format(split, field, val[0], 1.96 * val[1] / N))
else:
field_info.append("{:s} {:s} = {:0.6f}".format(split, field, val))
return ', '.join(field_info)
def convert_array(d):
ret = { }
for k,v in d.items():
if isinstance(v, dict):
ret[k] = { }
for kk,vv in v.items():
ret[k][kk] = np.array(vv)
else:
ret[k] = np.array(v)
return ret
def load_trace(trace_file):
ret = { }
with open(trace_file, 'r') as f:
for i,line in enumerate(f):
vals = json.loads(line.rstrip('\n'))
if i == 0:
for k,v in vals.items():
if isinstance(v, dict):
ret[k] = { }
for kk in v.keys():
ret[k][kk] = []
else:
ret[k] = []
for k,v in vals.items():
if isinstance(v, dict):
for kk,vv in v.items():
ret[k][kk].append(vv)
else:
ret[k].append(v)
return convert_array(ret)