Igor Sirotin e0eb737c51
fix_: enable tests to run with -count more than 1 (#5757)
* 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
2024-08-23 19:30:58 +00:00

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
}