From 2d55ed23af80ba0c3bd4c76b5c925a7a3ef3e57c Mon Sep 17 00:00:00 2001 From: Igor Mandrigin Date: Fri, 2 Feb 2018 13:23:47 +0100 Subject: [PATCH] Remove unused `helpers` package with single subpackage. --- lib/library.go | 2 +- .../profiling.go => profiling/cpu.go | 28 ++--------------- profiling/heap.go | 30 +++++++++++++++++++ .../profiling => profiling}/profiling_test.go | 0 4 files changed, 34 insertions(+), 26 deletions(-) rename helpers/profiling/profiling.go => profiling/cpu.go (52%) create mode 100644 profiling/heap.go rename {helpers/profiling => profiling}/profiling_test.go (100%) diff --git a/lib/library.go b/lib/library.go index a991f68ab..3c6ccf4ec 100644 --- a/lib/library.go +++ b/lib/library.go @@ -10,7 +10,7 @@ import ( "github.com/status-im/status-go/geth/common" "github.com/status-im/status-go/geth/log" "github.com/status-im/status-go/geth/params" - "github.com/status-im/status-go/helpers/profiling" + "github.com/status-im/status-go/profiling" "gopkg.in/go-playground/validator.v9" ) diff --git a/helpers/profiling/profiling.go b/profiling/cpu.go similarity index 52% rename from helpers/profiling/profiling.go rename to profiling/cpu.go index 2df43bc30..745b54ee5 100644 --- a/helpers/profiling/profiling.go +++ b/profiling/cpu.go @@ -3,21 +3,13 @@ package profiling import ( "os" "path/filepath" - "runtime" "runtime/pprof" ) -const ( - // CPUFilename is a filename in which the CPU profiling is stored. - CPUFilename = "status_cpu.prof" - // MemFilename is a filename in which the memory profiling is stored. - MemFilename = "status_mem.prof" -) +// CPUFilename is a filename in which the CPU profiling is stored. +const CPUFilename = "status_cpu.prof" -var ( - cpuFile *os.File - memFile *os.File -) +var cpuFile *os.File // StartCPUProfile enables CPU profiling for the current process. While profiling, // the profile will be buffered and written to the file in folder dataDir. @@ -41,17 +33,3 @@ func StopCPUProfile() error { pprof.StopCPUProfile() return cpuFile.Close() } - -// WriteHeapFile writes heap memory to the file. -func WriteHeapFile(dataDir string) error { - if memFile == nil { - var err error - memFile, err = os.Create(filepath.Join(dataDir, MemFilename)) - if err != nil { - return err - } - defer memFile.Close() - } - runtime.GC() - return pprof.WriteHeapProfile(memFile) -} diff --git a/profiling/heap.go b/profiling/heap.go new file mode 100644 index 000000000..fee5ab017 --- /dev/null +++ b/profiling/heap.go @@ -0,0 +1,30 @@ +package profiling + +import ( + "os" + "path/filepath" + "runtime" + "runtime/pprof" +) + +// MemFilename is a filename in which the memory profiling is stored. +const MemFilename = "status_mem.prof" + +var memFile *os.File + +// WriteHeapFile writes heap memory to the file. +func WriteHeapFile(dataDir string) error { + var err error + + if memFile == nil { + memFile, err = os.Create(filepath.Join(dataDir, MemFilename)) + if err != nil { + return err + } + defer memFile.Close() //nolint: errcheck + } + runtime.GC() + err = pprof.WriteHeapProfile(memFile) + + return err +} diff --git a/helpers/profiling/profiling_test.go b/profiling/profiling_test.go similarity index 100% rename from helpers/profiling/profiling_test.go rename to profiling/profiling_test.go