fix high cpu usage problem

master v1.3.2
兔子 2 years ago
parent 3b27697177
commit 1632256ded

@ -3,18 +3,7 @@ module b612.me/starlog
go 1.16
require (
b612.me/starmap v1.2.2
b612.me/staros v1.1.5
golang.org/x/sys v0.4.0
)
require (
b612.me/notify v1.2.3 // indirect
b612.me/starcrypto v0.0.2 // indirect
b612.me/stario v0.0.7 // indirect
b612.me/starnet v0.1.6 // indirect
b612.me/win32api v0.0.1 // indirect
b612.me/wincmd v0.0.2 // indirect
golang.org/x/crypto v0.0.0-20220321153916-2c7772ba3064 // indirect
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
b612.me/starmap v1.2.3
b612.me/staros v1.1.6
golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8
)

@ -1,15 +1,16 @@
b612.me/notify v1.2.3 h1:4w5zDakubC8jIPg4JT8DANczSMxRhwEFjM/2A0dvuvY=
b612.me/notify v1.2.3/go.mod h1:VV29yq3KXTKJKSSjr5yS9bD2c2MGzuypYalfL9yGQ6M=
b612.me/notify v1.2.4 h1:cjP80V9FeM+ib1DztZdykusakcbjNI4dAB1pXE8U6bo=
b612.me/notify v1.2.4/go.mod h1:SlCrG1kPRVhYUrIkwY/j0zAwCU4VeTHubcZoQXW8Anw=
b612.me/starcrypto v0.0.2 h1:aRf1HcqK8GqHYxLAhWfFC4W/EqQLEFNEmxsBu3wG30o=
b612.me/starcrypto v0.0.2/go.mod h1:hz0xRnfWNpYOlVrIPoGrQOWPibq4YiUZ7qN5tsQbzPo=
b612.me/stario v0.0.7 h1:QbQcsHCVLE6vRgVrPN4+9DGiSaC6IWdtm4ClL2tpMUg=
b612.me/stario v0.0.7/go.mod h1:or4ssWcxQSjMeu+hRKEgtp0X517b3zdlEOAms8Qscvw=
b612.me/starmap v1.2.2 h1:1OQbd0XXU7G/cHvkj9lEZg8sLZWZEcYlRjYzDxRc4N0=
b612.me/starmap v1.2.2/go.mod h1:fXb1SF8+BrkHlhSMQAJ/DUTYpqhNimPukpqzUIRio4U=
b612.me/starnet v0.1.6 h1:/QaaKpuXfvJm6ayvk85jaLaKBmO1zx+XSxfnlSB3xGw=
b612.me/starnet v0.1.6/go.mod h1:JjFLTMPsWsPei7AiXwBTt4QCoB9gux1XS7SHv/Ux+D4=
b612.me/staros v1.1.5 h1:0Mkk0TOYoI9SOUf50X2Amb+/4p2lopMntOzV5nPKEeg=
b612.me/staros v1.1.5/go.mod h1:JcmVUeFbuITVnwPqxCr6R9yDbBmFrfyhdk2HVdZMXYw=
b612.me/stario v0.0.8 h1:kaA4pszAKLZJm2D9JmiuYSpgjTeE3VaO74vm+H0vBGM=
b612.me/stario v0.0.8/go.mod h1:or4ssWcxQSjMeu+hRKEgtp0X517b3zdlEOAms8Qscvw=
b612.me/starmap v1.2.3 h1:+ao++KgbSGMA4UzcHm/EXJoukbUudk8t5ac7rjwV9KA=
b612.me/starmap v1.2.3/go.mod h1:K+exTSWg8i/taoUyGR6DPW6Ja0k6aIdpcniqByOf4O0=
b612.me/starnet v0.1.7 h1:k3CUfYNRolC/xw5Ekus2NVWHlqeykSyAH8USGTPKA5o=
b612.me/starnet v0.1.7/go.mod h1:DNC4i/ezgVLlmxnquf8AeljsL4mQ5vAyxh8vGPQqsys=
b612.me/staros v1.1.6 h1:m3QaEmPyvPcJVomjWs8cDeauDYFNKv7cLHTiOHClKqM=
b612.me/staros v1.1.6/go.mod h1:O657LC3qag4VSsHNmt5RM8gKJvzoEGq8IF8WegcRgq0=
b612.me/win32api v0.0.1 h1:vLFB1xhO6pd9+zB2EyaapKB459Urv3v+C1YwgwOFEWo=
b612.me/win32api v0.0.1/go.mod h1:MHu0JBQjzxQ2yxpZPUBbn5un45o67eF5iWKa4Q9e0yE=
b612.me/wincmd v0.0.2 h1:Ub1WtelVT6a3vD4B6zDYo3UPO/t9ymnI3x1dQPJcrGw=
@ -22,9 +23,8 @@ golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8 h1:OH54vjqzRWmbJ62fjuhxy7AxFFgoHN0/DPc/UrL8cAs=
golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.4.0 h1:Zr2JFtRQNX3BCZ8YtxRE9hNJYC8J6I1MVbMg6owUp18=
golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 h1:JGgROgKl9N8DuW20oFS5gxc+lE67/N3FcwmBPMe7ArY=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=

@ -1,7 +1,6 @@
package starlog
import (
"b612.me/starmap"
"fmt"
"io"
"math/rand"
@ -13,7 +12,6 @@ var Std *StarLogger
var stdmu sync.Mutex
func init() {
stacks = starmap.NewStarStack(1024)
rand.Seed(time.Now().UnixNano())
stackStopChan = make(chan int)
Std = NewStarlog(nil)

@ -33,7 +33,7 @@ var (
LvPanic: "PANIC",
LvFatal: "FATAL",
}
stacks *starmap.StarStack
stacks *starmap.StarChanStack
stackStarted bool = false
stackStopChan chan int
stackMu sync.Mutex
@ -181,9 +181,12 @@ func StartStacks() {
stackMu.Unlock()
return
}
unlock := make(chan struct{})
go func() {
stackStarted = true
stacks = starmap.NewStarChanStack(1024)
stackMu.Unlock()
unlock <- struct{}{}
defer func() {
stackStarted = false
}()
@ -193,10 +196,9 @@ func StartStacks() {
return
default:
}
poped := stacks.MustPop()
if poped == nil {
time.Sleep(time.Microsecond * 500)
continue
poped, err := stacks.Pop()
if err != nil {
return
}
val := poped.(logTransfer)
if val.handlerFunc != nil {
@ -204,6 +206,7 @@ func StartStacks() {
}
}
}()
<-unlock
}
func StopStacks() {
@ -214,5 +217,6 @@ func StopStacks() {
}
func Stop() {
stacks.Close()
StopStacks()
}

Loading…
Cancel
Save