Skip to content

Commit 7d1f943

Browse files
authored
service: Add pprof option (#153)
1 parent fba0e4b commit 7d1f943

5 files changed

Lines changed: 13 additions & 4 deletions

File tree

service/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ require (
77
github.com/sunshineplan/httpproxy v0.0.0-00010101000000-000000000000
88
github.com/sunshineplan/limiter v1.0.0
99
github.com/sunshineplan/service v1.0.22
10-
github.com/sunshineplan/utils v0.1.77
10+
github.com/sunshineplan/utils v0.1.78
1111
golang.org/x/net v0.42.0
1212
golang.org/x/time v0.12.0
1313
)

service/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ github.com/sunshineplan/limiter v1.0.0 h1:wx3q5eS5J+ggXlAxzg9k6UbDyJYrysNmHyxt5c
44
github.com/sunshineplan/limiter v1.0.0/go.mod h1:+Pjd5Pu7i5YclrnFz+MBFxGB9+MZ2cytQeV+S9kXOxY=
55
github.com/sunshineplan/service v1.0.22 h1:MFXKIbcd3POiJb9KRI8oeybc2qN0p79vv9f+OL88EDU=
66
github.com/sunshineplan/service v1.0.22/go.mod h1:JR7cTSNJVlajjXfXobA3Rr46z88M+6VK6coxq7JmyrY=
7-
github.com/sunshineplan/utils v0.1.77 h1:hDJtJahnkzvJ39L0GMc7mGFcZPjwYIbRcSwX3wPNVbM=
8-
github.com/sunshineplan/utils v0.1.77/go.mod h1:R7MInPRKnExzzNGJ9qY1W0+11P/3jc6IO5ICuGDPA1w=
7+
github.com/sunshineplan/utils v0.1.78 h1:4aBDOTqWUozGBKe3wI1jjxz03yjUdn2GvPMs7oKILuw=
8+
github.com/sunshineplan/utils v0.1.78/go.mod h1:R7MInPRKnExzzNGJ9qY1W0+11P/3jc6IO5ICuGDPA1w=
99
golang.org/x/net v0.42.0 h1:jzkYrhi3YQWD6MLBJcsklgQsoAcw89EcZbJw8Z614hs=
1010
golang.org/x/net v0.42.0/go.mod h1:FF1RA5d3u7nAYA4z2TkclSCKh68eSXtiFwcWQpPXdt8=
1111
golang.org/x/sys v0.34.0 h1:H5Y5sJ2L2JRdyv7ROF1he/lPdvFsd0mJHFw2ThKHxLA=

service/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ var (
2222
status = flag.String("status", "", "Path to status file")
2323
keep = flag.Int("keep", 100, "Count of status files")
2424
debug = flag.Bool("debug", false, "debug")
25+
pprof = flag.String("pprof", "", "pprof port")
2526
)
2627

2728
const commonFlag = `

service/misc.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"io"
5+
"net"
56
"net/url"
67
"path/filepath"
78
"time"
@@ -58,7 +59,7 @@ func watchFile(file string, fnChange, fnRemove func()) error {
5859
return nil
5960
}
6061

61-
func transfer(dst io.WriteCloser, src io.ReadCloser, user user, lim *limiter.Limiter) {
62+
func transfer(dst, src net.Conn, user user, lim *limiter.Limiter) {
6263
defer dst.Close()
6364
defer src.Close()
6465
if lim == nil {

service/run.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package main
22

33
import (
44
"net"
5+
"net/http"
6+
_ "net/http/pprof"
57
"net/url"
68
"strconv"
79

@@ -19,6 +21,11 @@ type Runner interface {
1921
}
2022

2123
func run() error {
24+
if addr := *pprof; addr != "" {
25+
go func() {
26+
svc.Print(http.ListenAndServe(addr, nil))
27+
}()
28+
}
2229
base := NewBase(*host, *port)
2330
base.ErrorLog = errorLogger.Logger
2431
servers := []*httpsvr.Server{base.Server}

0 commit comments

Comments
 (0)