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.

34 lines
543 B

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