-
Notifications
You must be signed in to change notification settings - Fork 0
/
log.go
55 lines (48 loc) · 1.08 KB
/
log.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
package sshclient
import (
"fmt"
"runtime"
"sync"
)
var mutex sync.Mutex
func GetStack() string {
trace := make([]byte, 8192)
count := runtime.Stack(trace, false)
content := fmt.Sprintf("Dump (%d bytes):\n %s \n", count, trace[:count])
return content
}
func schedulePrintClientCount() {
// <-time.After(3 * time.Minute)
// mutex.Lock()
// defer mutex.Unlock()
// fmt.Println("current active", len(clientList))
// for _, client := range clientList {
// fmt.Println("client", client.stackLog)
// }
}
func addClientToLog(client *Client) {
mutex.Lock()
defer mutex.Unlock()
clientList = append(clientList, client)
}
func removeClientFromLog(client *Client) {
mutex.Lock()
defer mutex.Unlock()
indexToDelete := -1
for index, clientInList := range clientList {
if clientInList == client {
indexToDelete = index
break
}
}
if indexToDelete != -1 {
deleteInClientList(clientList, indexToDelete)
} else {
fmt.Println("exit 2 times client", client.stackLog)
}
}
func deleteInClientList(a []*Client, i int) []*Client {
a[i] = a[len(a)-1]
a = a[:len(a)-1]
return a
}