From b057552dff6d40fcc7bdbc1bdd77fb700b03767d Mon Sep 17 00:00:00 2001 From: porosnicuadrian Date: Tue, 29 Jun 2021 11:15:14 +0300 Subject: [PATCH] Fixed cpuprof apis --- apis/cores.go | 8 +++++--- apis/cores_it_test.go | 6 +++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/apis/cores.go b/apis/cores.go index f31489b36..4b218b8a4 100644 --- a/apis/cores.go +++ b/apis/cores.go @@ -16,6 +16,7 @@ along with this program. If not, see package apis import ( + "path" "time" "github.com/cgrates/birpc/context" @@ -51,15 +52,16 @@ func (cS *CoreSv1) Shutdown(_ *context.Context, _ *utils.CGREvent, reply *string } // StartCPUProfiling is used to start CPUProfiling in the given path -func (cS *CoreSv1) StartCPUProfiling(_ *context.Context, args string, reply *string) error { - if err := cS.cS.StartCPUProfiling(args); err != nil { +func (cS *CoreSv1) StartCPUProfiling(_ *context.Context, dirPath string, reply *string) error { + if err := cS.cS.StartCPUProfiling(path.Join(dirPath, utils.CpuPathCgr)); err != nil { return err } *reply = utils.OK return nil } -// StopCPUProfiling is used to stop CPUProfiling in the given path +// StopCPUProfiling is used to stop CPUProfiling. The file should be written on the path +// where the CPUProfiling already started func (cS *CoreSv1) StopCPUProfiling(_ *context.Context, _ string, reply *string) error { if err := cS.cS.StopCPUProfiling(); err != nil { return err diff --git a/apis/cores_it_test.go b/apis/cores_it_test.go index 1049d6a14..93415de8e 100644 --- a/apis/cores_it_test.go +++ b/apis/cores_it_test.go @@ -63,7 +63,7 @@ var ( ) func TestCoreItTests(t *testing.T) { - argPath = "/tmp/cpu.prof" + argPath = "/tmp" switch *dbType { case utils.MetaInternal: coreItDirPath = "all2" @@ -163,7 +163,7 @@ func testCoreItStopCPUProfiling(t *testing.T) { } else if reply != utils.OK { t.Errorf("Unexpected reply returned") } - file, err := os.Open(argPath) + file, err := os.Open(path.Join(argPath, utils.CpuPathCgr)) if err != nil { t.Error(err) } @@ -177,7 +177,7 @@ func testCoreItStopCPUProfiling(t *testing.T) { t.Errorf("Size of CPUProfile %v is lower that expected", size.Size()) } //after we checked that CPUProfile was made successfully, can delete it - if err := os.Remove(argPath); err != nil { + if err := os.Remove(path.Join(argPath, utils.CpuPathCgr)); err != nil { t.Error(err) } }