上传性能监控工具
This commit is contained in:
parent
549006f4cd
commit
e50b9432f1
@ -20,6 +20,8 @@ type GameConfig struct {
|
||||
Workers []string //工作服
|
||||
BattleOpen bool //是否启用战斗
|
||||
BattleAddr string //战斗服地址
|
||||
PprofOpen bool //是否启动性能监控
|
||||
PprofAddr string //性能监控查看端口
|
||||
}
|
||||
|
||||
//区服db配置
|
||||
|
3
go.mod
3
go.mod
@ -27,6 +27,7 @@ require (
|
||||
github.com/tidwall/gjson v1.14.1
|
||||
github.com/ugorji/go/codec v1.2.7
|
||||
github.com/valyala/fastrand v1.1.0
|
||||
github.com/wolfogre/go-pprof-practice v0.0.0-20230706085634-23c8f603cac9
|
||||
go.mongodb.org/mongo-driver v1.5.1
|
||||
go.uber.org/multierr v1.6.0
|
||||
golang.org/x/net v0.10.0
|
||||
@ -134,7 +135,7 @@ require (
|
||||
go.opentelemetry.io/otel/trace v1.6.3 // indirect
|
||||
go.uber.org/atomic v1.7.0 // indirect
|
||||
go.uber.org/zap v1.17.0 // indirect
|
||||
golang.org/x/crypto v0.0.0-20220829220503-c86fa9a7ed90 // indirect
|
||||
golang.org/x/crypto v0.0.0-20220829220503-c86fa9a7ed90
|
||||
golang.org/x/mod v0.10.0 // indirect
|
||||
golang.org/x/sync v0.2.0 // indirect
|
||||
golang.org/x/sys v0.8.0 // indirect
|
||||
|
3
go.sum
3
go.sum
@ -578,6 +578,8 @@ github.com/vmihailenco/msgpack/v5 v5.3.5 h1:5gO0H1iULLWGhs2H5tbAHIZTV8/cYafcFOr9
|
||||
github.com/vmihailenco/msgpack/v5 v5.3.5/go.mod h1:7xyJ9e+0+9SaZT0Wt1RGleJXzli6Q/V5KbhBonMG9jc=
|
||||
github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAhO7/IwNM9g=
|
||||
github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV6mEfg5OIWRZA9qds=
|
||||
github.com/wolfogre/go-pprof-practice v0.0.0-20230706085634-23c8f603cac9 h1:JUZL5TQ/WK5veU2N171inEvwseqf4V0TxgGKl2Ypyvs=
|
||||
github.com/wolfogre/go-pprof-practice v0.0.0-20230706085634-23c8f603cac9/go.mod h1:guVzD2XeU5rwULTURC4peeFyZya60U0BLKqisEjCylA=
|
||||
github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c=
|
||||
github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI=
|
||||
github.com/xdg-go/scram v1.0.2 h1:akYIkZ28e6A96dkWNJQu3nmCzH3YfwMPQExUYDaRv7w=
|
||||
@ -758,6 +760,7 @@ golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU=
|
||||
golang.org/x/sys v0.8.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/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/term v0.8.0 h1:n5xxQn2i3PC0yLAbjTpNT85q/Kgzcr2gIoX9OrJUols=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
||||
|
22
lego/sys/pprof/core.go
Normal file
22
lego/sys/pprof/core.go
Normal file
@ -0,0 +1,22 @@
|
||||
package pprof
|
||||
|
||||
type (
|
||||
ISys interface {
|
||||
}
|
||||
)
|
||||
|
||||
var (
|
||||
defsys ISys
|
||||
)
|
||||
|
||||
func OnInit(config map[string]interface{}, option ...Option) (err error) {
|
||||
if defsys, err = newSys(newOptions(config, option...)); err == nil {
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func NewSys(option ...Option) (sys ISys, err error) {
|
||||
if sys, err = newSys(newOptionsByOption(option...)); err == nil {
|
||||
}
|
||||
return
|
||||
}
|
41
lego/sys/pprof/options.go
Normal file
41
lego/sys/pprof/options.go
Normal file
@ -0,0 +1,41 @@
|
||||
package pprof
|
||||
|
||||
import (
|
||||
"go_dreamfactory/lego/utils/mapstructure"
|
||||
)
|
||||
|
||||
type Option func(*Options)
|
||||
type Options struct {
|
||||
IsOpen bool
|
||||
ListenPort int
|
||||
}
|
||||
|
||||
func SetIsOpen(v bool) Option {
|
||||
return func(o *Options) {
|
||||
o.IsOpen = v
|
||||
}
|
||||
}
|
||||
func SetListenPort(v int) Option {
|
||||
return func(o *Options) {
|
||||
o.ListenPort = v
|
||||
}
|
||||
}
|
||||
|
||||
func newOptions(config map[string]interface{}, opts ...Option) Options {
|
||||
options := Options{}
|
||||
if config != nil {
|
||||
mapstructure.Decode(config, &options)
|
||||
}
|
||||
for _, o := range opts {
|
||||
o(&options)
|
||||
}
|
||||
return options
|
||||
}
|
||||
|
||||
func newOptionsByOption(opts ...Option) Options {
|
||||
options := Options{}
|
||||
for _, o := range opts {
|
||||
o(&options)
|
||||
}
|
||||
return options
|
||||
}
|
41
lego/sys/pprof/pprof.go
Normal file
41
lego/sys/pprof/pprof.go
Normal file
@ -0,0 +1,41 @@
|
||||
package pprof
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
_ "net/http/pprof"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"go_dreamfactory/lego/sys/log"
|
||||
|
||||
"github.com/wolfogre/go-pprof-practice/animal"
|
||||
)
|
||||
|
||||
func newSys(options Options) (sys *Pprof, err error) {
|
||||
if options.IsOpen {
|
||||
sys = &Pprof{options: options}
|
||||
go sys.Start()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
type Pprof struct {
|
||||
options Options
|
||||
}
|
||||
|
||||
func (this *Pprof) Start() {
|
||||
go func() {
|
||||
if err := http.ListenAndServe(fmt.Sprintf(":%d", this.options.ListenPort), nil); err != nil {
|
||||
log.Fatalf("Start Pprof Fatalf err:%v", err)
|
||||
}
|
||||
os.Exit(0)
|
||||
}()
|
||||
|
||||
for {
|
||||
for _, v := range animal.AllAnimals {
|
||||
v.Live()
|
||||
}
|
||||
time.Sleep(time.Second)
|
||||
}
|
||||
}
|
19
lego/sys/pprof/sys_test.go
Normal file
19
lego/sys/pprof/sys_test.go
Normal file
@ -0,0 +1,19 @@
|
||||
package pprof_test
|
||||
|
||||
/*
|
||||
查看堆栈调用信息
|
||||
go tool pprof http://localhost:6060/debug/pprof/heap
|
||||
查看 30 秒内的 CPU 信息
|
||||
go tool pprof http://localhost:6060/debug/pprof/profile?seconds=30
|
||||
查看 goroutine 阻塞
|
||||
go tool pprof http://localhost:6060/debug/pprof/block
|
||||
收集 5 秒内的执行路径
|
||||
go tool pprof http://localhost:6060/debug/pprof/trace?seconds=5
|
||||
争用互斥持有者的堆栈跟踪
|
||||
go tool pprof http://localhost:6060/debug/pprof/mutex
|
||||
*/
|
||||
/*
|
||||
UI web 界面
|
||||
curl -sK -v http://localhost:6060/debug/pprof/heap > heap.out
|
||||
go tool pprof -http=:8080 heap.out
|
||||
*/
|
@ -147,7 +147,7 @@ func (this *Mainline) BingoJumpLevel(session comm.IUserSession, level int32) (er
|
||||
return
|
||||
}
|
||||
|
||||
// 查询用户主线通关
|
||||
// 查询用户主线通关 db.changeUserPassword("root", "palsweasd*1!")
|
||||
func (this *Mainline) InquireMainLinePassLevel(uid string) (levels map[int32]int32) {
|
||||
var (
|
||||
info *pb.DBMainline
|
||||
|
@ -313,7 +313,7 @@ func (this *Robot) run() {
|
||||
this.Close()
|
||||
return
|
||||
}
|
||||
time.Sleep(time.Millisecond * time.Duration(100+rand.Int31n(1000)))
|
||||
time.Sleep(time.Millisecond * time.Duration(100+rand.Int31n(2000)))
|
||||
}
|
||||
|
||||
for this.cycle {
|
||||
@ -345,7 +345,7 @@ func (this *Robot) run() {
|
||||
this.cycle = true
|
||||
}
|
||||
}
|
||||
time.Sleep(time.Millisecond * time.Duration(100+rand.Int31n(1000)))
|
||||
time.Sleep(time.Millisecond * time.Duration(100+rand.Int31n(2000)))
|
||||
}
|
||||
}
|
||||
this.Close()
|
||||
|
@ -92,6 +92,7 @@ import (
|
||||
"go_dreamfactory/lego/core"
|
||||
"go_dreamfactory/lego/sys/cron"
|
||||
"go_dreamfactory/lego/sys/log"
|
||||
"go_dreamfactory/lego/sys/pprof"
|
||||
"go_dreamfactory/lego/sys/timewheel"
|
||||
)
|
||||
|
||||
@ -235,4 +236,10 @@ func (this *Service) InitSys() {
|
||||
} else {
|
||||
log.Infof("init sys.db success!")
|
||||
}
|
||||
//性能监控
|
||||
if err := pprof.OnInit(this.GetSettings().Sys["pprof"]); err != nil {
|
||||
panic(fmt.Sprintf("init sys.pprof err: %s", err.Error()))
|
||||
} else {
|
||||
log.Infof("init sys.pprof success!")
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user