mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Finished adding final_memprof file in stop api
This commit is contained in:
committed by
Dan Christian Bogos
parent
eddaa9a5a8
commit
2aeacca908
@@ -292,7 +292,7 @@ func testCoreItStartCPUProfiling(t *testing.T) {
|
||||
|
||||
func testCoreItSleep(t *testing.T) {
|
||||
args := &utils.DurationArgs{
|
||||
Duration: 500 * time.Millisecond,
|
||||
Duration: 600 * time.Millisecond,
|
||||
}
|
||||
var reply string
|
||||
if err := coreSBiRpc.Call(context.Background(), utils.CoreSv1Sleep,
|
||||
|
||||
@@ -346,9 +346,11 @@ func main() {
|
||||
|
||||
var cS *cores.CoreService
|
||||
var stopMemProf chan struct{}
|
||||
var memPrfDirForCores string
|
||||
if *memProfDir != utils.EmptyString {
|
||||
shdWg.Add(1)
|
||||
stopMemProf = make(chan struct{})
|
||||
memPrfDirForCores = *memProfDir
|
||||
go cores.MemProfiling(*memProfDir, *memProfInterval, *memProfNrFiles, shdWg, stopMemProf, shdChan)
|
||||
defer func() {
|
||||
if cS == nil {
|
||||
@@ -582,7 +584,8 @@ func main() {
|
||||
}
|
||||
|
||||
// init CoreSv1
|
||||
coreS := services.NewCoreService(cfg, caps, server, internalCoreSv1Chan, anz, cpuProfileFile, shdWg, stopMemProf, shdChan, srvDep)
|
||||
|
||||
coreS := services.NewCoreService(cfg, caps, server, internalCoreSv1Chan, anz, cpuProfileFile, memPrfDirForCores, shdWg, stopMemProf, shdChan, srvDep)
|
||||
shdWg.Add(1)
|
||||
if err := coreS.Start(); err != nil {
|
||||
fmt.Println(err)
|
||||
|
||||
@@ -34,7 +34,7 @@ import (
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
func NewCoreService(cfg *config.CGRConfig, caps *engine.Caps, file io.Closer, stopChan chan struct{},
|
||||
func NewCoreService(cfg *config.CGRConfig, caps *engine.Caps, fileCPU io.Closer, fileMem string, stopChan chan struct{},
|
||||
shdWg *sync.WaitGroup, stopMemPrf chan struct{}, shdChan *utils.SyncedChan) *CoreService {
|
||||
var st *engine.CapsStats
|
||||
if caps.IsLimited() && cfg.CoreSCfg().CapsStatsInterval != 0 {
|
||||
@@ -46,7 +46,8 @@ func NewCoreService(cfg *config.CGRConfig, caps *engine.Caps, file io.Closer, st
|
||||
shdChan: shdChan,
|
||||
cfg: cfg,
|
||||
CapsStats: st,
|
||||
fileCPU: file,
|
||||
fileCPU: fileCPU,
|
||||
fileMEM: fileMem,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,6 +57,7 @@ type CoreService struct {
|
||||
shdWg *sync.WaitGroup
|
||||
stopMemPrf chan struct{}
|
||||
shdChan *utils.SyncedChan
|
||||
fileMEM string
|
||||
fileCPU io.Closer
|
||||
fileMx sync.Mutex
|
||||
}
|
||||
@@ -73,13 +75,12 @@ func (cS *CoreService) Shutdown() {
|
||||
|
||||
// StopChanMemProf will stop the MemoryProfiling Channel in order to create
|
||||
// the final MemoryProfiling when CoreS subsystem will stop.
|
||||
func (cS *CoreService) StopChanMemProf() bool {
|
||||
func (cS *CoreService) StopChanMemProf() {
|
||||
if cS.stopMemPrf != nil {
|
||||
MemProfFile(cS.fileMEM)
|
||||
close(cS.stopMemPrf)
|
||||
cS.stopMemPrf = nil
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func StartCPUProfiling(path string) (file io.WriteCloser, err error) {
|
||||
@@ -190,6 +191,7 @@ func (cS *CoreService) StartMemoryProfiling(args *utils.MemoryPrf) (err error) {
|
||||
}
|
||||
cS.shdWg.Add(1)
|
||||
cS.stopMemPrf = make(chan struct{})
|
||||
cS.fileMEM = args.DirPath
|
||||
go MemProfiling(args.DirPath, args.Interval, args.NrFiles, cS.shdWg, cS.stopMemPrf, cS.shdChan)
|
||||
return
|
||||
}
|
||||
@@ -199,7 +201,7 @@ func (cS *CoreService) StopMemoryProfiling() (err error) {
|
||||
if cS.stopMemPrf == nil {
|
||||
return errors.New(" Memory Profiling is not started")
|
||||
}
|
||||
close(cS.stopMemPrf)
|
||||
cS.stopMemPrf = nil
|
||||
cS.fileMEM = path.Join(cS.fileMEM, utils.MemProfFileCgr)
|
||||
cS.StopChanMemProf()
|
||||
return
|
||||
}
|
||||
|
||||
@@ -44,6 +44,7 @@ func NewCoreService(cfg *config.CGRConfig, caps *engine.Caps, server *cores.Serv
|
||||
cfg: cfg,
|
||||
caps: caps,
|
||||
fileCpu: fileCpu,
|
||||
fileMem: fileMEM,
|
||||
server: server,
|
||||
anz: anz,
|
||||
srvDep: srvDep,
|
||||
@@ -61,6 +62,7 @@ type CoreService struct {
|
||||
stopMemPrf chan struct{}
|
||||
shdChan *utils.SyncedChan
|
||||
fileCpu io.Closer
|
||||
fileMem string
|
||||
cS *cores.CoreService
|
||||
rpc *apis.CoreSv1
|
||||
connChan chan birpc.ClientConnector
|
||||
|
||||
Reference in New Issue
Block a user