<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Trevor Brown on Medium]]></title>
        <description><![CDATA[Stories by Trevor Brown on Medium]]></description>
        <link>https://medium.com/@trevorbrownrentpath?source=rss-beb61e00cc1b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*RMM5zlpi8KCYRguL</url>
            <title>Stories by Trevor Brown on Medium</title>
            <link>https://medium.com/@trevorbrownrentpath?source=rss-beb61e00cc1b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 12:18:59 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@trevorbrownrentpath/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Introducing eFlambé]]></title>
            <link>https://medium.com/code-for-rent/introducing-eflamb%C3%A9-3065e70f9eb?source=rss-beb61e00cc1b------2</link>
            <guid isPermaLink="false">https://medium.com/p/3065e70f9eb</guid>
            <category><![CDATA[erlang]]></category>
            <category><![CDATA[elixir]]></category>
            <category><![CDATA[flamegraphs]]></category>
            <dc:creator><![CDATA[Trevor Brown]]></dc:creator>
            <pubDate>Wed, 20 Oct 2021 15:55:36 GMT</pubDate>
            <atom:updated>2021-10-20T15:59:33.032Z</atom:updated>
            <content:encoded><![CDATA[<p>SpawnFest is an annual 48 hour online contest where teams try to build the best BEAM-based application, as determined by the judges based on <a href="https://spawnfest.org/#rules">certain criteria</a>. In this blog post I am going to introduce the new tool I created during SpawnFest.</p><p>eFlambé is a tool for rapidly profiling Erlang and Elixir code. It is intended to be one of the first tools you reach for when debugging a performance issue in your Elixir or Erlang application. With a single command you can visualize your code’s performance as an interactive flame graph in your flame graph viewer of choice. It’s written in Erlang and published to <a href="https://hex.pm/packages/eflambe">hex.pm</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6zjZgqQ-Kh2Rrjz5I_jXAw.png" /><figcaption>eFlambé flame graph viewed in speedscope</figcaption></figure><h3>Design</h3><p>There are no new ideas behind eFlambé. Brendan Gregg <a href="https://www.brendangregg.com/flamegraphs.html">introduced flame graphs</a> nearly a decade ago and there have been several Erlang projects that have made it possible to generate flame graphs of Elixir and Erlang call stacks. By far the most popular has been Vlad Ki’s <a href="https://github.com/proger/eflame">eflame</a>. While eflame works well it has two disadvantages:</p><ul><li>Generating a SVG flame graph is a multi-step process.</li><li>Code that needs to be profiled must be invoked by the eflame:apply/3 directly. Sometimes you want to profile a function call as it is made by code inside of your running application. With eflame you must wrap the function call in an eflame:apply/3 call and re-compile and restart your application.</li></ul><p>eFlambé improves upon eflame by making flame graph generation a single step process, and making it possible to profile any function inside a running application without having to recompile code or run more than one command.</p><h3>Usage</h3><p>Using eFlambé is easy. Simply add it as a dependency to your project.</p><p>For Elixir projects, add the following line to your mix.exs file’s dependency section and then run mix deps.get:</p><pre>{:eflambe, &quot;~&gt; 0.2.1&quot;}</pre><p>For Erlang rebar3 projects add the following line to the dependency section of your rebar.config file and then run rebar3 get-deps:</p><pre>{eflambe, &quot;0.2.1&quot;}</pre><p>Then start up your application with a remote shell attached. For Elixir projects this will typically be iex -S &lt;script&gt;, and for Erlang rebar3 projects this will be rebar3 shell.</p><p>There are two different ways to generate flame graphs with eFlambé.</p><h4>Profiling a single call</h4><p>Generating a flame graph of a single function call can be done with the eflambe:apply/2 function. For example, suppose I want to generate a flame graph of my Fibonacci algorithm:</p><pre>iex(1)&gt; :eflambe.apply({MyFibonacci, generate, [10]}, [output_format: :brendan_gregg, open: :speedscope])</pre><p>The first argument is a tuple containing the module name, function name, and the list of arguments to invoke the function with. The second argument is a list of options for eFlambé. In this example we are specifying the output format as brendan_gregg (one of the formats that speedscope can read) and instructing eFlambé to open the generated flame graph in <a href="https://www.speedscope.app/">speedscope</a> (you’ll need to have speedscope already installed for this to work). See the <a href="https://github.com/Stratus3D/eflambe#options">readme</a> for the complete list of options. This will execute MyFibonacci.generate/1 with an argument of 10. Because I specified open: :speedscope eFlambé will immediately open the flame graph data in speedscope when the function returns.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9Hvo2I1ZIoU35g2AIP_idQ.png" /><figcaption>Flame graph of my Fibonacci function viewed in speedscope</figcaption></figure><h4>Profiling a call invoked by application code</h4><p>Sometimes the code you want to profile cannot be invoked directly, or you need to profile it with real arguments to generate a more accurate flame graph. For example, you want to profile a Phoenix controller action as it is invoked in your real Plug pipeline. eFlambé provides a convenient way to do this as well with the :eflambe.capture/3 function.</p><p>For example, to profile three invocations of MyController.index/2 action:</p><pre>iex(1)&gt; :eflambe.capture({MyController, index, 2}, 3, [output_format: :brendan_gregg, open: :speedscope])</pre><p>The moment a request is sent and MyController.index/2 is invoked eFlambé will “capture” the call stack during the execution of the function. Because the :open option was specified eFlambé will open the flame graph for viewing after the function has returned. This will happen for the first three invocations of the function. After three calls eFlambé will off capturing and stop tracing calls.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xYOYu05p7K55dJct7ekCMg.png" /><figcaption>Flame graph of my Phoenix controller action, viewed in speedscope</figcaption></figure><h3>Conclusion</h3><p>Seeing a flame graph of the code you’ve written can help you better understand how your code is executed. You don’t need to wait until you’ve run into performance issues to see where the execution time is spent. With eFlambé generating a flame graph is quick and easy so it only takes moment to gain some insight into your code’s performance characteristics. Hopefully the examples in this blog post have given you an idea of what is possible with <a href="https://hex.pm/packages/eflambe">eFlambé</a> and inspired you to give it a try.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3065e70f9eb" width="1" height="1" alt=""><hr><p><a href="https://medium.com/code-for-rent/introducing-eflamb%C3%A9-3065e70f9eb">Introducing eFlambé</a> was originally published in <a href="https://medium.com/code-for-rent">Code for RentPath</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Running Dialyzer for Elixir Projects in GitHub Actions]]></title>
            <link>https://medium.com/code-for-rent/running-dialyzer-for-elixir-projects-in-github-actions-e0594220b272?source=rss-beb61e00cc1b------2</link>
            <guid isPermaLink="false">https://medium.com/p/e0594220b272</guid>
            <category><![CDATA[elixir]]></category>
            <category><![CDATA[type-checking]]></category>
            <category><![CDATA[dialyzer]]></category>
            <category><![CDATA[github-actions]]></category>
            <dc:creator><![CDATA[Trevor Brown]]></dc:creator>
            <pubDate>Wed, 14 Apr 2021 17:45:20 GMT</pubDate>
            <atom:updated>2021-04-14T17:45:20.846Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>In this blog post I’ll show you how to set up GitHub Actions to perform type analysis on an Elixir project with </strong><a href="https://erlang.org/doc/man/dialyzer.html"><strong>Dialyzer</strong></a><strong>. I’ll also share optimal settings for Dialyzer PLT caching.</strong></p><p>Running automated tests for every commit or pull request has become common practice and is a good way to validate the correctness of your Erlang or Elixir software. Type checking with Dialyzer is another way to ensure the quality of your code changes.</p><p>I have previously written about <a href="http://stratus3d.com/blog/2020/05/01/running-dialyzer-in-jenkins-builds/">how to run Dialyzer in a Jenkins build</a> and here I’ll share how to do the same with a GitHub workflow.</p><h3>Adding Dialyzer</h3><p>You need to have dialyxir installed as a dev dependency for your project for it to be available in the GitHub workflow. If you don&#39;t already have dialyxir installed, add the following to your project&#39;s mix.exs file:</p><pre>defp deps do<br>  [<br>    ...<br>    {:dialyxir, &quot;~&gt; 1.0&quot;, only: [:dev, :test], runtime: false}<br>  ]<br>end</pre><p>Then run mix deps.get.</p><h3>Creating a GitHub Workflow</h3><p>On many of our Elixir projects we have a dedicated Dialyzer workflow that is triggered when pull requests are opened, updated, reopened, or when a new commit is pushed to the main branch. Below is a GitHub workflow for running Dialyzer:</p><pre>name: Dialyzer<br>on:<br>  pull_request:<br>    types:<br>      - opened<br>      - synchronize<br>      - reopened<br>  push:<br>    branches:<br>      - main<br>jobs:<br>  dialyzer:<br>    name: Run Dialyzer for type checking<br>    runs-on: ubuntu-latest<br>    steps:<br>      # Checkout the Elixir project&#39;s source code<br>      - uses: actions/checkout@v2<br>      # Use the erlef/setup-elixir action (https://github.com/erlef/setup-beam)<br>      # to setup Erlang and Elixir<br>      - name: Run Dialyzer<br>        uses: erlef/setup-elixir@v1<br>        with:<br>          otp-version: &#39;23.2.3&#39;<br>          elixir-version: &#39;1.11.3&#39;<br>      # Install the dependencies and run dialyzer<br>      - run: mix deps.get<br>      - run: mix dialyzer</pre><h3>Caching PLT Files</h3><p>The above will work fine but each run will take a substantial amount of time. On my projects it typically takes 10–12 minutes. Most of this time is spent building up the PLT file with type data from the applications that comprise Erlang and Elixir as well as your project’s dependencies. Caching the PLT files (the PLT file itself and the .hash file for it) between runs will dramatically speed up the workflow.</p><p>Caching files is possible with the <a href="https://github.com/actions/cache">actions/cache</a> action. While it’s not the simplest build artifact caching system I’ve seen, it’s relatively easy to set up once you understand how it works. It helps to first understand how cache keys and scopes work.</p><h4>Cache Keys</h4><p>Every time files are saved in a cache they are saved under a unique <strong>cache key</strong>. If a cached file changes, so should the key for it. An easy way to generate a unique cache key for PLT files is to take a hash of the mix.lock file and use it as part of the key. Then when the dependencies change the key also changes. (It may also be helpful to include the Elixir and Erlang versions in the cache key so when they change the key will change as well).</p><h4>Cache Scopes</h4><blockquote><em>The cache is scoped to the key and branch. The default branch cache is available to other branches.</em></blockquote><blockquote><em>— </em><a href="https://github.com/actions/cache#cache-scopes"><em>https://github.com/actions/cache#cache-scopes</em></a></blockquote><p>Workflows will not be able to access caches from any other branch except the default branch (typically main or master). Scoping is important because an existing cache for one branch may not be useful to another branch.</p><h4>Restore Keys</h4><p>Restore keys are used to locate the cache to use when there is a cache miss on the exact key defined in the workflow. Restore keys are a list of strings that are either exact or partial key matches.</p><blockquote><em>The cache action first searches for cache hits for key and restore-keys in the branch containing the workflow run. If there are no hits in the current branch, the cache action searches for key and restore-keys in the parent branch and upstream branches.</em></blockquote><blockquote><em>— </em><a href="https://docs.github.com/en/actions/guides/caching-dependencies-to-speed-up-workflows#matching-a-cache-key"><em>https://docs.github.com/en/actions/guides/caching-dependencies-to-speed-up-workflows#matching-a-cache-key</em></a></blockquote><p>Typically restore-keys is a list of patterns that are progressively more broad.</p><p>Since PLT files contain analysis for Erlang and Elixir libraries, as well as your project’s dependencies, changes to either results in Dialyzer adding or removing data from the PLT file. Thus, when storing PLT files, we want the key to indicate what dependencies they contain. The easiest way to do this is to generate a hash of the mix.lock file and use it as part of the cache key. That way on later runs we can restore to a PLT file that contains the exact same dependencies that the current commit of the code contains. If we don&#39;t find an exact match we can fall back to another PLT cache on the same branch. Here are the GitHub action steps for this:</p><pre># Step for generating the mix file Hash used in the cache key<br>- name: Set mix file hash<br>  id: set_vars<br>  run: |<br>    # hashFiles is a GitHub Actions function for generating a hash<br>    mix_hash=&quot;${{ hashFiles(format(&#39;{0}{1}&#39;, github.workspace, &#39;/mix.lock&#39;)) }}&quot;<br>    echo &quot;::set-output name=mix_hash::$mix_hash&quot;<br># Step to setup caching and cache restoration<br>- name: Cache PLT files<br>  id: cache-plt<br>  uses: actions/cache@v2<br>  with:<br>    # Cache PLT and PLT hash files after the job has finished<br>    path: |<br>      _build/dev/*.plt<br>      _build/dev/*.plt.hash<br>    # Key to use when restoring the cache and storing the results of this dialyzer run<br>    key: plt-cache-${{ steps.set_vars.outputs.mix_hash }}<br>    # Key patterns to fall back to if we don&#39;t find an exact match for `key`<br>    restore-keys: |<br>      plt-cache-</pre><p>Here is how the resulting cache restore process works:</p><ol><li>Look for a matching PLT cache key (remember it contains the mix.lock hash) on the current branch (e.g. a feature branch)</li><li>If not found, fall back to any PLT cache on the current branch</li><li>If not found, fall back to a matching PLT cache key on the main branch</li><li>If not found, fall back to any PLT cache on the main branch</li><li>If nothing is found, run dialyzer without an existing PLT file</li></ol><p>Saving to the cache is a much simpler process — after every run the PLT files are saved to a cache identified by the key value.</p><h3>Putting It All Together</h3><p>The completed Dialyzer workflow with caching looks like this:</p><pre>name: Dialyzer<br>on:<br>  pull_request:<br>    types:<br>      - opened<br>      - synchronize<br>      - reopened<br>  push:<br>    branches:<br>      - main<br>jobs:<br>  dialyzer:<br>    name: Run Dialyzer for type checking<br>    runs-on: ubuntu-latest<br>    steps:<br>      - uses: actions/checkout@v2<br>      - name: Set mix file hash<br>        id: set_vars<br>        run: |<br>          mix_hash=&quot;${{ hashFiles(format(&#39;{0}{1}&#39;, github.workspace, &#39;/mix.lock&#39;)) }}&quot;<br>          echo &quot;::set-output name=mix_hash::$mix_hash&quot;<br>      - name: Cache PLT files<br>        id: cache-plt<br>        uses: actions/cache@v2<br>        with:<br>          path: |<br>            _build/dev/*.plt<br>            _build/dev/*.plt.hash<br>          key: plt-cache-${{ steps.set_vars.outputs.mix_hash }}<br>          restore-keys: |<br>            plt-cache-<br>      - name: Run Dialyzer<br>        uses: erlef/setup-elixir@v1<br>        with:<br>          otp-version: &#39;23.2.3&#39;<br>          elixir-version: &#39;1.11.3&#39;<br>      - run: mix deps.get<br>      - run: mix dialyzer</pre><h3>Conclusion</h3><p>I have shown how to create a simple and effective caching strategy designed to reduce time-consuming re-builds of PLT files. With this approach Dialyzer only takes about 2 minutes to run when there is a cache, making it viable to run on every commit. GitHub Actions provides sufficient tooling for running Dialyzer in a workflow and for effective caching and restoration of PLT files between workflow runs. Understanding how the cache action works can be challenging at first, but once understood it can be used to create almost any caching mechanism you need.</p><h3>References</h3><ul><li><a href="http://stratus3d.com/blog/2020/05/01/running-dialyzer-in-jenkins-builds/">http://stratus3d.com/blog/2020/05/01/running-dialyzer-in-jenkins-builds/</a></li><li><a href="https://github.com/erlef/setup-beam">https://github.com/erlef/setup-beam</a></li><li><a href="https://github.com/actions/cache">https://github.com/actions/cache</a></li><li><a href="https://docs.github.com/en/actions/guides/caching-dependencies-to-speed-up-workflows#matching-a-cache-key">https://docs.github.com/en/actions/guides/caching-dependencies-to-speed-up-workflows#matching-a-cache-key</a></li><li><a href="https://docs.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions#hashfiles">https://docs.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions#hashfiles</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e0594220b272" width="1" height="1" alt=""><hr><p><a href="https://medium.com/code-for-rent/running-dialyzer-for-elixir-projects-in-github-actions-e0594220b272">Running Dialyzer for Elixir Projects in GitHub Actions</a> was originally published in <a href="https://medium.com/code-for-rent">Code for RentPath</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>