Setup initializes profiling and logging based on the CLI flags. It should be called as early as possible in the program.
(ctx *cli.Context)
| 80 | // Setup initializes profiling and logging based on the CLI flags. |
| 81 | // It should be called as early as possible in the program. |
| 82 | func Setup(ctx *cli.Context) error { |
| 83 | // profiling, tracing |
| 84 | runtime.MemProfileRate = ctx.GlobalInt(memprofilerateFlag.Name) |
| 85 | Handler.SetBlockProfileRate(ctx.GlobalInt(blockprofilerateFlag.Name)) |
| 86 | if traceFile := ctx.GlobalString(traceFlag.Name); traceFile != "" { |
| 87 | if err := Handler.StartGoTrace(traceFile); err != nil { |
| 88 | return err |
| 89 | } |
| 90 | } |
| 91 | if cpuFile := ctx.GlobalString(cpuprofileFlag.Name); cpuFile != "" { |
| 92 | if err := Handler.StartCPUProfile(cpuFile); err != nil { |
| 93 | return err |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | // pprof server |
| 98 | if ctx.GlobalBool(pprofFlag.Name) { |
| 99 | address := fmt.Sprintf("%s:%d", ctx.GlobalString(pprofAddrFlag.Name), ctx.GlobalInt(pprofPortFlag.Name)) |
| 100 | StartPProf(address) |
| 101 | } |
| 102 | return nil |
| 103 | } |
| 104 | |
| 105 | func StartPProf(address string) { |
| 106 | // Hook go-metrics into expvar on any /debug/metrics request, load all vars |
nothing calls this directly
no test coverage detected