-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgraphcsr.py
97 lines (73 loc) · 2.22 KB
/
graphcsr.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
import argparse
import os
import json
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
parser = argparse.ArgumentParser()
parser.add_argument('path')
parser.add_argument('-g', '--graph', action='store_true')
def plot(times, yvalues, yavg, ylabel):
plt.clf()
plt.figure(figsize=(15, 10))
plt.plot(times, yvalues)
plt.fill_between(times, 0, yvalues, alpha=0.3)
plt.plot([times[0], times[-1]], [yavg] * 2)
plt.xlabel('Time (s)')
plt.ylabel(ylabel)
plt.tight_layout()
basename, _ = os.path.splitext(os.path.basename(args.path))
suffix = ylabel.replace(' ', '')
if args.graph:
plt.savefig(basename + '-' + suffix + '.png')
print(ylabel + ':', yavg)
def calc_ipc(hpm0, hpm1):
cycle = hpm1[0] - hpm0[0]
instret = hpm1[1] - hpm0[1]
return instret / cycle
def calc_br_misp_rate(hpm0, hpm1):
br = hpm1[2] - hpm0[2]
br_misp = hpm1[5] - hpm0[5]
return br_misp / br
def calc_br_mpki(hpm0, hpm1):
instret = hpm1[1] - hpm0[1]
br_misp = hpm1[5] - hpm0[5]
return br_misp / instret * 1000
def parse_file(f):
lineno = 0
last_hpms = None
times = []
ipcs = []
br_misp_rates = []
br_mpkis = []
while True:
line = f.readline()
if not line:
break
line = line.strip()
if not line:
continue
data = json.loads(line)
time = data['time']
hpms = data['hpms']
times.append(time)
if lineno == 0:
first_hpms = hpms
else:
times.append(time)
ipcs.extend([calc_ipc(last_hpms, hpms)] * 2)
br_misp_rates.extend([calc_br_misp_rate(last_hpms, hpms)] * 2)
br_mpkis.extend([calc_br_mpki(last_hpms, hpms)] * 2)
last_hpms = hpms
lineno += 1
times.pop()
ipc_avg = calc_ipc(first_hpms, hpms)
br_misp_rate_avg = calc_br_misp_rate(first_hpms, hpms)
br_mpki_avg = calc_br_mpki(first_hpms, hpms)
plot(times, ipcs, ipc_avg, 'IPC')
plot(times, br_misp_rates, br_misp_rate_avg, 'Br Misp Rate')
plot(times, br_mpkis, br_mpki_avg, 'Br MPKI')
if __name__ == '__main__':
args = parser.parse_args()
with open(args.path) as f:
parse_file(f)