File tree Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Original file line number Diff line number Diff line change 99 "net"
1010 "os"
1111 "os/signal"
12+ "runtime/pprof"
1213 "strconv"
1314 "strings"
1415)
2021 versionFlag = flag .Bool ("version" , false , "Output version and exit" )
2122 kubeConfigFile = flag .String ("kube-config" , "" , "The path to a kubernetes configuration file" )
2223 inKubeCluster = flag .Bool ("in-kube-cluster" , false , "Use in-cluster kubernetes config" )
24+ cpuProfile = flag .String ("cpu-profile" , "" , "Enables CPU profiling and writes to given path" )
2325)
2426
2527var (
@@ -40,6 +42,20 @@ func main() {
4042 os .Exit (0 )
4143 }
4244
45+ if * cpuProfile != "" {
46+ cpuProfileFile , err := os .Create (* cpuProfile )
47+ if err != nil {
48+ logrus .WithError (err ).Fatal ("trying to create cpu profile file" )
49+ }
50+
51+ logrus .Info ("Starting cpu profiling" )
52+ err = pprof .StartCPUProfile (cpuProfileFile )
53+ if err != nil {
54+ logrus .WithError (err ).Fatal ("trying to start cpu profile" )
55+ }
56+ defer pprof .StopCPUProfile ()
57+ }
58+
4359 ctx , cancel := context .WithCancel (context .Background ())
4460
4561 c := make (chan os.Signal , 1 )
You can’t perform that action at this time.
0 commit comments