Created
June 22, 2021 08:57
-
-
Save elbrujohalcon/97f996f01516616b8ee32e1d6a04d29a to your computer and use it in GitHub Desktop.
Process Info Checker - v3
This file contains hidden or 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
-module(pi). | |
-format #{paper => 80}. | |
-export([check/0]). | |
check() -> | |
Pid = spawn(fun wait/0), | |
erlang:yield(), | |
Items = | |
[backtrace, binary, catchlevel, current_function, current_location, | |
current_stacktrace, dictionary, error_handler, garbage_collection, | |
garbage_collection_info, group_leader, heap_size, initial_call, links, | |
last_calls, memory, message_queue_len, messages, min_heap_size, | |
min_bin_vheap_size, monitored_by, monitors, message_queue_data, | |
priority, reductions, registered_name, sequential_trace_token, | |
stack_size, status, suspending, total_heap_size, trace, trap_exit], | |
CostlyBits = [Item || Item <- Items, reduction_increase(Item, Pid) > 0], | |
[{reductions, R1} | _] = erlang:process_info(Pid, [reductions | CostlyBits]), | |
[{reductions, R2} | _] = erlang:process_info(Pid, [reductions | CostlyBits]), | |
Pid ! stop, | |
R2 - R1. | |
reduction_increase(Item, Pid) -> | |
[{reductions, R1}, {Item, Value}] = | |
erlang:process_info(Pid, [reductions, Item]), | |
[{reductions, R2}, {Item, Value}] = | |
erlang:process_info(Pid, [reductions, Item]), | |
R2 - R1. | |
wait() -> | |
receive | |
stop -> | |
ok | |
end. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment