forked from valyala/gorpc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
conn_stats_386.go
113 lines (95 loc) · 1.99 KB
/
conn_stats_386.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
// Separate implementation for 386, since it has broken support for atomics.
// See https://github.com/valyala/gorpc/issues/5 for details.
// +build 386
package gorpc
import (
"sync"
)
// Snapshot returns connection statistics' snapshot.
//
// Use stats returned from ConnStats.Snapshot() on live Client and / or Server,
// since the original stats can be updated by concurrently running goroutines.
func (cs *ConnStats) Snapshot() *ConnStats {
cs.lock.Lock()
snapshot := *cs
cs.lock.Unlock()
snapshot.lock = sync.Mutex{}
return &snapshot
}
// Reset resets all the stats counters.
func (cs *ConnStats) Reset() {
cs.lock.Lock()
cs.RPCCalls = 0
cs.RPCTime = 0
cs.BytesWritten = 0
cs.BytesRead = 0
cs.WriteCalls = 0
cs.WriteErrors = 0
cs.ReadCalls = 0
cs.ReadErrors = 0
cs.DialCalls = 0
cs.DialErrors = 0
cs.AcceptCalls = 0
cs.AcceptErrors = 0
cs.lock.Unlock()
}
func (cs *ConnStats) incRPCCalls() {
cs.lock.Lock()
cs.RPCCalls++
cs.lock.Unlock()
}
func (cs *ConnStats) incRPCTime(dt uint64) {
cs.lock.Lock()
cs.RPCTime += dt
cs.lock.Unlock()
}
func (cs *ConnStats) addBytesWritten(n uint64) {
cs.lock.Lock()
cs.BytesWritten += n
cs.lock.Unlock()
}
func (cs *ConnStats) addBytesRead(n uint64) {
cs.lock.Lock()
cs.BytesRead += n
cs.lock.Unlock()
}
func (cs *ConnStats) incReadCalls() {
cs.lock.Lock()
cs.ReadCalls++
cs.lock.Unlock()
}
func (cs *ConnStats) incReadErrors() {
cs.lock.Lock()
cs.ReadErrors++
cs.lock.Unlock()
}
func (cs *ConnStats) incWriteCalls() {
cs.lock.Lock()
cs.WriteCalls++
cs.lock.Unlock()
}
func (cs *ConnStats) incWriteErrors() {
cs.lock.Lock()
cs.WriteErrors++
cs.lock.Unlock()
}
func (cs *ConnStats) incDialCalls() {
cs.lock.Lock()
cs.DialCalls++
cs.lock.Unlock()
}
func (cs *ConnStats) incDialErrors() {
cs.lock.Lock()
cs.DialErrors++
cs.lock.Unlock()
}
func (cs *ConnStats) incAcceptCalls() {
cs.lock.Lock()
cs.AcceptCalls++
cs.lock.Unlock()
}
func (cs *ConnStats) incAcceptErrors() {
cs.lock.Lock()
cs.AcceptErrors++
cs.lock.Unlock()
}