StartProfile initializes the CPU and memory profile, if specified.
(cpuprofile, memprofile string)
| 31 | |
| 32 | // StartProfile initializes the CPU and memory profile, if specified. |
| 33 | func StartProfile(cpuprofile, memprofile string) error { |
| 34 | if cpuprofile != "" { |
| 35 | f, err := os.Create(cpuprofile) |
| 36 | if err != nil { |
| 37 | log.WithField("file", cpuprofile).WithError(err).Error("failed to create CPU profile file") |
| 38 | return err |
| 39 | } |
| 40 | log.WithField("file", cpuprofile).Info("writing CPU profiling to file") |
| 41 | prof.cpu = f |
| 42 | pprof.StartCPUProfile(prof.cpu) |
| 43 | } |
| 44 | |
| 45 | if memprofile != "" { |
| 46 | f, err := os.Create(memprofile) |
| 47 | if err != nil { |
| 48 | log.WithField("file", memprofile).WithError(err).Error("failed to create memory profile file") |
| 49 | return err |
| 50 | } |
| 51 | log.WithField("file", memprofile).WithError(err).Info("writing memory profiling to file") |
| 52 | prof.mem = f |
| 53 | runtime.MemProfileRate = 4096 |
| 54 | } |
| 55 | return nil |
| 56 | } |
| 57 | |
| 58 | // StopProfile closes the CPU and memory profiles if they are running. |
| 59 | func StopProfile() { |