Skip to content

Commit

Permalink
update(cpu_profiling): makes profiling optional via cmd flags
Browse files Browse the repository at this point in the history
  • Loading branch information
Rohan Sreerama committed Aug 21, 2024
1 parent 41ae187 commit 1b23dda
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions cmd/wirey/main.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
package main

import (
"flag"
"log"
"net/http"
_ "net/http/pprof"
)

func main() {
enableProfiling := flag.Bool("enable-profiling", false, "Enable pprof profiling")
profileAddr := flag.String("profile-addr", "localhost:6060", "Address for pprof profiling")

go func() {
log.Println(http.ListenAndServe("localhost:6060", nil))
}()
flag.Parse()

if *enableProfiling {
go func() {
log.Printf("Starting pprof server on %s\n", *profileAddr)
if err := http.ListenAndServe(*profileAddr, nil); err != nil {
log.Fatalf("Error starting pprof server: %v\n", err)
}
}()
}

// Execute main application logic
Execute()
}

0 comments on commit 1b23dda

Please sign in to comment.