Profiling Go App Service in Yuk Recycle
The Go ecosystem provides a very easy way to profile your applications.
Hi! My name is William Rumanta. In this article we will try to profile our currently-running project called Yuk Recycle. In this project, we use Go as our backend service app. So, I will show you how we profile our Go app in this article — stay tune!
We will try to use CPU profiling and Memory profiling in our app. To do that, we will need a tools to help out. I am using this free tools, check it out!
In our go project terminal, you can run this command to automatically install it.
go get github.com/pkg/profile
CPU Profiling
Now we need to add a block of code to our main() function.
Then, run and build your Go project to receive the profiling file report.
As you can see, a new file is generated in /temp/profile970886342/cpu.pprof
By using prof tool, we can run this command to generate the file into pdf
go tool pprof --pdf ~/go/src/profiles /tmp/profile970886342/cpu.pprof > cpu_profile.pdf
You can do Memory profiling as well by adding this line of code in main.go file.
Conclusion
Profiling is needed in our app. It shows and benchmarks how good your system is related to computer works. But in our case, unfortunately the our generated file doesn’t contain anything or any result. It is said by some articles that if the report file doesn’t contain anything, that means the app is run too fast. Hopefully this article help you profiling your own app!