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.

32 lines
503 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. OnInterrupt(func() {
  15. pprof.StopCPUProfile()
  16. })
  17. }
  18. if memProfile != "" {
  19. f, err := os.Create(memProfile)
  20. if err != nil {
  21. glog.Fatal(err)
  22. }
  23. OnInterrupt(func() {
  24. pprof.WriteHeapProfile(f)
  25. f.Close()
  26. })
  27. }
  28. }