spawn(fn -> log_file = "vm_top_processes.log" loop = fn loop -> timestamp = DateTime.utc_now() |> DateTime.to_string() top_cpu = :recon.proc_count(:redu, 5) top_mailbox = :recon.proc_count(:message_queue_len, 5) format_proc = fn {pid, value, info} -> name = case info[:registered_name] do [] -> inspect(pid) nil -> inspect(pid) n -> "#{n} (#{inspect(pid)})" end " #{name} | #{info[:current_function] |> inspect()} | value=#{value}\n" end cpu_lines = Enum.map_join(top_cpu, "", format_proc) mailbox_lines = Enum.map_join(top_mailbox, "", format_proc) entry = """ ========== #{timestamp} ========== TOP 5 CPU TIME (reductions): #{cpu_lines} TOP 5 MAILBOX LENGTH: #{mailbox_lines} """ File.write!(log_file, entry, [:append]) Process.sleep(15_000) loop.(loop) end loop.(loop) end)