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.

51 lines
1.1 KiB

  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. if err := profFile.Close(); err != nil {
  27. return nil, err
  28. }
  29. return &ctypes.ResultUnsafeProfile{}, nil
  30. }
  31. func UnsafeWriteHeapProfile(filename string) (*ctypes.ResultUnsafeProfile, error) {
  32. memProfFile, err := os.Create(filename)
  33. if err != nil {
  34. return nil, err
  35. }
  36. if err := pprof.WriteHeapProfile(memProfFile); err != nil {
  37. return nil, err
  38. }
  39. if err := memProfFile.Close(); err != nil {
  40. return nil, err
  41. }
  42. return &ctypes.ResultUnsafeProfile{}, nil
  43. }