]> 127.0.0.1 Git - bili_danmu/.git/commitdiff
Add 添加配置debug路径,调整debug模式
authorqydysky <qydysky@foxmail.com>
Wed, 15 May 2024 16:43:56 +0000 (16:43 +0000)
committerqydysky <qydysky@foxmail.com>
Wed, 15 May 2024 16:43:56 +0000 (16:43 +0000)
README.md
Reply/F.go
demo/config/config_K_v.json

index c808b43252ba66b24a350658a70a5e1adae0f5e5..cf3a0019fca46555a9ea2c00a520a00af362d6c0 100644 (file)
--- 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中的配置项。
index 8e9b9c25ab30a781a4335334c588175662441de0..282abeaacca59392526824768f8a89ccd346d63a 100644 (file)
@@ -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)
                        })
                }
 
index 32bf18d2f0b540497573ad34e18549c126c41a8f..c033b77c67d2a83808891bef88ce728160642b8e 100644 (file)
     "几秒后重载-help":"最少间隔60s,-1时不重载",
     "几秒后重载":60,
     "下播后不记录人气观看人数":true,
-    "debug模å¼\8f-help":"å\9c¨/debug/pprof/å\90¯ç\94¨è°\83è¯\95",
+    "debug模å¼\8f-help":"å\90¯ç\94¨é¢\9då¤\96è°\83è¯\95ä¿¡æ\81¯",
     "debug模式":false,
+    "debug路径-help":"当Web服务地址不为空时, 访问此路径可以获取调试信息,为空时关闭,需要/结尾",
+    "debug路径":"",
     "性能路径-help":"当Web服务地址不为空时, 访问此路径可以获取性能信息,为空时关闭",
     "性能路径":"/state/",
     "生成pgo-help":"将在退出后生成pgo文件在指定路径,default.pgo将有助于下次构建的优化,但会导致gc频繁,构建缓慢,为空时不生成",