-
Notifications
You must be signed in to change notification settings - Fork 5
/
stat.go
130 lines (109 loc) · 3.37 KB
/
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
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// Copyright 2023-2024 antlabs. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package greatws
import "sync/atomic"
// 统计信息
type stat struct {
readSyssall int64 // 读系统调用次数
writeSyscall int64 // 写系统调用次数
curConn int64 // 当前tcp连接数
realloc int64 // 重新分配内存次数
moveBytes uint64 // 移动字节数
readEv int64 // 读事件次数
writeEv int64 // 写事件次数
pollEv int64 // poll事件次数, 包含读,写, 错误事件
}
// 对外接口,查询当前业务协程池个数
func (m *MultiEventLoop) GetCurGoNum() (total int) {
for _, v := range m.loops {
// 本地任务数
total += int(v.localTask.GetGoroutines())
}
return
}
// 对外接口,查询业务协程池运行的当前业务数
func (m *MultiEventLoop) GetCurTaskNum() (total int64) {
for _, v := range m.loops {
// 本地任务数
total += int64(v.localTask.GetGoroutines())
}
return
}
// 对外接口,查询移动字节数
func (m *MultiEventLoop) GetMoveBytesNum() uint64 {
return atomic.LoadUint64(&m.moveBytes)
}
// 对外接口,查询重新分配内存次数
func (m *MultiEventLoop) GetReallocNum() int64 {
return atomic.LoadInt64(&m.realloc)
}
// 对外接口,查询read syscall次数
func (m *MultiEventLoop) GetReadSyscallNum() int64 {
return atomic.LoadInt64(&m.readSyssall)
}
// 对外接口,查询write syscall次数
func (m *MultiEventLoop) GetWriteSyscallNum() int64 {
return atomic.LoadInt64(&m.writeSyscall)
}
// 对外接口,查询当前websocket连接数
func (m *MultiEventLoop) GetCurConnNum() int64 {
return atomic.LoadInt64(&m.curConn)
}
// 对外接口,查询poll read事件次数
func (m *MultiEventLoop) GetReadEvNum() int64 {
return atomic.LoadInt64(&m.readEv)
}
// 对外接口,查询poll write事件次数
func (m *MultiEventLoop) GetWriteEvNum() int64 {
return atomic.LoadInt64(&m.writeEv)
}
// 对外接口,查询poll 返回的事件总次数
func (m *MultiEventLoop) GetPollEvNum() int64 {
return atomic.LoadInt64(&m.pollEv)
}
// 对外接口,返回当前使用的api名字
func (m *MultiEventLoop) GetApiName() string {
if len(m.loops) == 0 {
return ""
}
return m.loops[0].GetApiName()
}
// 对内接口
func (m *MultiEventLoop) addRealloc() {
atomic.AddInt64(&m.realloc, 1)
}
// 对内接口
func (m *MultiEventLoop) addReadSyscall() {
atomic.AddInt64(&m.readSyssall, 1)
}
// 对内接口
func (m *MultiEventLoop) addWriteSyscall() {
atomic.AddInt64(&m.writeSyscall, 1)
}
// 对内接口
func (m *MultiEventLoop) addMoveBytes(n uint64) {
atomic.AddUint64(&m.moveBytes, n)
}
// 对内接口
func (m *MultiEventLoop) addReadEvNum() {
atomic.AddInt64(&m.readEv, 1)
}
// 对内接口
func (m *MultiEventLoop) addWriteEvNum() {
atomic.AddInt64(&m.writeEv, 1)
}
// 对内接口
func (m *MultiEventLoop) addPollEvNum() {
atomic.AddInt64(&m.pollEv, 1)
}