-
-
Save garazdawi/01467ecd6b8c7bcb08ddc8f3eb03d1af 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) -> | |
Tracer = spawn(fun() -> | |
tracer_loop(Printer) | |
end), | |
erlang:trace(self(), true, [garbage_collection, {tracer, Tracer}]). | |
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