import ( "코딩", "행복", "즐거움" )

pprof 본문

GO

pprof

더코드마니아 2022. 10. 5. 11:53

pprof??

GO의 프로파일링(profile) 도구다 

우리 팀에서는 이 도구로 메모리 누수를 잡은 적이 있다. 

매우 유용한 도구이기 때문에 Go로 프로젝트를 한다면 

추천한다. 

 

Go의 웹프레임워크 중에 가장 유명한 gin 을 사용 중인데 

gin의 pprof 패키지는 이걸 사용한다. 

https://github.com/DeanThompson/ginpprof

 

GitHub - DeanThompson/ginpprof: A wrapper for golang web framework gin to use net/http/pprof easily.

A wrapper for golang web framework gin to use net/http/pprof easily. - GitHub - DeanThompson/ginpprof: A wrapper for golang web framework gin to use net/http/pprof easily.

github.com

ginpprof를 import 하고 Wrap()를 사용하여 프로젝트와 연결 한다. 

"github.com/DeanThompson/ginpprof"

ginpprof.Wrap(...)

위의 ... 부분에 *gin.Engine 을 연결 해주면 된다. 

 

이후 서버를 띄우고 나면 언제든지 웹 페이지를 통해서 프로파일 정보를 가져올 수 있다. 

http://localhost:3000/debug/pprof/

 

프로파일링을 그래프화 해서 한눈에 볼 수 있다. 

아래와 같이 링크주소로 요청 하면 

파일을 내려 받게 된다. 

http://localhost:3000/debug/pprof/heap
http://localhost:3000/debug/pprof/profile

위 파일들을 아래 사이트에서 upload하고 

웹에서 분석 할 수 있다. 

https://pprofweb.evanjones.ca/

 

PProf Web Interface

PProf Web Interface Upload a file to explore it using the Pprof web interface. See the documentation/source code. This is currently a hack: it runs in Google Cloud Run, which will restart instances whenever it wants. This means your state may get lost at a

pprofweb.evanjones.ca