CPU profiling (#1371)

* Add cpuprofile flag
* Add notes to readme
This commit is contained in:
WithoutPants
2021-05-16 17:21:11 +10:00
committed by GitHub
parent bc9aa02835
commit 16fe21138f
5 changed files with 59 additions and 5 deletions

View File

@@ -5,6 +5,7 @@ import (
"fmt"
"os"
"path/filepath"
"runtime/pprof"
"sync"
"time"
@@ -55,6 +56,7 @@ func Initialize() *singleton {
}
initLog()
initProfiling(cfg.GetCPUProfilePath())
instance = &singleton{
Config: cfg,
@@ -92,6 +94,22 @@ func Initialize() *singleton {
return instance
}
func initProfiling(cpuProfilePath string) {
if cpuProfilePath == "" {
return
}
f, err := os.Create(cpuProfilePath)
if err != nil {
logger.Fatalf("unable to create cpu profile file: %s", err.Error())
}
logger.Infof("profiling to %s", cpuProfilePath)
// StopCPUProfile is defer called in main
pprof.StartCPUProfile(f)
}
func initFFMPEG() {
configDirectory := paths.GetStashHomeDirectory()
ffmpegPath, ffprobePath := ffmpeg.GetPaths(configDirectory)