Finished adding final_memprof file in stop api

This commit is contained in:
porosnicuadrian
2021-07-08 09:23:55 +03:00
committed by Dan Christian Bogos
parent 5daad44e32
commit 7bea1b2697
6 changed files with 24 additions and 14 deletions

View File

@@ -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
}
@@ -70,13 +72,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) {
@@ -187,6 +188,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
}
@@ -196,7 +198,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
}

View File

@@ -40,6 +40,7 @@ func TestNewCoreService(t *testing.T) {
shdChan := utils.NewSyncedChan()
stopMemPrf := make(chan struct{})
expected := &CoreService{
fileMEM: "/tmp",
shdWg: shdWg,
shdChan: shdChan,
stopMemPrf: stopMemPrf,
@@ -47,7 +48,7 @@ func TestNewCoreService(t *testing.T) {
CapsStats: sts,
}
rcv := NewCoreService(cfgDflt, caps, nil, stopchan, shdWg, stopMemPrf, shdChan)
rcv := NewCoreService(cfgDflt, caps, nil,"/tmp", stopchan, shdWg, stopMemPrf, shdChan)
if !reflect.DeepEqual(expected, rcv) {
t.Errorf("Expected %+v, received %+v", utils.ToJSON(expected), utils.ToJSON(rcv))
}
@@ -62,7 +63,7 @@ func TestCoreServiceStatus(t *testing.T) {
caps := engine.NewCaps(1, utils.MetaBusy)
stopChan := make(chan struct{}, 1)
cores := NewCoreService(cfgDflt, caps, nil, stopChan, nil, nil, nil)
cores := NewCoreService(cfgDflt, caps, nil,"/tmp", stopChan, nil, nil, nil)
args := &utils.TenantWithAPIOpts{
Tenant: "cgrates.org",
APIOpts: map[string]interface{}{},