Incendium (Incendium v0.4.0) View Source

Easy flamegraphs to profile for your web applications.

Rationale

Profiling Elixir code is easy using the default Erlang tools, such as fprof. These tools produce a lot of potentially useful data, but visualizing and interpreting all that data is not easy. The erlang tool eflame contains some utilities to generate flamegraphs from the results of profiling your code

But... eflame expects you to manually run a bash script, which according to my reading seems to call a perl (!) script that generates an interactive SVG. And although the generated SVGs support some minimal interaction, it's possible to do better.

Incendium can be used to run benchmarks with integrated profiling data (in the form of flamegraphs). It uses Benchee under the hood, and the API is actually quite similar to Benchee's.

It provides a single function, namely Incendium.run/2, which takes the same arguments as Benchee.run/2, plus some incendium-specific ones. The main difference is that the suite title is a required keyword argument instead of an optional one.

An example:

defmodule Incendium.Benchmarks.Example do
  defp map_fun(i) do
    [i, i * i]
  end

  def run() do
    list = Enum.to_list(1..10_000)

    Incendium.run(%{
      "flat_map" => fn -> Enum.flat_map(list, &map_fun/1) end,
      "map.flatten" => fn -> list |> Enum.map(&map_fun/1) |> List.flatten() end
      },
      title: "Example",
      incendium_flamegraph_widths_to_scale: true
    )
  end
end

Incendium.Benchmarks.Example.run()

The output of the script above can be found here.

Link to this section Summary

Functions

Runs benchmarks using Benchee and render the scenarios as flamegraphs.

Link to this section Functions

Link to this function

run(benchmarks, options)

View Source

Runs benchmarks using Benchee and render the scenarios as flamegraphs.

Takes the same parameters as Benchee.run/2. Takes the following Incendium-specific options:

  • :incendium_flamegraph_widths_to_scale (default true) - sets the width of the flamegraphs according to the scenario runtime. Scenarios that take a longer time to run will generate wider flamegraphs.

  • :incendium_file (default "incendium/#{suite.title}) - the path to the HTML file were Incendium saves the benchmark results (in Benchee, this is specified by a Formatter, bue Incendium unfortunatelly can't reuse the normal Benchee formatting infrastructure)

All other options are passed into Benchee.run/2