2017-11-23 24 views
0

작성한 웹 서버의 프로필을 작성하려고했지만 pprof에 처리기 func에 대한 데이터가 없습니다.
julienschmidt가 httprouter package을 사용하고 있으며, 단순히 내 처리기 중 하나를 벤치마킹하고 pprof 프로필을보고 싶습니다.pprof 프로필이 julienschmidtrouter이고 벤치 마크가 프로파일 링 처리기가 아닙니다.

// Configure the server 
server := &http.Server{ 
    Addr: ":4000", 
    Handler: router, 
} 

go func() { 
    log.Println(http.ListenAndServe(":6060", nil)) 
}() 

// Start the server 
err = server.ListenAndServe() 
if err != nil { 
    panic(err) 
} 

라우터는 다음과 같이 초기화 : 벤치마킹을 위해, 내가 go-wrk

을 사용하고이 같은 내 웹 서버와 pprof 설정

// Create the httprouter 
router := httprouter.New() 
// Register all handlers 
router.GET("/entities/:type/map", h.UseHandler(&h.ApiGetEntitiesMapRequest{}, p)) 

을 그리고 내 핸들러는 다음과 같습니다 :

func (req ApiGetEntitiesMapRequest) Handle(r *http.Request, hrp httprouter.Params, p Params) (interface{}, error) { 
    test := make([]string, 0) 
    for i := 0; i < 1000; i++ { 
     test = append(test, "1") 
     test = append(test, "2") 
     // Ensure pprof has some time to collect its data 
     time.Sleep(10) 
    } 
    return test, nil 
} 

이 처리기는 단지 테스트 일 뿐이며 동적으로 추가합니다 슬라이스에 많은 요소. 그 이유는 이러한 동적 할당이 pprof의 힙 프로파일에 표시되는지 테스트하려고합니다.

자, 내가 한 일은이었다

요청이 작동하며 내 벤치 마크도 repor 모든 것이 올바르게 처리됩니다. 그러나 png을 pprof 터미널에 입력하면이 그래프 enter image description here이 표시됩니다.

그래프에는 처리기 및 처리기에서 수행 한 값 비싼 힙 할당에 대한 정보가 없습니다. 내가 도대체 ​​뭘 잘못하고있는 겁니까?

답변

0

그래서 결국 문제를 발견했습니다!

router.HandlerFunc(http.MethodGet, "/debug/pprof/", pprof.Index) 
router.HandlerFunc(http.MethodGet, "/debug/pprof/cmdline", pprof.Cmdline) 
router.HandlerFunc(http.MethodGet, "/debug/pprof/profile", pprof.Profile) 
router.HandlerFunc(http.MethodGet, "/debug/pprof/symbol", pprof.Symbol) 
router.HandlerFunc(http.MethodGet, "/debug/pprof/trace", pprof.Trace) 
router.Handler(http.MethodGet, "/debug/pprof/goroutine", pprof.Handler("goroutine")) 
router.Handler(http.MethodGet, "/debug/pprof/heap", pprof.Handler("heap")) 
router.Handler(http.MethodGet,"/debug/pprof/threadcreate", pprof.Handler("threadcreate")) 
router.Handler(http.MethodGet,"/debug/pprof/block", pprof.Handler("block")) 

지금은 내 원하는 결과를 얻었다 :

당신이 당신의 요청을 처리하기 위해 사용자 정의 먹스를 사용하는 경우, 당신은 프로파일 권리를 얻기 위해, 당신의 먹스에 pprof 핸들러를 등록해야합니다!