From 08b1528c6232daae7ad7bbe577b9c6556de309e7 Mon Sep 17 00:00:00 2001 From: vatebur Date: Fri, 7 Jun 2024 17:07:36 +0800 Subject: [PATCH] analyze --- main.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 2a95f0b6cf..9949f64229 100644 --- a/main.go +++ b/main.go @@ -6,6 +6,7 @@ import ( "flag" "fmt" "math/rand" + "net/http" "os" "runtime" "strconv" @@ -13,8 +14,8 @@ import ( "time" _ "github.com/FloatTech/ZeroBot-Plugin/console" // 更改控制台属性 - - "github.com/FloatTech/ZeroBot-Plugin/kanban" // 打印 banner + "github.com/FloatTech/ZeroBot-Plugin/kanban" // 打印 banner + _ "net/http/pprof" // ---------以下插件均可通过前面加 // 注释,注释后停用并不加载插件--------- // // ----------------------插件优先级按顺序从高到低---------------------- // @@ -308,6 +309,16 @@ func init() { } func main() { + runtime.GOMAXPROCS(1) // 限制 CPU 使用数,避免过载 + runtime.SetMutexProfileFraction(1) // 开启对锁调用的跟踪 + runtime.SetBlockProfileRate(1) // 开启对阻塞操作的跟踪 + go func() { + // 启动一个 http server,注意 pprof 相关的 handler 已经自动注册过了 + if err := http.ListenAndServe(":6060", nil); err != nil { + logrus.Error(err) + } + os.Exit(0) + }() if !strings.Contains(runtime.Version(), "go1.2") { // go1.20之前版本需要全局 seed,其他插件无需再 seed rand.Seed(time.Now().UnixNano()) //nolint: staticcheck }