StartCPUProfile turns on CPU profiling, writing to the given file.
(file string)
| 78 | |
| 79 | // StartCPUProfile turns on CPU profiling, writing to the given file. |
| 80 | func (h *HandlerT) StartCPUProfile(file string) error { |
| 81 | h.mu.Lock() |
| 82 | defer h.mu.Unlock() |
| 83 | if h.cpuW != nil { |
| 84 | return errors.New("CPU profiling already in progress") |
| 85 | } |
| 86 | f, err := os.Create(expandHome(file)) |
| 87 | if err != nil { |
| 88 | return err |
| 89 | } |
| 90 | if err := pprof.StartCPUProfile(f); err != nil { |
| 91 | f.Close() |
| 92 | return err |
| 93 | } |
| 94 | h.cpuW = f |
| 95 | h.cpuFile = file |
| 96 | log.Info("CPU profiling started", "dump", h.cpuFile) |
| 97 | return nil |
| 98 | } |
| 99 | |
| 100 | // StopCPUProfile stops an ongoing CPU profile. |
| 101 | func (h *HandlerT) StopCPUProfile() error { |