mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 10:06:24 +05:00
Upgraded MemoryProfiling api + tests
This commit is contained in:
committed by
Dan Christian Bogos
parent
2541fd1cd2
commit
78a9b724ed
@@ -21,6 +21,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
package v1
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/rpc"
|
||||
"net/rpc/jsonrpc"
|
||||
"os"
|
||||
@@ -46,18 +47,27 @@ var (
|
||||
testCoreSv1LoadCofig,
|
||||
testCoreSv1InitDataDB,
|
||||
testCoreSv1InitStorDB,
|
||||
testCoreSv1StartEngineByExecWithCPUProfiling,
|
||||
testCoreSv1RPCConn,
|
||||
testCoreSv1StartCPUProfilingErrorAlreadyStarted,
|
||||
testCoreSv1Sleep,
|
||||
testCoreSv1StopCPUProfiling,
|
||||
testCoreSv1KillEngine,
|
||||
/*
|
||||
testCoreSv1StartEngineByExecWithCPUProfiling,
|
||||
testCoreSv1RPCConn,
|
||||
testCoreSv1StartCPUProfilingErrorAlreadyStarted,
|
||||
testCoreSv1Sleep,
|
||||
testCoreSv1StopCPUProfiling,
|
||||
testCoreSv1KillEngine,
|
||||
|
||||
*/
|
||||
testCoreSv1StartEngine,
|
||||
testCoreSv1RPCConn,
|
||||
testCoreSv1StopCPUProfilingBeforeStart,
|
||||
testCoreSv1StartCPUProfiling,
|
||||
/*
|
||||
testCoreSv1StopCPUProfilingBeforeStart,
|
||||
testCoreSv1StartCPUProfiling,
|
||||
testCoreSv1Sleep,
|
||||
testCoreSv1StopCPUProfiling,
|
||||
|
||||
*/
|
||||
testCoreSv1StartMemoryProfiling,
|
||||
testCoreSv1Sleep,
|
||||
testCoreSv1StopCPUProfiling,
|
||||
testCoreSv1StopMemoryProfiling,
|
||||
testCoreSv1KillEngine,
|
||||
}
|
||||
)
|
||||
@@ -201,6 +211,51 @@ func testCoreSv1StopCPUProfiling(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func testCoreSv1StartMemoryProfiling(t *testing.T) {
|
||||
var reply string
|
||||
args := &utils.MemoryPrf{
|
||||
DirPath: argPath,
|
||||
Interval: 100 * time.Millisecond,
|
||||
NrFiles: 2,
|
||||
}
|
||||
if err := coreV1Rpc.Call(utils.CoreSv1StartMemoryProfiling,
|
||||
args, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if reply != utils.OK {
|
||||
t.Errorf("Unexpected reply returned")
|
||||
}
|
||||
}
|
||||
|
||||
func testCoreSv1StopMemoryProfiling(t *testing.T) {
|
||||
var reply string
|
||||
if err := coreV1Rpc.Call(utils.CoreSv1StopMemoryProfiling,
|
||||
new(utils.MemoryPrf), &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if reply != utils.OK {
|
||||
t.Errorf("Unexpected reply returned")
|
||||
}
|
||||
|
||||
for i := 1; i <= 2; i++ {
|
||||
file, err := os.Open(path.Join(argPath, fmt.Sprintf("mem%v.prof", i)))
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
//compare the size
|
||||
size, err := file.Stat()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
} else if size.Size() < int64(415) {
|
||||
t.Errorf("Size of MemoryProfile %v is lower that expected", size.Size())
|
||||
}
|
||||
//after we checked that CPUProfile was made successfully, can delete it
|
||||
if err := os.Remove(path.Join(argPath, fmt.Sprintf("mem%v.prof", i))); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testCoreSv1KillEngine(t *testing.T) {
|
||||
if err := engine.KillEngine(*waitRater); err != nil {
|
||||
t.Error(err)
|
||||
|
||||
@@ -131,6 +131,9 @@ func (cS *CoreService) StartMemoryProfiling(args *utils.MemoryPrf) (err error) {
|
||||
return utils.NewErrMandatoryIeMissing("Path")
|
||||
}
|
||||
cS.shdWg.Add(1)
|
||||
if cS.stopMemPrf == nil {
|
||||
cS.stopMemPrf = make(chan struct{})
|
||||
}
|
||||
go MemProfiling(args.DirPath, args.Interval, args.NrFiles, cS.shdWg, cS.stopMemPrf, cS.shdChan)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1519,6 +1519,7 @@ const (
|
||||
CoreSv1StartCPUProfiling = "CoreSv1.StartCPUProfiling"
|
||||
CoreSv1StopCPUProfiling = "CoreSv1.StopCPUProfiling"
|
||||
CoreSv1StartMemoryProfiling = "CoreSv1.StartMemoryProfiling"
|
||||
CoreSv1StopMemoryProfiling = "CoreSv1.StopMemoryProfiling"
|
||||
)
|
||||
|
||||
// RouteS APIs
|
||||
|
||||
Reference in New Issue
Block a user