Skip to content

Commit

Permalink
Avoid having to post-process file by generating the correct output
Browse files Browse the repository at this point in the history
  • Loading branch information
jfacorro committed Jul 1, 2018
1 parent a9636f4 commit c9a5df5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
16 changes: 7 additions & 9 deletions src/eflame.erl
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ stack_collapse(Stack) ->
entry_to_iolist({M, F, A}) ->
[ atom_to_binary(M, utf8), <<":">>
, atom_to_binary(F, utf8), <<"/">>
, integer_to_list(A)
, integer_to_binary(A)
];
entry_to_iolist(A) when is_atom(A) ->
[atom_to_binary(A, utf8)].
Expand All @@ -231,13 +231,11 @@ dump_to_iolist(Pid, Stacks) ->
dump_to_iolist(_PidList, [], Result) ->
Result;
dump_to_iolist(PidList, [{N, Stack} | Rest], Result) ->
Item = stack_to_iolist(PidList, Stack),
Items = lists:duplicate(N, Item),
dump_to_iolist(PidList, Rest, [Items | Result]);
dump_to_iolist(PidList, [Stack | Rest], Result) ->
Item = stack_to_iolist(PidList, Stack),
Item = stack_to_iolist(PidList, N, Stack),
dump_to_iolist(PidList, Rest, [Item | Result]).

-spec stack_to_iolist(string(), list()) -> iolist().
stack_to_iolist(PidList, Stack) ->
[PidList, <<";">>, stack_collapse(Stack), <<"\n">>].
-spec stack_to_iolist(string(), integer(), list()) -> iolist().
stack_to_iolist(PidList, N, Stack) ->
[ PidList, <<";">>, stack_collapse(Stack)
, <<" ">>, integer_to_binary(N)
, <<"\n">>].
2 changes: 1 addition & 1 deletion stack_to_flame.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

me="$(dirname $0)"

uniq -c | awk '{print $2, " ", $1}' | $me/flamegraph.pl
$me/flamegraph.pl $1

0 comments on commit c9a5df5

Please sign in to comment.