-
Notifications
You must be signed in to change notification settings - Fork 1
/
summary_event_flow.go
90 lines (78 loc) · 2.12 KB
/
summary_event_flow.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
package evaluation
import (
"errors"
"strings"
"github.com/rai-project/evaluation/eventflow"
"github.com/rai-project/evaluation/writer"
db "upper.io/db.v3"
)
//easyjson:json
type SummaryEventFlow struct {
SummaryBase `json:",inline"`
EventFlow eventflow.Events `json:"event_flow,omitempty"`
}
type SummaryEventFlows []SummaryEventFlow
func (SummaryEventFlow) Header(opts ...writer.Option) []string {
extra := eventflow.Event{}.Header()
return append(SummaryBase{}.Header(opts...), extra...)
}
func (s SummaryEventFlow) Row(opts ...writer.Option) []string {
events := []string{}
for _, e := range s.EventFlow {
events = append(events, strings.Join(e.Row(opts...), "\t"))
}
extra := []string{
strings.Join(events, ";"),
}
return append(s.SummaryBase.Row(opts...), extra...)
}
func (SummaryEventFlows) Header(opts ...writer.Option) []string {
return SummaryEventFlow{}.Header(opts...)
}
func (s SummaryEventFlows) Rows(opts ...writer.Option) [][]string {
rows := [][]string{}
for _, e := range s {
rows = append(rows, e.Row(opts...))
}
return rows
}
func spansToEventFlow(spans Spans) eventflow.Events {
return eventflow.SpansToEvenFlow(spans)
}
func (p Performance) EventFlowSummary(e Evaluation) (*SummaryEventFlow, error) {
perfSpans, err := p.Spans()
if err != nil {
return nil, err
}
flow := spansToEventFlow(perfSpans)
return &SummaryEventFlow{
SummaryBase: e.summaryBase(),
EventFlow: flow,
}, nil
}
func (e Evaluation) EventFlowSummary(perfCol *PerformanceCollection) (*SummaryEventFlow, error) {
perfs, err := perfCol.Find(db.Cond{"_id": e.PerformanceID})
if err != nil {
return nil, err
}
if len(perfs) != 1 {
return nil, errors.New("expecting on performance output")
}
perf := perfs[0]
return perf.EventFlowSummary(e)
}
func (es Evaluations) EventFlowSummary(perfCol *PerformanceCollection) (SummaryEventFlows, error) {
res := []SummaryEventFlow{}
for _, e := range es {
s, err := e.EventFlowSummary(perfCol)
if err != nil {
log.WithError(err).Error("failed to get layer information summary")
continue
}
if s == nil {
continue
}
res = append(res, *s)
}
return res, nil
}