run.go: add a way to profile program's cpu usage
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
set the flag `cpuprofile` to a file where the cpu profiling output should be saved. the output can then be read using: `go tool pprof math-optim <profiling output file`. ref: https://go.dev/blog/pprof
This commit is contained in:
parent
9dce419cfb
commit
a74ea8c8e4
18
run.go
18
run.go
@ -6,6 +6,8 @@ package main
|
||||
import (
|
||||
"flag"
|
||||
"log"
|
||||
"os"
|
||||
"runtime/pprof"
|
||||
"sync"
|
||||
|
||||
"git.dotya.ml/wanderer/math-optim/algo"
|
||||
@ -15,6 +17,8 @@ import (
|
||||
var version = "development"
|
||||
|
||||
var (
|
||||
cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file")
|
||||
|
||||
doPrint = flag.Bool("printreport", true, "print report.tex to console")
|
||||
generate = flag.Bool("generate", true, "run algos and generate plot pics/statistical tables (anew)")
|
||||
rS = flag.Bool("randomsearch", false, "run Random Search algorithm")
|
||||
@ -34,6 +38,20 @@ func run() {
|
||||
|
||||
flag.Parse()
|
||||
|
||||
if *cpuprofile != "" {
|
||||
f, err := os.Create(*cpuprofile)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
err = pprof.StartCPUProfile(f)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
defer pprof.StopCPUProfile()
|
||||
}
|
||||
|
||||
if *generate {
|
||||
if !*jDE && !*c2jDE && !*c2SOMAT3A && !*sHC && !*rS {
|
||||
log.Println("at least one algo needs to be specified, exiting...")
|
||||
|
Loading…
Reference in New Issue
Block a user