浏览代码

新增pprof

dxc 1 年之前
父节点
当前提交
f85370235a
共有 2 个文件被更改,包括 19 次插入0 次删除
  1. 15 0
      pkg/debug/pprof.go
  2. 4 0
      transcoder.go

+ 15 - 0
pkg/debug/pprof.go

@@ -0,0 +1,15 @@
+package debug
+
+import (
+	"log"
+	"net/http"
+	_ "net/http/pprof"
+	"runtime"
+)
+
+// Debugpprof 性能调试工具
+func Debugpprof() {
+	runtime.SetMutexProfileFraction(100)
+	runtime.SetBlockProfileRate(100)
+	log.Println(http.ListenAndServe(":6060", nil))
+}

+ 4 - 0
transcoder.go

@@ -2,6 +2,7 @@ package main
 
 import (
 	"audio_transcoder/job"
+	"audio_transcoder/pkg/debug"
 	"flag"
 	"fmt"
 
@@ -11,6 +12,7 @@ import (
 
 	"github.com/zeromicro/go-zero/core/conf"
 	"github.com/zeromicro/go-zero/rest"
+	_ "net/http/pprof"
 )
 
 var configFile = flag.String("f", "etc/transcoder.yaml", "the config file")
@@ -30,6 +32,8 @@ func main() {
 	go job.AutoTranscoder(ctx)
 	//注册接口
 	handler.RegisterHandlers(server, ctx)
+	//启动性能监控工具
+	go debug.Debugpprof()
 
 	fmt.Printf("Starting server at %s:%d...\n", c.Host, c.Port)
 	server.Start()