Skip to content

Commit

Permalink
Add cpu profiling option
Browse files Browse the repository at this point in the history
  • Loading branch information
devries committed Dec 3, 2023
1 parent 205ad6a commit 30aa414
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,40 @@ import (
"fmt"
"io"
"os"
"runtime/pprof"
"strconv"
"time"

"aoc/utils"

"github.com/spf13/pflag"
)

var RunAll bool
var DaySelected int
var PartSelected string
var CpuProfile string

func init() {
pflag.BoolVarP(&RunAll, "all", "a", false, "run all days")
pflag.IntVarP(&DaySelected, "day", "d", 0, "run specific day")
pflag.StringVarP(&PartSelected, "part", "p", "2", "run specific part (default 2)")
pflag.StringVar(&CpuProfile, "cpuprofile", "", "write cpu profile to `file`")
}

func main() {
pflag.Parse()

if CpuProfile != "" {
f, err := os.Create(CpuProfile)
utils.Check(err, "Unable to create cpu profile file")
defer f.Close()

err = pprof.StartCPUProfile(f)
utils.Check(err, "Unable to start CPU Profiler")
defer pprof.StopCPUProfile()
}

if RunAll {
runAll()
return
Expand Down

0 comments on commit 30aa414

Please sign in to comment.