mirror of
https://github.com/itzg/mc-router.git
synced 2024-11-14 10:15:33 +01:00
Add CPU profiling option
This commit is contained in:
parent
96399cfd40
commit
6cdc1e06ac
@ -9,6 +9,7 @@ import (
|
||||
"net"
|
||||
"os"
|
||||
"os/signal"
|
||||
"runtime/pprof"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
@ -20,6 +21,7 @@ var (
|
||||
versionFlag = flag.Bool("version", false, "Output version and exit")
|
||||
kubeConfigFile = flag.String("kube-config", "", "The path to a kubernetes configuration file")
|
||||
inKubeCluster = flag.Bool("in-kube-cluster", false, "Use in-cluster kubernetes config")
|
||||
cpuProfile = flag.String("cpu-profile", "", "Enables CPU profiling and writes to given path")
|
||||
)
|
||||
|
||||
var (
|
||||
@ -40,6 +42,20 @@ func main() {
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
if *cpuProfile != "" {
|
||||
cpuProfileFile, err := os.Create(*cpuProfile)
|
||||
if err != nil {
|
||||
logrus.WithError(err).Fatal("trying to create cpu profile file")
|
||||
}
|
||||
|
||||
logrus.Info("Starting cpu profiling")
|
||||
err = pprof.StartCPUProfile(cpuProfileFile)
|
||||
if err != nil {
|
||||
logrus.WithError(err).Fatal("trying to start cpu profile")
|
||||
}
|
||||
defer pprof.StopCPUProfile()
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
|
||||
c := make(chan os.Signal, 1)
|
||||
|
Loading…
Reference in New Issue
Block a user