image::docs/eflambe-torch-logo.png[E flambè Live, a tool for rapid profiling of Elixir code in Livebook]

* Generate and view flamegraphs in livebook
* Uses link:[eFlambè] to generate flamegraphs

== Screenshot and demo

image::docs/screenshot-livebook.png[Livebook flamegraph screenshot]

The best way to see how it works is to link:guides/eflambe_live_demo.livemd[open up the demo in Livebook!]

== Description

eFlambè integration with Livebook. This tool is designed for rapid profiling of Elixir code in Livebook. The API mirrors the API profiled by `:eflambe` but the output is displayed as an interactive SVG flamegraph in Livebook using link:[Kino.JS].

== Installation

Add the following to the setup block in your livebook to use EflambeLive:

[source, elixir]
  {:kino, "~> 0.7.0"},
  {:eflambe_live, "~> 0.1.0"}

== Usage

There are two ways to profile code with eflambè. You can either invoke the code directly using `EflambeLive.apply/1,2` or you can "capture" trace data from a function when it is invoked by another process on the node `EflambeLive.capture/1,2,3`.

== Implementation

For SpawnFest 2021 I created link:[eFlambè]. This year I wanted to try extending it to Livebook. eFlambè worked well enough for its intended use, but there were several things that had to be addressed in order to use it from Livebook:

* eFlambè only wrote flamegraph data to files on disk. There was no API that returned flamegraphs to the caller.
* The `eflambe:capture/3` function was asynchronous so the flamegraph wasn't even generated when the function returned.
* eFlambè only generated flamegraphs in formats that required a link:[flamegraph viewer] in order to understand.

I addressed these issues in a series of PRs:

* I redesigned the eFlambè API so function calls were synchronous and would return the name of the file containing the flamegraph data. **This PR was done before SpawnFest and is not part of my submission**:
* Added an option to return the formatted flamegraph data directly:
* Added an eFlambè link:[formatter] that generated a self-contained interactive SVG file:

With these things in place there was very little code that needed to be written for EflambeLive. The functions in `EflambeLive` call corresponding functions in `:eflambe` and receive SVG data back from them. The code passes the SVG data to `Kino.JS` which handles rendering the SVG on the page and adding JavaScript and CSS to make the SVG interactive in Livebook.

The JavaScript code that makes the flamegraph interactive was ported from

This project was inspired by Mike Binn's project and is very similar.

== Links

* Hex package: TODO
* Github:
* eFlambè:
* JS ported from:

== Contributing

Feedback is welcome! This was started as a hackathon project but I plan on maintaining it for my teams every day use, so if you see something that could be improved please open an issue!

==== Tagging Releases

1. Update versions in `README.adoc` to new version.
1. Run `git add README.adoc`.
1. Use `mix hex.publish`.
1. Run `git tag <new tag>`.
1. Run `git push origin master <new tag>`.