2016-08-19 17:14:17 -07:00
|
|
|
package pprof
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"sync"
|
|
|
|
|
|
|
|
|
|
"github.com/mholt/caddy"
|
2017-02-21 22:51:47 -08:00
|
|
|
"github.com/coredns/coredns/middleware"
|
2016-08-19 17:14:17 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
|
caddy.RegisterPlugin("pprof", caddy.Plugin{
|
|
|
|
|
ServerType: "dns",
|
|
|
|
|
Action: setup,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func setup(c *caddy.Controller) error {
|
|
|
|
|
found := false
|
|
|
|
|
for c.Next() {
|
|
|
|
|
if found {
|
2016-09-10 09:16:25 +01:00
|
|
|
return middleware.Error("pprof", c.Err("pprof can only be specified once"))
|
2016-08-19 17:14:17 -07:00
|
|
|
}
|
|
|
|
|
if len(c.RemainingArgs()) != 0 {
|
2016-09-10 09:16:25 +01:00
|
|
|
return middleware.Error("pprof", c.ArgErr())
|
2016-08-19 17:14:17 -07:00
|
|
|
}
|
|
|
|
|
if c.NextBlock() {
|
2016-09-10 09:16:25 +01:00
|
|
|
return middleware.Error("pprof", c.ArgErr())
|
2016-08-19 17:14:17 -07:00
|
|
|
}
|
|
|
|
|
found = true
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-23 09:14:12 +01:00
|
|
|
h := &handler{}
|
2016-08-19 17:14:17 -07:00
|
|
|
pprofOnce.Do(func() {
|
2016-09-23 09:14:12 +01:00
|
|
|
c.OnStartup(h.Startup)
|
|
|
|
|
c.OnShutdown(h.Shutdown)
|
2016-08-19 17:14:17 -07:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var pprofOnce sync.Once
|