Go: Profile Your Code Like a Master

Ali Josie
The Startup

--

Go is a programming language often used for applications in which performance matters. Optimizing your code based on assumptions is not a best practice of course. You need to have insights about your code performance and bottlenecks to be able to optimize it efficiently.

What is a profiler?

Profiler is a dynamic performance analysis tool that provides critical execution insights in various dimensions which enable resolving performance issues, locating memory leaks, thread contention, and more.

Go comes with built-in support for profiling!

What kinds of profiles can I get?

Go has several built in profiles:

Goroutine: stack traces of all current Goroutines
CPU: stack traces of CPU returned by runtime
Heap: a sampling of memory allocations of live objects
Allocation: a sampling of all past memory allocations
Thread: stack traces that led to the creation of new OS threads
Block: stack traces that led to blocking on synchronization primitives
Mutex: stack traces of holders of contended mutexes

--

--

Ali Josie
The Startup

Software Engineer & Information Security Enthusiast