-
Notifications
You must be signed in to change notification settings - Fork 1
/
datfiles.go
203 lines (168 loc) · 5.31 KB
/
datfiles.go
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
package main
import (
"io/ioutil"
"sort"
"strconv"
"github.com/jbreitbart/coBench/commands"
"github.com/jbreitbart/coBench/stats"
log "github.com/sirupsen/logrus"
)
func sortedKeys(r *map[int]stats.RuntimeT) []int {
var sortedKeys []int
for k := range *r {
sortedKeys = append(sortedKeys, k)
}
sort.Slice(sortedKeys[:], func(i, j int) bool {
return sortedKeys[i] < sortedKeys[j]
})
return sortedKeys
}
func createCoSchedCATDatFiles(pairs [][2]string, matchpairs bool) ([]string, []string) {
log.WithField("paired", matchpairs).Infoln("Creating dat files for co-scheduling CAT runs")
ret := make([]string, 0)
perfName := make([]string, 0)
for _, pair := range pairs {
r0 := stats.GetCoSchedCATRuntimes(pair[0], pair[1])
r1 := stats.GetCoSchedCATRuntimes(pair[1], pair[0])
if r0 == nil && r1 == nil {
log.WithFields(log.Fields{
"app0": pair[0],
"app1": pair[1],
}).Infoln("No CAT co-scheduling data")
continue
}
if r0 == nil || r1 == nil {
log.WithFields(log.Fields{
"app0": pair[0],
"app1": pair[1],
}).Errorln("CAT co-scheduling data inconsistent")
continue
}
out := "# 0: " + pair[0] + "\n"
out += "# co-scheduled with \n"
out += "# 1: " + pair[1] + "\n"
if matchpairs {
out += "L3 limit correct only for 0, 1 uses rest\n"
}
sortedKeys0 := sortedKeys(r0)
sortedKeys1 := sortedKeys(r1)
arbRun := (*r0)[sortedKeys0[0]]
out += "# L3(0) Runtime(0) Std.Dev.(0) "
for _, temp := range extractPerfData(&arbRun) {
out += temp.Name + "(0) "
out += "Std.Dev " + temp.Name + "(0) "
if pair == pairs[0] {
perfName = append(perfName, temp.Name)
}
}
out += "Runtime(1) Std.Dev(1) "
for _, temp := range extractPerfData(&arbRun) {
out += temp.Name + "(1) "
out += "Std.Dev " + temp.Name + "(1) "
}
out += "\n"
for i := range sortedKeys0 {
k0 := sortedKeys0[i]
k1 := sortedKeys1[i]
if matchpairs {
k1 = sortedKeys1[len(sortedKeys1)-i-1]
}
v0, exist := (*r0)[k0]
if !exist {
log.Fatalf("Could not find key %v. Should never happen.", k0)
}
v1, exist := (*r1)[k1]
if !exist {
log.Fatalf("Could not find key %v. Should never happen.\n", k1)
}
out += coSchedRuntimeToString(k0, &v0, &v1, extractPerfData(&v0), extractPerfData(&v1))
}
ref0 := stats.GetCoSchedRuntimes(pair[0], pair[1])
ref1 := stats.GetCoSchedRuntimes(pair[1], pair[0])
// TODO fix hardcoded 20
out += coSchedRuntimeToString(20, ref0, ref1, extractPerfData(ref0), extractPerfData(ref1))
filename := coSchedCATDatFilename(pair[0], pair[1], matchpairs)
err := ioutil.WriteFile(filename, []byte(out), 0644)
if err != nil {
log.WithError(err).WithFields(log.Fields{
"filename": filename,
}).Fatalln("Error while write file")
}
ret = append(ret, filename)
}
return ret, perfName
}
// Returns the filenames
func createIndvCATDatFiles(apps []string) ([]string, []string) {
log.Println("Creating dat files for individual CAT runs.")
ret := make([]string, 0)
perfName := make([]string, 0)
for _, app := range apps {
catRuntime := stats.GetCATRuntimes(app)
if catRuntime == nil {
continue
}
out := "# " + app + "\n"
sortedKeys := sortedKeys(catRuntime)
arbRun := (*catRuntime)[sortedKeys[0]]
out += "# L3 Runtime Std.Dev. "
for _, temp := range extractPerfData(&arbRun) {
out += temp.Name
out += "Std.Dev " + temp.Name
if app == apps[0] {
perfName = append(perfName, temp.Name)
}
}
out += "\n"
for _, k := range sortedKeys {
log.WithField("app", app).WithField("cat", k).Debugln("Currently analysing")
v, exist := (*catRuntime)[k]
if !exist {
log.Fatalln("Could not find key. Should never happen.")
}
out += coSchedRuntimeToString(k, &v, nil, extractPerfData(&v), nil)
}
log.WithField("app", app).WithField("cat", "no cat").Debugln("Currently analysing")
ref := stats.GetReferenceRuntime(app)
// TODO fix hardcoded 20
out += coSchedRuntimeToString(20, ref, nil, extractPerfData(ref), nil)
filename := indvCATDatFilename(app)
err := ioutil.WriteFile(filename, []byte(out), 0644)
if err != nil {
log.WithError(err).WithFields(log.Fields{
"filename": filename,
}).Fatalln("Error while write file")
}
ret = append(ret, filename)
}
return ret, perfName
}
func coSchedRuntimeToString(CATChunks int, ref0, ref1 *stats.RuntimeT, perf0, perf1 []perfDataT) string {
out := strconv.FormatFloat(1.5*float64(CATChunks), 'E', -1, 64) + " "
out += strconv.FormatFloat(ref0.Mean, 'E', -1, 64) + " " + strconv.FormatFloat(ref0.Stddev, 'E', -1, 64)
for _, p := range perf0 {
out += " " + strconv.FormatFloat(p.Mean, 'E', -1, 64) + " " + strconv.FormatFloat(p.Stddev, 'E', -1, 64)
}
if ref1 != nil {
out += " "
out += strconv.FormatFloat(ref1.Mean, 'E', -1, 64) + " " + strconv.FormatFloat(ref1.Stddev, 'E', -1, 64)
for _, p := range perf1 {
out += " " + strconv.FormatFloat(p.Mean, 'E', -1, 64) + " " + strconv.FormatFloat(p.Stddev, 'E', -1, 64)
}
}
out += "\n"
return out
}
func indvCATDatFilename(app string) string {
// TODO check if filename already in use
return commands.Pretty(app) + "-cat.dat"
}
func coSchedCATDatFilename(app0 string, app1 string, matchpairs bool) string {
// TODO check if filename already in use
ret := commands.Pretty(app0) + "-" + commands.Pretty(app1) + "-cosched-cat"
if matchpairs {
ret += "-paired"
}
ret += ".dat"
return ret
}