mirror of
				https://github.com/coredns/coredns.git
				synced 2025-10-31 10:13:14 -04:00 
			
		
		
		
	
		
			
	
	
		
			41 lines
		
	
	
		
			590 B
		
	
	
	
		
			Go
		
	
	
	
	
	
		
		
			
		
	
	
			41 lines
		
	
	
		
			590 B
		
	
	
	
		
			Go
		
	
	
	
	
	
|  | package pprof
 | ||
|  | 
 | ||
|  | import (
 | ||
|  | 	"sync"
 | ||
|  | 
 | ||
|  | 	"github.com/mholt/caddy"
 | ||
|  | )
 | ||
|  | 
 | ||
|  | func init() {
 | ||
|  | 	caddy.RegisterPlugin("pprof", caddy.Plugin{
 | ||
|  | 		ServerType: "dns",
 | ||
|  | 		Action:     setup,
 | ||
|  | 	})
 | ||
|  | }
 | ||
|  | 
 | ||
|  | func setup(c *caddy.Controller) error {
 | ||
|  | 	found := false
 | ||
|  | 	for c.Next() {
 | ||
|  | 		if found {
 | ||
|  | 			return c.Err("pprof can only be specified once")
 | ||
|  | 		}
 | ||
|  | 		if len(c.RemainingArgs()) != 0 {
 | ||
|  | 			return c.ArgErr()
 | ||
|  | 		}
 | ||
|  | 		if c.NextBlock() {
 | ||
|  | 			return c.ArgErr()
 | ||
|  | 		}
 | ||
|  | 		found = true
 | ||
|  | 	}
 | ||
|  | 
 | ||
|  | 	handler := &Handler{}
 | ||
|  | 	pprofOnce.Do(func() {
 | ||
|  | 		c.OnStartup(handler.Startup)
 | ||
|  | 		c.OnShutdown(handler.Shutdown)
 | ||
|  | 	})
 | ||
|  | 
 | ||
|  | 	return nil
 | ||
|  | }
 | ||
|  | 
 | ||
|  | var pprofOnce sync.Once
 |