zhangmeng
2020-01-11 c46b023d7a165d4b1a32f2b6fdc00d66334597f1
main.go
@@ -3,8 +3,13 @@
import (
   "analysis/logo"
   "analysis/util"
   "fmt"
   "os/exec"
   "os/signal"
   "runtime/debug"
   "strconv"
   "syscall"
   "time"
   "analysis/app/master"
   "analysis/app/slave"
@@ -13,8 +18,6 @@
   "flag"
   "os"
   "basic.com/valib/gogpu.git"
   // "net/http"
   // _ "net/http/pprof"
)
@@ -29,8 +32,6 @@
   ruleIPC string
   configPath string
   showConsole bool
)
const (
@@ -39,8 +40,8 @@
)
func init() {
   flag.StringVar(&role, "role", roleMaster, "run process role master/slave, default single")
   flag.StringVar(&runType, "sdk", util.FeatAll, "run sdk type, face/facedetect/facecompare/yolo,etc.")
   flag.StringVar(&role, "role", roleMaster, "run process role master/slave, default master")
   flag.StringVar(&runType, "sdk", util.FeatAll, "run sdk type, facedetect/yolo,etc.")
   flag.StringVar(&id, "id", util.FakeSdkID, "sdk id as ipc label")
   flag.StringVar(&configPath, util.ConfigPath, "", "sdk config file path")
@@ -49,8 +50,6 @@
   flag.BoolVar(&shm, util.SHM, false, "use shm for performance")
   flag.IntVar(&gpu, util.GPU, -1, "gpu index")
   flag.BoolVar(&showConsole, "log-console", false, "log show console, only for debug")
   // 指定获取配置信息从sqlite,有最高优先级, master使用
   flag.StringVar(&util.FSI.IP, util.FetchSrvIP, util.FSI.IP, "fetch server ip, like camera info")
@@ -71,9 +70,7 @@
      logo.Config(file, 500, 3, 30)
      logo.Infoln("START LOGGER FILE: ", file)
   }
   if showConsole {
      logo.ShowConsole()
   }
   logo.ShowConsole()
}
func setParamters() {
@@ -95,12 +92,6 @@
func main() {
   indices := gogpu.RankGPU()
   if len(indices) == 0 {
      logo.Errorln("there is no gpu for valid")
      return
   }
   util.InitConfig()
   flag.Parse()
@@ -120,16 +111,19 @@
   ret := false
   if role == roleMaster {
      defer dump(util.LogFile + "_dump_" + time.Now().Format("20060102150405"))
      setParamters()
      ret = master.Run(ctx, configPath, "./libcomm.so")
      ret = master.Run(ctx, "./libcomm.so", configPath)
   } else if role == roleSlave {
      ret = slave.Run(ctx, configPath, runType, id, gpu, shm)
   } else if role == "test" {
      ret = slave.TwoPluginConflict("./libcomm.so", "./zconf/Yolo.json")
   }
   if ret {
      c := make(chan os.Signal, 1)
      signal.Notify(c, os.Interrupt, os.Kill)
      signal.Notify(c, os.Interrupt, os.Kill, syscall.SIGTERM)
      <-c
   }
@@ -149,3 +143,26 @@
// viper.AddConfigPath("./")
// envString := ""
func dump(dumpFile string) {
   dumpErr := recover()
   if dumpErr == nil {
      return
   }
   f, err := os.Create(dumpFile)
   if err != nil {
      return
   }
   f.WriteString(fmt.Sprintf("panic:\r\n%v", dumpErr))
   f.WriteString("\r\n\nstack:\r\n")
   f.WriteString(string(debug.Stack()))
   f.Close()
   //////////////////////////////////////////////
   // restart master
   cmd := exec.Command(os.Args[0], os.Args[1:]...)
   cmd.Stdout = os.Stdout
   cmd.Stderr = os.Stderr
   cmd.Start()
}