| 651 | } |
| 652 | |
| 653 | func stopProfiling(cmd *cobra.Command) { |
| 654 | if cpuprofile != nil { |
| 655 | pprof.StopCPUProfile() |
| 656 | cpuprofile.Close() |
| 657 | cpuprofile = nil |
| 658 | } |
| 659 | |
| 660 | if memprofile != nil { |
| 661 | err := pprof.Lookup("heap").WriteTo(memprofile, 0) |
| 662 | if err != nil { |
| 663 | fmt.Fprintf(cmd.ErrOrStderr(), "bench: could not write mem profile") |
| 664 | } |
| 665 | memprofile.Close() |
| 666 | memprofile = nil |
| 667 | } |
| 668 | |
| 669 | if blockprofile != nil { |
| 670 | err := pprof.Lookup("block").WriteTo(blockprofile, 0) |
| 671 | if err != nil { |
| 672 | fmt.Fprintf(cmd.ErrOrStderr(), "bench: could not write block profile") |
| 673 | } |
| 674 | blockprofile.Close() |
| 675 | blockprofile = nil |
| 676 | runtime.SetBlockProfileRate(0) |
| 677 | } |
| 678 | } |
| 679 | |
| 680 | // benchResults represents the performance results of the benchmark and is thread-safe. |
| 681 | type benchResults struct { |