From fcfd4fcc06b648207f5d57c48cffc2c79641949b Mon Sep 17 00:00:00 2001 From: qydysky <32743305+qydysky@users.noreply.github.com> Date: Tue, 28 Feb 2023 20:52:21 +0800 Subject: [PATCH] =?utf8?q?Add=20=E6=B7=BB=E5=8A=A0debug=E6=A8=A1=E5=BC=8F?= =?utf8?q?=20=E9=BB=98=E8=AE=A4=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- Reply/F.go | 15 +++++++++++++- Reply/stream.go | 19 ++++++++--------- demo/config/config_K_v.json | 6 ++++-- demo/main.go | 41 +------------------------------------ 4 files changed, 28 insertions(+), 53 deletions(-) diff --git a/Reply/F.go b/Reply/F.go index 1de5d36..6019618 100644 --- a/Reply/F.go +++ b/Reply/F.go @@ -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) diff --git a/Reply/stream.go b/Reply/stream.go index 7a5478b..94e1ce3 100644 --- a/Reply/stream.go +++ b/Reply/stream.go @@ -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 { diff --git a/demo/config/config_K_v.json b/demo/config/config_K_v.json index 2283710..e1087f0 100644 --- a/demo/config/config_K_v.json +++ b/demo/config/config_K_v.json @@ -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, @@ -104,5 +104,7 @@ "启动时显示ip":true, "几秒后重载-help":"最少间隔60s,-1时不重载", "几秒后重载":60, - "下播后不记录人气观看人数":true + "下播后不记录人气观看人数":true, + "debug模式-help":"在/debug/pprof/启用调试", + "debug模式":false } \ No newline at end of file diff --git a/demo/main.go b/demo/main.go index 77ca666..9f9bb43 100644 --- a/demo/main.go +++ b/demo/main.go @@ -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") -// } -- 2.39.2