Created
July 5, 2022 12:18
-
-
Save vorce/b64f149c440843790f0c4b97dc4d4343 to your computer and use it in GitHub Desktop.
JUnitFormatter that outputs memory usage to a file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule TestMem do | |
@moduledoc """ | |
JUnitFormatter that outputs memory usage to a file. | |
Useful to measure your test suite's memory consumption. | |
""" | |
use GenServer | |
@impl true | |
def init(_opts) do | |
file = File.open!("memory_usage.csv", [:write, {:delayed_write, 1000, 200}]) | |
{:ok, %{file: file}} | |
end | |
@impl true | |
def handle_cast({:test_finished, %ExUnit.Test{state: nil}}, config) do | |
IO.binwrite(config.file, "#{DateTime.utc_now()},#{:erlang.memory(:total)}\n") | |
{:noreply, config} | |
end | |
def handle_cast({:test_finished, %ExUnit.Test{state: {:failed, _failed}}}, config) do | |
IO.binwrite(config.file, "#{DateTime.utc_now()},#{:erlang.memory(:total)}\n") | |
{:noreply, config} | |
end | |
def handle_cast(_event, config), do: {:noreply, config} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment