gitee.com/quant1x/engine@v1.8.4/config/config_profile.go (about)

     1  package config
     2  
     3  import (
     4  	"fmt"
     5  	"gitee.com/quant1x/gox/logger"
     6  	"net/http"
     7  	_ "net/http/pprof"
     8  )
     9  
    10  type PprofParameter struct {
    11  	Enable bool `yaml:"enable" default:"false"` // 是否开启go tool pprof
    12  	Port   int  `yaml:"port" default:"6060"`    // pprof web端口
    13  }
    14  
    15  // PprofEnable 获取配置中pprof开关
    16  func PprofEnable() bool {
    17  	return GlobalConfig.Runtime.Pprof.Enable
    18  }
    19  
    20  // StartPprof 启动性能分析工具
    21  func StartPprof() {
    22  	if !PprofEnable() {
    23  		return
    24  	}
    25  	go func() {
    26  		addr := fmt.Sprintf("localhost:%d", GlobalConfig.Runtime.Pprof.Port)
    27  		err := http.ListenAndServe(addr, nil)
    28  		logger.Info("启动pprof性能分析工具", err)
    29  	}()
    30  }