-
Notifications
You must be signed in to change notification settings - Fork 0
/
graphview.py
112 lines (103 loc) · 3.26 KB
/
graphview.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
107
108
109
110
111
112
import argparse
import subprocess
from tracemalloc import start
import numpy as np
import pwlf
from matplotlib import pyplot as plt
parser = argparse.ArgumentParser(description='uperf parameters')
parser.add_argument('-exec', type=str)
parser.add_argument('-case', type=str)
parser.add_argument('-start', type=str)
parser.add_argument('-end', type=str)
parser.add_argument('-step', type=str)
parser.add_argument('-delay', type=str)
parser.add_argument('-prologue', type=str)
parser.add_argument('-epilogue', type=str)
parser.add_argument('-loop', type=str)
parser.add_argument('-inst_num', type=str)
parser.add_argument('-thrput_inst', type=str)
parser.add_argument('-thrput_fill', type=str)
parser.add_argument('-affinity', type=str)
parser.add_argument('-f', type=str)
parser.add_argument('-segments', type=int, default=0)
args = parser.parse_args()
cmd = [args.exec]
if args.case is not None:
cmd.extend(['-case', args.case])
if args.start is not None:
cmd.extend(['-start', args.start])
if args.end is not None:
cmd.extend(['-end', args.end])
if args.step is not None:
cmd.extend(['-step', args.step])
if args.delay is not None:
cmd.extend(['-delay', args.delay])
if args.prologue is not None:
cmd.extend(['-prologue', args.prologue])
if args.epilogue is not None:
cmd.extend(['-epilogue', args.epilogue])
if args.loop is not None:
cmd.extend(['-loop', args.loop])
if args.inst_num is not None:
cmd.extend(['-inst_num', args.inst_num])
if args.thrput_inst is not None:
cmd.extend(['-thrput_inst', args.thrput_inst])
if args.thrput_fill is not None:
cmd.extend(['-thrput_fill', args.thrput_fill])
if args.affinity is not None:
cmd.extend(['-affinity', args.affinity])
if args.f is not None:
cmd.extend(['-f', args.f])
p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
p.wait()
x = []
y = []
starttest = False
list_of_strings = [line.decode('utf-8').rstrip('\n')
for line in iter(p.stdout.readlines())]
for line in list_of_strings:
if line.find('test start:') == 0:
starttest = True
elif starttest == True:
point = line.strip().split(' ')
x.append(int(point[0]))
y.append(float(point[1]))
else:
print(line)
my_pwlf = pwlf.PiecewiseLinFit(x, y)
minli = args.segments
if minli == 0:
minloss = 1000000000000.0
minli = 6
for i in range(1, 6):
my_pwlf.fit(i)
y_fit = my_pwlf.predict(x)
y_delta = y_fit - y
y_deltasum = np.sum(y_delta)
y_delta = y_delta - y_deltasum
loss = np.sqrt(np.sum(np.square(y_delta) / len(y)))
if minloss > loss:
minloss = loss
minli = i
if minloss < 1:
break
res = my_pwlf.fit(minli)
for i in range(0, len(res)-1):
start = res[i]
end = res[i+1]
if end > start:
subx = []
suby = []
for i in range(0, len(x)):
if x[i] >= start and x[i] < end:
subx.append(x[i])
suby.append(y[i])
subx_matrix = np.vstack([subx, np.ones(len(subx))]).T
k = np.linalg.lstsq(subx_matrix, suby, rcond=None)
print("{}->{}, cpi:{}, ipc:{}".format(start,
end, str(k[0][0]), str(1/(k[0][0]+1e-8))))
y_fit = my_pwlf.predict(x)
plt.title(cmd)
plt.plot(x, y)
plt.plot(x, y_fit)
plt.show()