Created
August 1, 2018 10:17
-
-
Save devonestes/abe4dc60484e5426d4890c4494430194 to your computer and use it in GitHub Desktop.
Reproduction escript for trace/3 wierdness
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
#!/usr/bin/env escript | |
%% -*- erlang -*- | |
%%! -smp enable -sname wtf | |
main(_) -> | |
process_flag(trap_exit, true), | |
ToMap = lists:seq(1, 50), | |
MapFun = fun() -> | |
lists:map(fun(N) -> N end, ToMap) | |
end, | |
start_runner(MapFun), | |
timer:sleep(5000). | |
start_runner(MapFun) -> | |
spawn_link(fun() -> | |
Printer = start_printer(), | |
start_tracer(self(), Printer), | |
measure_memory(MapFun, Printer) | |
end). | |
measure_memory(MapFun, Printer) -> | |
Printer ! process_info(self(), garbage_collection_info), | |
MapFun(), | |
Printer ! process_info(self(), garbage_collection_info). | |
start_printer() -> | |
spawn(fun() -> print_loop() end). | |
print_loop() -> | |
receive | |
Elem -> | |
io:format("~w\n\n", [Elem]), | |
print_loop() | |
end. | |
start_tracer(Runner, Printer) -> | |
spawn(fun() -> | |
erlang:trace(Runner, true, [garbage_collection, {tracer, self()}]), | |
tracer_loop(Printer) | |
end). | |
tracer_loop(Printer) -> | |
receive | |
Elem -> | |
Printer ! Elem, | |
tracer_loop(Printer) | |
end. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment