]> 127.0.0.1 Git - bili_danmu/.git/commitdiff
Add 添加debug模式 默认关
authorqydysky <32743305+qydysky@users.noreply.github.com>
Tue, 28 Feb 2023 12:52:21 +0000 (20:52 +0800)
committerqydysky <32743305+qydysky@users.noreply.github.com>
Tue, 28 Feb 2023 12:52:21 +0000 (20:52 +0800)
Reply/F.go
Reply/stream.go
demo/config/config_K_v.json
demo/main.go

index 1de5d367535cf2da531695d52356fb7ae186c855..6019618dc8c58e66b0af13e961b39858b8e1ffff 100644 (file)
@@ -9,6 +9,7 @@ import (
        "io/fs"
        "math"
        "net/http"
+       "net/http/pprof"
        "path/filepath"
        "sort"
        "strconv"
@@ -297,7 +298,10 @@ func StreamOStart(roomid int) {
                common = c.C
        )
        common.Roomid = roomid
-       tmp.LoadConfig(common, c.C.Log)
+       if e := tmp.LoadConfig(common); e != nil {
+               flog.L(`E: `, e)
+               return
+       }
        //录制回调,关于ass
        tmp.Callback_startRec = func(ms *M4SStream) error {
                StartRecDanmu(ms.Current_save_path + "0.csv")
@@ -1091,6 +1095,15 @@ func init() {
                        return
                }
 
+               // debug模式
+               if de, ok := c.C.K_v.LoadV(`debug模式`).(bool); ok && de {
+                       c.C.SerF.Store("/debug/pprof/", pprof.Index)
+                       c.C.SerF.Store("/debug/pprof/cmdline", pprof.Cmdline)
+                       c.C.SerF.Store("/debug/pprof/profile", pprof.Profile)
+                       c.C.SerF.Store("/debug/pprof/symbol", pprof.Symbol)
+                       c.C.SerF.Store("/debug/pprof/trace", pprof.Trace)
+               }
+
                // 直播流主页
                c.C.SerF.Store(path, func(w http.ResponseWriter, r *http.Request) {
                        p := strings.TrimPrefix(r.URL.Path, path)
index 7a5478b7396a2ea22e1c5288654d3cf20cabf6e8..94e1ce331c6987bb7f91f07a8dcc0ce04e531a43 100644 (file)
@@ -139,9 +139,9 @@ func (t *M4SStream) Common() c.Common {
        return t.common
 }
 
-func (t *M4SStream) LoadConfig(common c.Common, l *log.Log_interface) {
+func (t *M4SStream) LoadConfig(common c.Common) (e error) {
        t.common = common
-       t.log = l.Base(`直播流保存`)
+       t.log = common.Log.Base(`直播流保存`)
 
        //读取配置
        if path, ok := common.K_v.LoadV("直播流保存位置").(string); ok {
@@ -149,22 +149,20 @@ func (t *M4SStream) LoadConfig(common c.Common, l *log.Log_interface) {
                        if fs, err := os.Stat(path); err != nil {
                                if errors.Is(err, os.ErrNotExist) {
                                        if err := p.File().NewPath(path); err != nil {
-                                               t.log.L(`E: `, `直播流保存位置错误`, err)
-                                               return
+                                               return errors.New(`直播流保存位置错误` + err.Error())
                                        }
                                } else {
-                                       t.log.L(`E: `, `直播流保存位置错误`, err)
-                                       return
+                                       return errors.New(`直播流保存位置错误` + err.Error())
                                }
                        } else if !fs.IsDir() {
-                               t.log.L(`E: `, `直播流保存位置不是目录`)
-                               return
+                               return errors.New(`直播流保存位置不是目录`)
                        }
                        t.config.save_path = path + "/"
                } else {
-                       t.log.L(`E: `, `直播流保存位置错误`, err)
-                       return
+                       return errors.New(`直播流保存位置错误` + err.Error())
                }
+       } else {
+               return errors.New(`未配置直播流保存位置`)
        }
        if v, ok := common.K_v.LoadV(`直播hls流保存为MP4`).(bool); ok {
                t.config.save_as_mp4 = v
@@ -178,6 +176,7 @@ func (t *M4SStream) LoadConfig(common c.Common, l *log.Log_interface) {
        if v, ok := common.K_v.LoadV(`直播流类型`).(string); ok {
                t.config.want_type = v
        }
+       return
 }
 
 func (t *M4SStream) getFirstBuf() []byte {
index 2283710e440cc9c320b2f39aafeb3599249c7e9c..e1087f0d6071318d6a2dae09413bf4ce9c752dc9 100644 (file)
@@ -56,7 +56,7 @@
     "直播流类型-help": "flv,fmp4,flvH,fmp4H,带H后缀的为Hevc格式编码",
     "直播流类型": "flv",
     "直播流保存位置": "./live",
-    "直播流保存天数-help": "当t日有1录播时,会尝试删除t-n日的1个最早的录播",
+    "直播流保存天数-help": "当t日有1录播时,会尝试删除t-n日的1个最早的录播。小于1的数将禁用此功能",
     "直播流保存天数": 4,
     "直播hls流故障转移-help":"true:hls服务器故障时,使用其他",
     "直播hls流故障转移": true,
     "启动时显示ip":true,
     "几秒后重载-help":"最少间隔60s,-1时不重载",
     "几秒后重载":60,
-    "下播后不记录人气观看人数":true
+    "下播后不记录人气观看人数":true,
+    "debug模式-help":"在/debug/pprof/启用调试",
+    "debug模式":false
 }
\ No newline at end of file
index 77ca66609254bae197866b0a1a576a856d68c266..9f9bb43a38b1a254f8ec043825f238d6723b4770 100644 (file)
@@ -1,48 +1,9 @@
 package main
 
-import ( // "runtime"
-       // "runtime/pprof"
-       // "net/http"
-       // _ "net/http/pprof"
-       // "github.com/skratchdot/open-golang/open"
+import (
        q "github.com/qydysky/bili_danmu"
 )
 
 func main() {
-       // go func() {
-       //      http.ListenAndServe("0.0.0.0:8899", nil)
-       // }()
-       // defer func(){
-       //      open.Run("http://127.0.0.1:8899/debug/pprof/goroutine?debug=2")
-       //      time.Sleep(time.Duration(3)*time.Second)
-       // }()
-       // go func() {
-       // for {
-       //      View()
-       //      time.Sleep(time.Duration(60) * time.Second)
-       //      {
-       //              debug.FreeOSMemory()
-       //      }
-       // }
-       // }()
-       // f, err := os.OpenFile("cpu.pprof", os.O_RDWR|os.O_CREATE, 0644)
-       // if err != nil {
-       //     log.Fatal(err)
-       // }
-       // defer f.Close()
-       // pprof.StartCPUProfile(f)
-
        q.Start()
-
-       // pprof.StopCPUProfile()
 }
-
-// func View() {
-// var memStats runtime.MemStats
-// runtime.ReadMemStats(&memStats)
-// fmt.Printf("=====\n")
-// fmt.Printf("总内存:%v MB\n",memStats.Alloc/1024e2/8)
-// fmt.Printf("GC次数:%v \n",memStats.NumGC)
-// fmt.Printf("堆 :%v %v MB\n",memStats.HeapInuse/1024e2/8,(memStats.HeapIdle - memStats.HeapReleased)/1024e2/8)
-// fmt.Printf("=====\n")
-// }