Skip to content

Commit f3cf718

Browse files
committed
add CPU profiling option
1 parent 1deb4c7 commit f3cf718

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ $ basic_hmac_auth -h
3939
Usage of /usr/local/bin/basic_hmac_auth:
4040
-buffer-size int
4141
initial buffer size for stream parsing
42+
-cpu-profile string
43+
write CPU profile to file
4244
-secret string
4345
hex-encoded HMAC secret value
4446
-secret-file string

cmd/main.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"io"
1010
"log"
1111
"os"
12+
"runtime/pprof"
1213

1314
"github.com/SenseUnit/basic_hmac_auth/handler"
1415
)
@@ -24,6 +25,7 @@ var (
2425
hexSecret = flag.String("secret", "", "hex-encoded HMAC secret value")
2526
hexSecretFile = flag.String("secret-file", "", "file containing single line with hex-encoded secret")
2627
showVersion = flag.Bool("version", false, "show program version and exit")
28+
cpuProfile = flag.String("cpu-profile", "", "write CPU profile to file")
2729
)
2830

2931
func run() int {
@@ -65,6 +67,16 @@ func run() int {
6567
return 3
6668
}
6769

70+
if *cpuProfile != "" {
71+
f, err := os.Create(*cpuProfile)
72+
if err != nil {
73+
log.Fatal(err)
74+
}
75+
defer f.Close()
76+
pprof.StartCPUProfile(f)
77+
defer pprof.StopCPUProfile()
78+
}
79+
6880
err = (&handler.BasicHMACAuthHandler{
6981
Secret: secret,
7082
BufferSize: *bufferSize,

0 commit comments

Comments
 (0)