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

     1  package main
     2  
     3  import (
     4  	"fmt"
     5  	"gitee.com/quant1x/engine/command"
     6  	"gitee.com/quant1x/engine/config"
     7  	"gitee.com/quant1x/gox/logger"
     8  	"gitee.com/quant1x/gox/runtime"
     9  	_ "net/http/pprof"
    10  	"os"
    11  	"runtime/pprof"
    12  	"time"
    13  )
    14  
    15  // 系统构建时传入的值
    16  // go build -ldflags "-X 'main.MinVersion=${version}'"
    17  
    18  var (
    19  	MinVersion = "1.0.0" // 应用版本号
    20  )
    21  
    22  var (
    23  	cpuProfile = "./cpu.pprof"
    24  	memProfile = "./mem.pprof"
    25  )
    26  
    27  // 更新日线数据工具
    28  func main() {
    29  	if config.PprofEnable() {
    30  		fCpu, err := os.Create(cpuProfile)
    31  		if err != nil {
    32  			logger.Fatal(err)
    33  		}
    34  		_ = pprof.StartCPUProfile(fCpu)
    35  		defer pprof.StopCPUProfile()
    36  	}
    37  	mainStart := time.Now()
    38  	defer func() {
    39  		runtime.CatchPanic("")
    40  		elapsedTime := time.Since(mainStart) / time.Millisecond
    41  		fmt.Printf("\n总耗时: %.3fs\n", float64(elapsedTime)/1000)
    42  	}()
    43  	// stock模块内的更新版本号
    44  	command.UpdateApplicationVersion(MinVersion)
    45  	runtime.GoMaxProcs()
    46  
    47  	// 命令字
    48  	rootCommand := command.GlobalFlags()
    49  	_ = rootCommand.Execute()
    50  	if config.PprofEnable() {
    51  		fMem, err := os.Create(memProfile)
    52  		if err != nil {
    53  			logger.Fatal(err)
    54  		}
    55  		_ = pprof.WriteHeapProfile(fMem)
    56  		_ = fMem.Close()
    57  	}
    58  }