57 lines
1.2 KiB
Go
57 lines
1.2 KiB
Go
package core
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"runtime/pprof"
|
|
"strconv"
|
|
|
|
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
|
)
|
|
|
|
func UnsafeSetConfig(typ, key, value string) (*ctypes.ResultUnsafeSetConfig, error) {
|
|
switch typ {
|
|
case "string":
|
|
config.Set(key, value)
|
|
case "int":
|
|
val, err := strconv.Atoi(value)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("non-integer value found. key:%s; value:%s; err:%v", key, value, err)
|
|
}
|
|
config.Set(key, val)
|
|
case "bool":
|
|
switch value {
|
|
case "true":
|
|
config.Set(key, true)
|
|
case "false":
|
|
config.Set(key, false)
|
|
default:
|
|
return nil, fmt.Errorf("bool value must be true or false. got %s", value)
|
|
}
|
|
default:
|
|
return nil, fmt.Errorf("Unknown type %s", typ)
|
|
}
|
|
return &ctypes.ResultUnsafeSetConfig{}, nil
|
|
}
|
|
|
|
var profFile *os.File
|
|
|
|
func UnsafeStartCPUProfiler(filename string) (*ctypes.ResultUnsafeCPUProfiler, error) {
|
|
var err error
|
|
profFile, err = os.Create(filename)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
err = pprof.StartCPUProfile(profFile)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &ctypes.ResultUnsafeCPUProfiler{}, nil
|
|
}
|
|
|
|
func UnsafeStopCPUProfiler() (*ctypes.ResultUnsafeCPUProfiler, error) {
|
|
pprof.StopCPUProfile()
|
|
profFile.Close()
|
|
return &ctypes.ResultUnsafeCPUProfiler{}, nil
|
|
}
|