-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update(cpu_profiling): makes profiling optional via cmd flags
- Loading branch information
Rohan Sreerama
committed
Aug 21, 2024
1 parent
41ae187
commit 1b23dda
Showing
1 changed file
with
14 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |