| 222 | } |
| 223 | |
| 224 | func setupProfiling() { |
| 225 | if traceFile != "" { |
| 226 | log.Info("setup trace profile: %s", traceFile) |
| 227 | f, err := os.Create(traceFile) |
| 228 | if err != nil { |
| 229 | log.Fatal("could not create trace profile: %s", err) |
| 230 | } |
| 231 | trace.Start(f) |
| 232 | } |
| 233 | if memProfile != "" { |
| 234 | log.Info("setup mem profile: %s", memProfile) |
| 235 | var err error |
| 236 | memFile, err = os.Create(memProfile) |
| 237 | if err != nil { |
| 238 | log.Fatal("could not create memory profile: %s", err) |
| 239 | } |
| 240 | } |
| 241 | if cpuProfile != "" { |
| 242 | log.Info("setup cpu profile: %s", cpuProfile) |
| 243 | if f, err := os.Create(cpuProfile); err != nil { |
| 244 | log.Fatal("%s", err) |
| 245 | } else if err := pprof.StartCPUProfile(f); err != nil { |
| 246 | log.Fatal("%s", err) |
| 247 | } |
| 248 | } |
| 249 | } |
| 250 | |
| 251 | func setupSignals() { |
| 252 | sigChan = make(chan os.Signal, 1) |