mirror of
https://github.com/zrepl/zrepl.git
synced 2025-06-18 15:56:45 +02:00
cmd: support for pprof over http
This commit is contained in:
parent
af2aa9dfe1
commit
4f86fa8332
14
cmd/main.go
14
cmd/main.go
@ -10,6 +10,8 @@ import (
|
|||||||
"golang.org/x/sys/unix"
|
"golang.org/x/sys/unix"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
|
"net/http"
|
||||||
|
_ "net/http/pprof"
|
||||||
"os"
|
"os"
|
||||||
"runtime/debug"
|
"runtime/debug"
|
||||||
"sync"
|
"sync"
|
||||||
@ -45,9 +47,11 @@ func main() {
|
|||||||
app.Flags = []cli.Flag{
|
app.Flags = []cli.Flag{
|
||||||
cli.StringFlag{Name: "config"},
|
cli.StringFlag{Name: "config"},
|
||||||
cli.StringFlag{Name: "logfile"},
|
cli.StringFlag{Name: "logfile"},
|
||||||
|
cli.StringFlag{Name: "debug.pprof.http"},
|
||||||
}
|
}
|
||||||
app.Before = func(c *cli.Context) (err error) {
|
app.Before = func(c *cli.Context) (err error) {
|
||||||
|
|
||||||
|
// Logging
|
||||||
if c.GlobalIsSet("logfile") {
|
if c.GlobalIsSet("logfile") {
|
||||||
var logFile *os.File
|
var logFile *os.File
|
||||||
logFile, err = os.OpenFile(c.String("logfile"), os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0600)
|
logFile, err = os.OpenFile(c.String("logfile"), os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0600)
|
||||||
@ -63,8 +67,16 @@ func main() {
|
|||||||
} else {
|
} else {
|
||||||
logOut = os.Stderr
|
logOut = os.Stderr
|
||||||
}
|
}
|
||||||
|
|
||||||
defaultLog = log.New(logOut, "", logFlags)
|
defaultLog = log.New(logOut, "", logFlags)
|
||||||
|
|
||||||
|
// CPU profiling
|
||||||
|
if c.GlobalIsSet("debug.pprof.http") {
|
||||||
|
go func() {
|
||||||
|
http.ListenAndServe(c.GlobalString("debug.pprof.http"), nil)
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Config
|
||||||
if !c.GlobalIsSet("config") {
|
if !c.GlobalIsSet("config") {
|
||||||
return cli.NewExitError("config flag not set", 2)
|
return cli.NewExitError("config flag not set", 2)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user