This commit is contained in:
Sam
2026-06-10 11:51:56 -05:00
commit 66ba338b81
57 changed files with 5509 additions and 0 deletions

24
lib/forum/vm_memory.ex Normal file
View File

@@ -0,0 +1,24 @@
defmodule Forum.VmMemory do
@moduledoc """
Snapshot of BEAM VM memory categories.
These numbers come from `:erlang.memory/0`, so they describe memory held by
the whole VM rather than memory attributed to a particular Erlang process.
"""
@doc """
Returns VM memory categories as JSON-friendly maps.
"""
def list do
:erlang.memory()
|> Enum.map(fn {category, bytes} ->
%{
"category" => Atom.to_string(category),
"bytes" => bytes,
"kb" => div(bytes, 1024),
"mb" => Float.round(bytes / 1_048_576, 2)
}
end)
|> Enum.sort_by(& &1["bytes"], :desc)
end
end