Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Reproduction escript for trace/3 wierdness
#!/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
You can’t perform that action at this time.