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.

45 lines
989 B

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