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.

40 lines
851 B

  1. package core
  2. import (
  3. "os"
  4. "runtime/pprof"
  5. ctypes "github.com/tendermint/tendermint/rpc/core/types"
  6. )
  7. var profFile *os.File
  8. func UnsafeStartCPUProfiler(filename string) (*ctypes.ResultUnsafeProfile, error) {
  9. var err error
  10. profFile, err = os.Create(filename)
  11. if err != nil {
  12. return nil, err
  13. }
  14. err = pprof.StartCPUProfile(profFile)
  15. if err != nil {
  16. return nil, err
  17. }
  18. return &ctypes.ResultUnsafeProfile{}, nil
  19. }
  20. func UnsafeStopCPUProfiler() (*ctypes.ResultUnsafeProfile, error) {
  21. pprof.StopCPUProfile()
  22. profFile.Close()
  23. return &ctypes.ResultUnsafeProfile{}, nil
  24. }
  25. func UnsafeWriteHeapProfile(filename string) (*ctypes.ResultUnsafeProfile, error) {
  26. memProfFile, err := os.Create(filename)
  27. if err != nil {
  28. return nil, err
  29. }
  30. pprof.WriteHeapProfile(memProfFile)
  31. memProfFile.Close()
  32. return &ctypes.ResultUnsafeProfile{}, nil
  33. }