1
0
mirror of https://github.com/Mrs4s/go-cqhttp.git synced 2025-05-04 19:17:37 +08:00

feat: modular pprof server

This module is about 384KiB in windows/amd64
This commit is contained in:
wdvxdr 2021-10-11 22:47:06 +08:00
parent e4bd30d000
commit fcc9962b15
No known key found for this signature in database
GPG Key ID: 703F8C071DE7A1B6
3 changed files with 20 additions and 17 deletions

View File

@ -18,16 +18,17 @@ import (
"golang.org/x/crypto/pbkdf2"
"golang.org/x/term"
_ "github.com/Mrs4s/go-cqhttp/modules/mime" // mime检查模块
"github.com/Mrs4s/go-cqhttp/modules/servers"
_ "github.com/Mrs4s/go-cqhttp/modules/silk" // silk编码模块
"github.com/Mrs4s/go-cqhttp/coolq"
"github.com/Mrs4s/go-cqhttp/global"
"github.com/Mrs4s/go-cqhttp/global/terminal"
"github.com/Mrs4s/go-cqhttp/internal/base"
"github.com/Mrs4s/go-cqhttp/internal/selfupdate"
"github.com/Mrs4s/go-cqhttp/modules/servers"
"github.com/Mrs4s/go-cqhttp/server"
_ "github.com/Mrs4s/go-cqhttp/modules/mime" // mime检查模块
_ "github.com/Mrs4s/go-cqhttp/modules/pprof" // pprof 性能分析
_ "github.com/Mrs4s/go-cqhttp/modules/silk" // silk编码模块
)
// 允许通过配置文件设置的状态列表

View File

@ -1,4 +1,4 @@
package server
package pprof
import (
"fmt"
@ -12,6 +12,7 @@ import (
"github.com/Mrs4s/go-cqhttp/coolq"
"github.com/Mrs4s/go-cqhttp/modules/config"
"github.com/Mrs4s/go-cqhttp/modules/servers"
)
// runPprof 启动 pprof 性能分析服务器
@ -33,15 +34,17 @@ func runPprof(_ *coolq.CQBot, node yaml.Node) {
mux.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
mux.HandleFunc("/debug/pprof/trace", pprof.Trace)
server := http.Server{Addr: addr, Handler: mux}
go func() {
log.Infof("pprof debug 服务器已启动: %v/debug/pprof", addr)
log.Warnf("警告: pprof 服务不支持鉴权, 请不要运行在公网.")
if err := server.ListenAndServe(); err != nil && err != http.ErrServerClosed {
log.Error(err)
log.Infof("pprof 服务启动失败, 请检查端口是否被占用.")
log.Warnf("将在五秒后退出.")
time.Sleep(time.Second * 5)
os.Exit(1)
}
}()
log.Infof("pprof debug 服务器已启动: %v/debug/pprof", addr)
log.Warnf("警告: pprof 服务不支持鉴权, 请不要运行在公网.")
if err := server.ListenAndServe(); err != nil && err != http.ErrServerClosed {
log.Error(err)
log.Infof("pprof 服务启动失败, 请检查端口是否被占用.")
log.Warnf("将在五秒后退出.")
time.Sleep(time.Second * 5)
os.Exit(1)
}
}
func init() {
servers.Register("pprof", runPprof)
}

View File

@ -8,6 +8,5 @@ func init() {
servers.Register("http", runHTTP)
servers.Register("ws", runWSServer)
servers.Register("ws-reverse", runWSClient)
servers.Register("pprof", runPprof)
servers.Register("lambda", runLambda)
}