| 
									
										
										
										
											2016-04-28 10:26:58 +01:00
										 |  |  | package pprof
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import (
 | 
					
						
							|  |  |  | 	"log"
 | 
					
						
							| 
									
										
										
										
											2016-04-29 07:28:35 +01:00
										 |  |  | 	"net"
 | 
					
						
							| 
									
										
										
										
											2016-04-28 10:26:58 +01:00
										 |  |  | 	"net/http"
 | 
					
						
							| 
									
										
										
										
											2016-04-29 07:28:35 +01:00
										 |  |  | 	pp "net/http/pprof"
 | 
					
						
							| 
									
										
										
										
											2016-04-28 10:26:58 +01:00
										 |  |  | )
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | type Handler struct {
 | 
					
						
							| 
									
										
										
										
											2016-04-29 22:04:22 +01:00
										 |  |  | 	ln  net.Listener
 | 
					
						
							|  |  |  | 	mux *http.ServeMux
 | 
					
						
							| 
									
										
										
										
											2016-04-28 10:26:58 +01:00
										 |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-19 17:14:17 -07:00
										 |  |  | func (h *Handler) Startup() error {
 | 
					
						
							| 
									
										
										
										
											2016-04-29 07:28:35 +01:00
										 |  |  | 	if ln, err := net.Listen("tcp", addr); err != nil {
 | 
					
						
							|  |  |  | 		log.Printf("[ERROR] Failed to start pprof handler: %s", err)
 | 
					
						
							|  |  |  | 		return err
 | 
					
						
							|  |  |  | 	} else {
 | 
					
						
							|  |  |  | 		h.ln = ln
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	h.mux = http.NewServeMux()
 | 
					
						
							|  |  |  | 	h.mux.HandleFunc(path+"/", pp.Index)
 | 
					
						
							|  |  |  | 	h.mux.HandleFunc(path+"/cmdline", pp.Cmdline)
 | 
					
						
							|  |  |  | 	h.mux.HandleFunc(path+"/profile", pp.Profile)
 | 
					
						
							|  |  |  | 	h.mux.HandleFunc(path+"/symbol", pp.Symbol)
 | 
					
						
							|  |  |  | 	h.mux.HandleFunc(path+"/trace", pp.Trace)
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-28 10:26:58 +01:00
										 |  |  | 	go func() {
 | 
					
						
							| 
									
										
										
										
											2016-04-29 07:28:35 +01:00
										 |  |  | 		http.Serve(h.ln, h.mux)
 | 
					
						
							| 
									
										
										
										
											2016-04-28 10:26:58 +01:00
										 |  |  | 	}()
 | 
					
						
							|  |  |  | 	return nil
 | 
					
						
							|  |  |  | }
 | 
					
						
							| 
									
										
										
										
											2016-04-29 07:28:35 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | func (h *Handler) Shutdown() error {
 | 
					
						
							|  |  |  | 	if h.ln != nil {
 | 
					
						
							|  |  |  | 		return h.ln.Close()
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							|  |  |  | 	return nil
 | 
					
						
							|  |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const (
 | 
					
						
							|  |  |  | 	addr = "localhost:6053"
 | 
					
						
							|  |  |  | 	path = "/debug/pprof"
 | 
					
						
							|  |  |  | )
 |