mirror of
https://github.com/status-im/status-go.git
synced 2025-01-11 15:14:52 +00:00
e0eb737c51
* fix(TestProfilingCPU)_: enable run with -count=2 * fix(TestProfilingMem)_: enable run with -count=2 * fix(zaputil)_: register encoder only once * fix(timesource)_: global variables override in tests * fix(TestClosingsqlDB)_: delete database from cache * fix(postgres/helpers)_: drop connections before dropping database * fix_: linter * chore_: remove redundant condition
35 lines
592 B
Go
35 lines
592 B
Go
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 func() {
|
|
memFile.Close() //nolint: errcheck
|
|
memFile = nil
|
|
}()
|
|
}
|
|
|
|
runtime.GC()
|
|
err = pprof.WriteHeapProfile(memFile)
|
|
|
|
return err
|
|
}
|