You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
534 B

  1. package util
  2. import (
  3. "os"
  4. "runtime/pprof"
  5. "github.com/chrislusf/seaweedfs/weed/glog"
  6. )
  7. func SetupProfiling(cpuProfile, memProfile string) {
  8. if cpuProfile != "" {
  9. f, err := os.Create(cpuProfile)
  10. if err != nil {
  11. glog.Fatal(err)
  12. }
  13. pprof.StartCPUProfile(f)
  14. defer pprof.StopCPUProfile()
  15. OnInterrupt(func() {
  16. pprof.StopCPUProfile()
  17. })
  18. }
  19. if memProfile != "" {
  20. f, err := os.Create(memProfile)
  21. if err != nil {
  22. glog.Fatal(err)
  23. }
  24. OnInterrupt(func() {
  25. pprof.WriteHeapProfile(f)
  26. f.Close()
  27. })
  28. }
  29. }