-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtk_stat.go
40 lines (30 loc) · 845 Bytes
/
tk_stat.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
package templatemanager
import (
"fmt"
"time"
)
type QpsStat struct {
TStart time.Time
TStop time.Time
Count int
}
func NewQpsStat(tStart time.Time, tStop time.Time, count int) *QpsStat {
return &QpsStat{TStart: tStart, TStop: tStop, Count: count}
}
func (st *QpsStat) Duration() time.Duration {
return st.TStop.Sub(st.TStart)
}
func (st *QpsStat) Qps() float64 {
return float64(st.Count) / st.Duration().Seconds()
}
func (st *QpsStat) Spq() float64 {
return 1 / st.Qps()
}
func (st *QpsStat) String() string {
t0 := st.TStart.Format(time.RFC3339Nano)
t1 := st.TStop.Format(time.RFC3339Nano)
return fmt.Sprintf(`(%s, %s, d:%s), (qps:%.5f, spq:%.5f)`, t0, t1, st.Duration(), st.Qps(), st.Spq())
}
func (st *QpsStat) ShortString() string {
return fmt.Sprintf(`%s(qps:%.3f, spq:%.3f)`, st.Duration(), st.Qps(), st.Spq())
}