Profiling
Learn about profiling and understand how it works.
We'll cover the following
What is profiling?
Profiling is a performance tuning technique that primarily measures the frequency and duration of function calls. Erlang/OTP ships with three profilers.
-
The
cprof
profiler counts the number of invocations. -
The
eprof
profiler measures execution time. -
The
fprof
profiler measures both frequency and time.
Each has its own advantages and disadvantages. cprof
runs quite fast and has a minimal impact on execution times, but doesn’t tell us as much as full execution times. On the other hand, fprof
provides much more data, but it impacts our execution time.
Elixir provides integration with cprof
, eprof
, and fprof
via the Mix tool. In this section, we’ll provide a quick example of using cprof
and fprof
.
Imagine that your load tests found one fairly slow route. After looking at the data, the slowdown was in the index action of the PostController
. We need to figure out exactly what is happening.
Example of profiling
In our Phoenix application, create a file named post_index.exs
in a new perf
directory. We want to write a piece of code that will execute the action we want to profile. We’ll rely on the same functions we use to test our controllers:
Get hands-on with 1400+ tech skills courses.