StartCPUProfile turns on CPU profiling, writing to the given file.
(file string)
| 56 | |
| 57 | // StartCPUProfile turns on CPU profiling, writing to the given file. |
| 58 | func (h *HandlerT) StartCPUProfile(file string) error { |
| 59 | h.mu.Lock() |
| 60 | defer h.mu.Unlock() |
| 61 | if h.cpuW != nil { |
| 62 | return errors.New("CPU profiling already in progress") |
| 63 | } |
| 64 | f, err := os.Create(file) |
| 65 | if err != nil { |
| 66 | return err |
| 67 | } |
| 68 | if err := pprof.StartCPUProfile(f); err != nil { |
| 69 | f.Close() |
| 70 | return err |
| 71 | } |
| 72 | h.cpuW = f |
| 73 | h.cpuFile = file |
| 74 | log.Info("CPU profiling started", "dump", h.cpuFile) |
| 75 | return nil |
| 76 | } |
| 77 | |
| 78 | // StopCPUProfile stops an ongoing CPU profile. |
| 79 | func (h *HandlerT) StopCPUProfile() error { |