-
Notifications
You must be signed in to change notification settings - Fork 31
/
info.go
107 lines (86 loc) · 2.34 KB
/
info.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
package main
import (
"sync"
"time"
)
// Status represents a benchmark status.
type Status string
// Process statuses.
const (
Starting Status = "Starting"
InProgress = "In progress"
Finished = "Finished"
Aborted = "Aborted"
Failed = "Failed"
)
// BenchmarkStatus holds details of current status.
type BenchmarkStatus struct {
Status Status `json:"status"`
Progress float64 `json:"progress"`
CurrentCommit *Commit `json:"commit,omitempty"`
}
// Info holds information about bench session,
// like pkg name, start time, progress, status, etc.
type Info struct {
mx *sync.RWMutex
BenchmarkStatus
PkgName string `json:"pkg_name"`
PkgPath string `json:"pkg_path"`
VCS string `json:"vcs"`
BenchOptions string `json:"bench_options"`
Filter string `json:"filter"`
Commits []Commit `json:"commits"`
BenchResults []BenchmarkSet `json:"results"`
TimeSeries *HighchartsData `json:"time_series,omitempty"`
MemSeries *HighchartsData `json:"mem_series,omitempty"`
StartTime time.Time `json:"start_time"`
EndTime time.Time `json:"end_time"`
}
// NewInfo returns new initialized info.
func NewInfo(pkg, path, vcs, benchopts string, filter *FilterOptions, commits []Commit) *Info {
return &Info{
mx: &sync.RWMutex{},
BenchmarkStatus: BenchmarkStatus{
Status: Starting,
Progress: 0.0,
},
PkgName: pkg,
PkgPath: path,
VCS: vcs,
BenchOptions: benchopts,
Filter: filter.String(),
Commits: commits,
TimeSeries: &HighchartsData{Categories: commits},
MemSeries: &HighchartsData{Categories: commits},
StartTime: time.Now(),
}
}
// SetProgress is a setter for Progress value.
func (i *Info) SetProgress(v float64) {
i.mx.Lock()
i.Progress = v
i.mx.Unlock()
}
// SetCommit is a setter for Current Commit value.
func (i *Info) SetCommit(commit *Commit) {
i.mx.Lock()
i.CurrentCommit = commit
i.mx.Unlock()
}
// SetStatus changes status of execution.
func (i *Info) SetStatus(status Status) {
i.mx.Lock()
defer i.mx.Unlock()
i.Status = status
if status == Finished {
i.EndTime = time.Now()
}
}
// AddResult inserts new BenchmarkSet result to Info.
func (i *Info) AddResult(b BenchmarkSet) {
i.mx.Lock()
defer i.mx.Unlock()
i.BenchResults = append(i.BenchResults, b)
i.TimeSeries.AddResult(b, "time")
i.MemSeries.AddResult(b, "memory")
}