Last active 1773877793

Revision 2b1b7be3fddf14be49285f19e8d5ac8b13892ab5

recon_to_file.exs Raw
1spawn(fn ->
2 log_file = "vm_top_processes.log"
3
4 loop = fn loop ->
5 timestamp = DateTime.utc_now() |> DateTime.to_string()
6
7 top_cpu = :recon.proc_count(:redu, 5)
8 top_mailbox = :recon.proc_count(:message_queue_len, 5)
9
10 format_proc = fn {pid, value, info} ->
11 name = case info[:registered_name] do
12 [] -> inspect(pid)
13 nil -> inspect(pid)
14 n -> "#{n} (#{inspect(pid)})"
15 end
16 " #{name} | #{info[:current_function] |> inspect()} | value=#{value}\n"
17 end
18
19 cpu_lines = Enum.map_join(top_cpu, "", format_proc)
20 mailbox_lines = Enum.map_join(top_mailbox, "", format_proc)
21
22 entry = """
23 ========== #{timestamp} ==========
24 TOP 5 CPU TIME (reductions):
25 #{cpu_lines}
26 TOP 5 MAILBOX LENGTH:
27 #{mailbox_lines}
28 """
29
30 File.write!(log_file, entry, [:append])
31 Process.sleep(15_000)
32 loop.(loop)
33 end
34
35 loop.(loop)
36end)
37