stopProfiling stops profiling CPU and memory usage. It writes memory profile to the file path specified in HELM_PPROF_MEM_PROFILE environment variable.
()
| 58 | // It writes memory profile to the file path specified in HELM_PPROF_MEM_PROFILE |
| 59 | // environment variable. |
| 60 | func stopProfiling() error { |
| 61 | errs := []error{} |
| 62 | |
| 63 | // Stop CPU profiling if it was started |
| 64 | if cpuProfileFile != nil { |
| 65 | pprof.StopCPUProfile() |
| 66 | err := cpuProfileFile.Close() |
| 67 | if err != nil { |
| 68 | errs = append(errs, err) |
| 69 | } |
| 70 | cpuProfileFile = nil |
| 71 | } |
| 72 | |
| 73 | if memProfilePath != "" { |
| 74 | f, err := os.Create(memProfilePath) |
| 75 | if err != nil { |
| 76 | errs = append(errs, err) |
| 77 | } |
| 78 | defer f.Close() |
| 79 | |
| 80 | runtime.GC() // get up-to-date statistics |
| 81 | if err := pprof.WriteHeapProfile(f); err != nil { |
| 82 | errs = append(errs, err) |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | if err := errors.Join(errs...); err != nil { |
| 87 | return fmt.Errorf("error(s) while stopping profiling: %w", err) |
| 88 | } |
| 89 | |
| 90 | return nil |
| 91 | } |
no test coverage detected
searching dependent graphs…