plugin/pprof - add option to enable block profiling (#2729)

* - add an option for block profiling to plugin pprof

* - move option block into nested block
This commit is contained in:
Francois Tur 2019-03-29 02:37:17 -04:00 committed by Miek Gieben
parent f6eb2a4c14
commit c144da2524
4 changed files with 53 additions and 11 deletions

View file

@ -2,6 +2,7 @@ package pprof
import (
"net"
"strconv"
"sync"
"github.com/coredns/coredns/plugin"
@ -36,15 +37,34 @@ func setup(c *caddy.Controller) error {
h.addr = args[0]
_, _, e := net.SplitHostPort(h.addr)
if e != nil {
return e
return plugin.Error("pprof", c.Errf("%v", e))
}
}
if len(args) > 1 {
return plugin.Error("pprof", c.ArgErr())
}
if c.NextBlock() {
return plugin.Error("pprof", c.ArgErr())
for c.NextBlock() {
switch c.Val() {
case "block":
args := c.RemainingArgs()
if len(args) > 1 {
return plugin.Error("pprof", c.ArgErr())
}
h.rateBloc = 1
if len(args) > 0 {
t, err := strconv.Atoi(args[0])
if err != nil {
return plugin.Error("pprof", c.Errf("property '%s' invalid integer value '%v'", "block", args[0]))
}
h.rateBloc = t
}
default:
return plugin.Error("pprof", c.Errf("unknown property '%s'", c.Val()))
}
}
}
pprofOnce.Do(func() {