From 81d52135ad7af420461aeab1bb2ded8e11c1a654 Mon Sep 17 00:00:00 2001 From: qydysky Date: Wed, 15 May 2024 16:43:56 +0000 Subject: [PATCH] =?utf8?q?Add=20=E6=B7=BB=E5=8A=A0=E9=85=8D=E7=BD=AEdebug?= =?utf8?q?=E8=B7=AF=E5=BE=84=EF=BC=8C=E8=B0=83=E6=95=B4debug=E6=A8=A1?= =?utf8?q?=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- README.md | 8 +++++--- Reply/F.go | 39 +++++++++++++------------------------ demo/config/config_K_v.json | 4 +++- 3 files changed, 22 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index c808b43..cf3a001 100644 --- a/README.md +++ b/README.md @@ -310,11 +310,13 @@ config_K_v.json } ``` -另外,当配置文件中的`debug模式`为`true`时 +另外,当配置文件中的`debug路径`不为空时, 访问此路径可以获取调试信息,为空时关闭,需要/结尾,默认为空 -- 标准包[net/http/pprof](https://pkg.go.dev/net/http/pprof)将在`/debug/pprof/`路径可用,从而可以使用`go tool pprof`工具进行性能调试。 -- 当录制fmp4时,每1分钟打印m4s池状态 +- 标准包[net/http/pprof](https://pkg.go.dev/net/http/pprof)将在`debug路径`路径可用,从而可以使用`go tool pprof`工具进行性能调试。 + +另外,当配置文件中的`debug模式`为`true`时,默认为`false`, 启用额外调试信息 +- 当录制fmp4时,每1分钟打印m4s池状态 #### 自定义config_K_v.json 当启动时使用`-ckv 路径`,将从此路径(或http地址)加载config_K_v.json并覆盖默认config_K_v.json中的配置项。 diff --git a/Reply/F.go b/Reply/F.go index 8e9b9c2..282abea 100644 --- a/Reply/F.go +++ b/Reply/F.go @@ -1140,36 +1140,25 @@ func init() { } // debug模式 - if de, ok := c.C.K_v.LoadV(`debug模式`).(bool); ok && de { - c.C.SerF.Store("/debug/pprof/", func(w http.ResponseWriter, r *http.Request) { + if debugP, ok := c.C.K_v.LoadV(`debug路径`).(string); ok && debugP != "" { + c.C.SerF.Store(debugP, func(w http.ResponseWriter, r *http.Request) { if c.DefaultHttpCheck(c.C, w, r, http.MethodGet, http.MethodPost) { return } - pprof.Index(w, r) - }) - c.C.SerF.Store("/debug/pprof/cmdline", func(w http.ResponseWriter, r *http.Request) { - if c.DefaultHttpCheck(c.C, w, r, http.MethodGet, http.MethodPost) { - return - } - pprof.Cmdline(w, r) - }) - c.C.SerF.Store("/debug/pprof/profile", func(w http.ResponseWriter, r *http.Request) { - if c.DefaultHttpCheck(c.C, w, r, http.MethodGet, http.MethodPost) { - return - } - pprof.Profile(w, r) - }) - c.C.SerF.Store("/debug/pprof/symbol", func(w http.ResponseWriter, r *http.Request) { - if c.DefaultHttpCheck(c.C, w, r, http.MethodGet, http.MethodPost) { - return - } - pprof.Symbol(w, r) - }) - c.C.SerF.Store("/debug/pprof/trace", func(w http.ResponseWriter, r *http.Request) { - if c.DefaultHttpCheck(c.C, w, r, http.MethodGet, http.MethodPost) { + if name, found := strings.CutPrefix(r.URL.Path, debugP); found && name != "" { + switch name { + case "cmdline": + pprof.Cmdline(w, r) + case "profile": + pprof.Profile(w, r) + case "trace": + pprof.Trace(w, r) + default: + pprof.Handler(name).ServeHTTP(w, r) + } return } - pprof.Trace(w, r) + pprof.Index(w, r) }) } diff --git a/demo/config/config_K_v.json b/demo/config/config_K_v.json index 32bf18d..c033b77 100644 --- a/demo/config/config_K_v.json +++ b/demo/config/config_K_v.json @@ -185,8 +185,10 @@ "几秒后重载-help":"最少间隔60s,-1时不重载", "几秒后重载":60, "下播后不记录人气观看人数":true, - "debug模式-help":"在/debug/pprof/启用调试", + "debug模式-help":"启用额外调试信息", "debug模式":false, + "debug路径-help":"当Web服务地址不为空时, 访问此路径可以获取调试信息,为空时关闭,需要/结尾", + "debug路径":"", "性能路径-help":"当Web服务地址不为空时, 访问此路径可以获取性能信息,为空时关闭", "性能路径":"/state/", "生成pgo-help":"将在退出后生成pgo文件在指定路径,default.pgo将有助于下次构建的优化,但会导致gc频繁,构建缓慢,为空时不生成", -- 2.39.2