mv most of profiling logic to profile.go
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
cf61dd4795
commit
adfba66f38
46
profile.go
Normal file
46
profile.go
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
// Copyright 2023 wanderer <a_mirre at utb dot cz>
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"runtime/pprof"
|
||||||
|
)
|
||||||
|
|
||||||
|
// profileCPU checks whether CPU profiling was requested and if so, enables it.
|
||||||
|
// NOTE: deferred pprof.StopCPUProfile() needs to be called at the call site of
|
||||||
|
// this function, otherwise the profiling would end when this function goes out
|
||||||
|
// of scope.
|
||||||
|
func profileCPU(prof *string) error {
|
||||||
|
if *prof != "" {
|
||||||
|
f, err := os.Create(*prof)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = pprof.StartCPUProfile(f)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// profileMem checks if memory profiling was requested and if so, enables it.
|
||||||
|
func profileMem(prof *string) error {
|
||||||
|
if *prof != "" {
|
||||||
|
f, err := os.Create(*prof)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = pprof.WriteHeapProfile(f)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
33
run.go
33
run.go
@ -7,7 +7,6 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"flag"
|
"flag"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
|
||||||
"runtime/pprof"
|
"runtime/pprof"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
@ -36,26 +35,19 @@ var (
|
|||||||
c2SOMAT3A = flag.Bool("c2somat3a", false, "run CEC2020 version of the SOMA Team-to-Team Adaptive (T3A)")
|
c2SOMAT3A = flag.Bool("c2somat3a", false, "run CEC2020 version of the SOMA Team-to-Team Adaptive (T3A)")
|
||||||
)
|
)
|
||||||
|
|
||||||
// nolint: gocognit
|
|
||||||
func run() error {
|
func run() error {
|
||||||
log.Println("starting math-optim version", "'"+version+"'")
|
log.Println("starting math-optim version", "'"+version+"'")
|
||||||
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
if *cpuprofile != "" {
|
err := profileCPU(cpuprofile)
|
||||||
f, err := os.Create(*cpuprofile)
|
if err != nil {
|
||||||
if err != nil {
|
return err
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = pprof.StartCPUProfile(f)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
defer pprof.StopCPUProfile()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// see profile.go on why we're calling this here.
|
||||||
|
defer pprof.StopCPUProfile()
|
||||||
|
|
||||||
if *generate {
|
if *generate {
|
||||||
if !*jDE && !*c2jDE && !*c2SOMAT3A && !*sHC && !*rS {
|
if !*jDE && !*c2jDE && !*c2SOMAT3A && !*sHC && !*rS {
|
||||||
log.Println("at least one algo needs to be specified, exiting...")
|
log.Println("at least one algo needs to be specified, exiting...")
|
||||||
@ -120,16 +112,9 @@ func run() error {
|
|||||||
|
|
||||||
report.SaveAndPrint(*doPrint)
|
report.SaveAndPrint(*doPrint)
|
||||||
|
|
||||||
if *memprofile != "" {
|
err = profileMem(memprofile)
|
||||||
f, err := os.Create(*memprofile)
|
if err != nil {
|
||||||
if err != nil {
|
return err
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = pprof.WriteHeapProfile(f)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Println("looks like we're done")
|
log.Println("looks like we're done")
|
||||||
|
Loading…
Reference in New Issue
Block a user