mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Started apis for CpuProfiling
This commit is contained in:
committed by
Dan Christian Bogos
parent
1449d220b4
commit
2e7d3e7449
@@ -56,3 +56,21 @@ func (cS *CoreSv1) Sleep(arg *utils.DurationArgs, reply *string) error {
|
||||
*reply = utils.OK
|
||||
return nil
|
||||
}
|
||||
|
||||
// StartCPUProfiling is used to start CPUProfiling in the given path
|
||||
func (cS *CoreSv1) StartCPUProfiling(args, reply *string) error {
|
||||
if err := cS.cS.StartCPUProfiling(args); err != nil {
|
||||
return err
|
||||
}
|
||||
*reply = utils.OK
|
||||
return nil
|
||||
}
|
||||
|
||||
// StopCPUProfiling is used to stop CPUProfiling in the given path
|
||||
func (cS *CoreSv1) StopCPUProfiling(args, reply *string) error {
|
||||
if err := cS.cS.StopCPUProfiling(args); err != nil {
|
||||
return err
|
||||
}
|
||||
*reply = utils.OK
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -20,7 +20,9 @@ package cores
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"runtime"
|
||||
"runtime/pprof"
|
||||
|
||||
"github.com/cgrates/cgrates/config"
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
@@ -67,3 +69,33 @@ func (cS *CoreService) Status(arg *utils.TenantWithAPIOpts, reply *map[string]in
|
||||
*reply = response
|
||||
return
|
||||
}
|
||||
|
||||
// StartCPUProfiling is used to start CPUProfiling in the given path
|
||||
func (cS *CoreService) StartCPUProfiling(argPath *string) (err error) {
|
||||
if *argPath == utils.EmptyString {
|
||||
return utils.NewErrMandatoryIeMissing("Path")
|
||||
}
|
||||
f, err := os.Create(*argPath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not create CPU profile: %v", err)
|
||||
}
|
||||
if err := pprof.StartCPUProfile(f); err != nil {
|
||||
return fmt.Errorf("could not create CPU profile: %v", err)
|
||||
}
|
||||
defer f.Close()
|
||||
return
|
||||
}
|
||||
|
||||
// StopCPUProfiling is used to stop CPUProfiling in the given path
|
||||
func (cS *CoreService) StopCPUProfiling(argPath *string) (err error) {
|
||||
f, err := os.Create(*argPath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not create CPU profile: %v", err)
|
||||
}
|
||||
if err := pprof.StartCPUProfile(f); err != nil {
|
||||
// this means CPUProfiling is already active,so we can shut down now
|
||||
pprof.StopCPUProfile()
|
||||
return nil
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user