-
Notifications
You must be signed in to change notification settings - Fork 1
/
perf.go
99 lines (90 loc) · 2.54 KB
/
perf.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
package main
import (
"sort"
"strconv"
"strings"
"github.com/jbreitbart/coBench/stats"
mstats "github.com/montanaflynn/stats"
log "github.com/sirupsen/logrus"
)
type perfDataT struct {
Name string
Mean float64
Stddev float64
Vari float64
}
func extractPerfData(dat *stats.RuntimeT) []perfDataT {
coll := make(map[string][]float64)
for _, temp := range *dat.RawRuntimesByMask {
for _, runs := range temp {
stdout := runs.Output
/*
Performance counter stats for '/global/work/share/npb/bt.C.x':
31162368.00 Bytes intel_cqm/llc_occupancy/
7313911210 LLC-load-misses
*/
posHead := strings.Index(stdout, "Performance counter stats for")
if posHead == -1 {
continue
}
posHEadLinebreak := posHead + strings.Index(stdout[posHead:], "\n")
if posHEadLinebreak == -1 {
continue
}
lineStart := posHEadLinebreak + 2 // 2 linebreaks
for {
/* 31162368.00 Bytes intel_cqm/llc_occupancy/ */
endOfLine := strings.Index(stdout[lineStart:], "\n")
if endOfLine == -1 {
break
}
line := strings.TrimSpace(stdout[lineStart : lineStart+endOfLine])
if line == "" {
break
}
endNumber := strings.Index(line, " ")
if endNumber == -1 {
break
}
if value, err := strconv.ParseFloat(line[:endNumber], 64); err == nil {
beginName := strings.LastIndex(line, " ")
name := strings.TrimSpace(line[beginName:])
log.WithField("value", value).WithField("name", name).Debugln("found value")
coll[name] = append(coll[name], value)
} else {
log.WithError(err).WithField("line", line).Errorln("Could not extract value from perf")
}
lineStart = lineStart + endOfLine + 1
}
}
}
var sortedCollKeys []string
for k := range coll {
sortedCollKeys = append(sortedCollKeys, k)
}
sort.Slice(sortedCollKeys[:], func(i, j int) bool {
return sortedCollKeys[i] < sortedCollKeys[j]
})
// TODO verify that sortedCollKeys is identical for every call
perfData := make([]perfDataT, 0)
for _, v := range sortedCollKeys {
var p perfDataT
var err error
p.Name = v
p.Mean, err = mstats.Mean(coll[v])
if err != nil {
log.WithError(err).Errorln("Error while computing mean")
}
p.Stddev, err = mstats.StandardDeviation(coll[v])
if err != nil {
log.WithError(err).Errorln("Error while computing stddev")
}
p.Vari, err = mstats.Variance(coll[v])
if err != nil {
log.WithError(err).Errorln("Error while computing variance")
}
perfData = append(perfData, p)
log.WithField("compute perf", p).Debugln()
}
return perfData
}