diff --git a/main.go b/main.go index a20d864..c2fce8b 100644 --- a/main.go +++ b/main.go @@ -3,6 +3,17 @@ package main +import ( + "log" +) + func main() { - run() + err := run() + if err != nil { + if err.Error() == "ErrNoAlgoSelected" { + return + } + + log.Fatal(err) + } } diff --git a/run.go b/run.go index f0dea37..1d9f29c 100644 --- a/run.go +++ b/run.go @@ -4,6 +4,7 @@ package main import ( + "errors" "flag" "log" "os" @@ -17,7 +18,9 @@ var version = "development" var ( - cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file") + // ref: https://go.dev/blog/pprof. + cpuprofile = flag.String("cpuprofile", "", "write cpu profile to this file") + memprofile = flag.String("memprofile", "", "write memory profile to this 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)") @@ -33,7 +36,8 @@ c2SOMAT3A = flag.Bool("c2somat3a", false, "run CEC2020 version of the SOMA Team-to-Team Adaptive (T3A)") ) -func run() { +// nolint: gocognit +func run() error { log.Println("starting math-optim version", "'"+version+"'") flag.Parse() @@ -41,12 +45,12 @@ func run() { if *cpuprofile != "" { f, err := os.Create(*cpuprofile) if err != nil { - log.Fatal(err) + return err } err = pprof.StartCPUProfile(f) if err != nil { - log.Fatal(err) + return err } defer pprof.StopCPUProfile() @@ -56,7 +60,7 @@ func run() { if !*jDE && !*c2jDE && !*c2SOMAT3A && !*sHC && !*rS { log.Println("at least one algo needs to be specified, exiting...") - return + return errors.New("ErrNoAlgoSelected") } var wg sync.WaitGroup @@ -116,6 +120,20 @@ func run() { report.SaveAndPrint(*doPrint) + if *memprofile != "" { + f, err := os.Create(*memprofile) + if err != nil { + return err + } + + err = pprof.WriteHeapProfile(f) + if err != nil { + return err + } + } + log.Println("looks like we're done") log.Println("run an equivalent of `pdflatex -clean -shell-escape -interaction=nonstopmode ./report.tex` to get a pdf") + + return nil } diff --git a/run_test.go b/run_test.go index ba080ff..7b1db10 100644 --- a/run_test.go +++ b/run_test.go @@ -23,5 +23,12 @@ func TestRun(t *testing.T) { t.Errorf("failed to not run jDE: %q", err) } - run() + err := run() + if err != nil { + if err.Error() == "ErrNoAlgoSelected" { + return + } + + t.Error(err) + } }