-
Notifications
You must be signed in to change notification settings - Fork 1
/
summarize.py
125 lines (109 loc) · 3.7 KB
/
summarize.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
113
114
115
116
117
118
119
120
121
122
123
124
125
import os
import copy
import json
configs = ['bimodal next_line bingo bingo bingo lru 1',
'bimodal next_line bingo_new bingo bingo lru 1']
simulation = 10
bandwidths = {}
bandwidths[configs[0]] = list(range(2, 33, 2))
bandwidths[configs[1]] = [2]
trace_dir = ''
caches = ['L1D', 'L1I', 'L2C', 'LLC']
basedict = {
'IPC': {},
'L1D': {
'USEFUL': {},
'USELESS': {},
'MISSES': {},
'ACCURACY': {},
'COVERAGE': {},
'MISS LATENCY': {}
},
'L1I': {
'USEFUL': {},
'USELESS': {},
'MISSES': {},
'ACCURACY': {},
'COVERAGE': {},
'MISS LATENCY': {}
},
'L2C': {
'USEFUL': {},
'USELESS': {},
'MISSES': {},
'ACCURACY': {},
'COVERAGE': {},
'MISS LATENCY': {}
},
'LLC': {
'USEFUL': {},
'USELESS': {},
'MISSES': {},
'ACCURACY': {},
'COVERAGE': {},
'MISS LATENCY': {}
},
}
def extract(file, summary, bandwidth):
with open(file, 'r') as f:
cache_index = 0
cache = caches[cache_index]
misses = 0
for line in f:
content = line.split()
if line.startswith('CPU 0 cumulative IPC'):
summary['IPC'][bandwidth] = float(content[4])
continue
if line.startswith(f'{cache} LOAD ACCESS'):
misses += float(content[-1])
continue
if line.startswith(f'{cache} RFO ACCESS'):
misses += float(content[-1])
continue
if line.startswith(f'{cache} PREFETCH REQUESTED'):
useful = float(content[-3])
useless = float(content[-1])
try:
accuracy = useful / (useful + useless)
except Exception:
accuracy = float("nan")
try:
coverage = useful / (useful + misses)
except Exception:
coverage = float("nan")
summary[cache]['USEFUL'][bandwidth] = int(useful)
summary[cache]['USELESS'][bandwidth] = int(useless)
summary[cache]['MISSES'][bandwidth] = int(misses)
summary[cache]['ACCURACY'][bandwidth] = accuracy
summary[cache]['COVERAGE'][bandwidth] = coverage
continue
if line.startswith(f'{cache} AVERAGE MISS LATENCY'):
try:
latency = float(content[4])
except Exception:
coverage = float("nan")
summary[cache]['MISS LATENCY'][bandwidth] = latency
cache_index += 1
if cache_index == 4:
break
cache = caches[cache_index]
misses = 0
if __name__ == '__main__':
files = os.listdir('../../dpc3_traces/{}'.format(trace_dir))
files.sort()
for file in files:
if not file.startswith("server"):
continue
json_file = 'summary/{}.json'.format(file)
data = {}
for config in configs:
data[config] = copy.deepcopy(basedict)
executable = '{}core'.format(config.replace(' ', '-'))
for bandwidth in bandwidths[config]:
data_file = 'results/{}M_{}B/{}-{}.txt'.format(simulation,
bandwidth,
file,
executable)
extract(data_file, data[config], bandwidth*100)
with open(json_file, 'w') as f:
json.dump(data, f, indent=4)