Skip to content
Permalink
Browse files
use special formatting only if rec module is activated
  • Loading branch information
bartekgorny committed Jul 25, 2018
1 parent ce229fd commit 7da65553cd39916834dfd937abc754388335614c
Showing 3 changed files with 23 additions and 9 deletions.
@@ -13,7 +13,8 @@
term_to_port/1,
time_map/5, time_fold/6,
scheduler_usage_diff/2,
sublist_top_n_attrs/2, format_trace_output/1]).
sublist_top_n_attrs/2,
format_trace_output/1, format_trace_output/2]).
%% private exports
-export([binary_memory/1]).

@@ -248,16 +249,19 @@ binary_memory(Bins) ->
%% @doc formats call arguments and return values - most types are just printed out, except for
%% tuples recognised as records, which mimic the source code syntax
%% @end
format_trace_output(Args) when is_tuple(Args) ->
format_trace_output(Args) ->
format_trace_output(recon_rec:is_active(), Args).

format_trace_output(true, Args) when is_tuple(Args) ->
recon_rec:format_tuple(Args);
format_trace_output(Args) when is_list(Args) ->
format_trace_output(true, Args) when is_list(Args) ->
case io_lib:printable_list(Args) of
true -> io_lib:format("~p", [Args]);
false ->
L = lists:map(fun format_trace_output/1, Args),
L = lists:map(fun(A) -> format_trace_output(true, A) end, Args),
"[" ++ string:join(L, ", ") ++ "]"
end;
format_trace_output(Args) ->
format_trace_output(_, Args) ->
io_lib:format("~p", [Args]).

%%%%%%%%%%%%%%%
@@ -14,6 +14,7 @@
-author("bartlomiej.gorny@erlang-solutions.com").
%% API

-export([is_active/0]).
-export([import/1, format_tuple/1, clear/1, clear/0, list/0, get_list/0, limit/3]).

-export([lookup_record/2]). %% for testing
@@ -41,6 +42,14 @@ import(Modules) when is_list(Modules) ->
import(Module) ->
import(Module, []).

%% @doc quickly check if we want to do any record formatting
-spec is_active() -> boolean().
is_active() ->
case whereis(recon_ets) of
undefined -> false;
_ -> true
end.

%% @doc remove definitions imported from a module.
clear(Module) ->
lists:map(fun(R) -> rem_for_module(R, Module) end, ets:tab2list(ets_table_name())).
@@ -181,7 +190,7 @@ format_tuple(Name, Rec) when is_atom(Name) ->
[RecDef] -> format_record(Rec, RecDef);
_ ->
List = tuple_to_list(Rec),
["{", lists:join(", ", [recon_lib:format_trace_output(El) || El <- List]), "}"]
["{", lists:join(", ", [recon_lib:format_trace_output(true, El) || El <- List]), "}"]
end;
format_tuple(_, Tuple) ->
format_default(Tuple).
@@ -204,7 +213,7 @@ format_record(Rec, {{Name, Arity}, Fields, _, Limits}) ->
end.

format_kv(Key, Val) ->
[recon_lib:format_trace_output(Key), "=", recon_lib:format_trace_output(Val)].
[recon_lib:format_trace_output(true, Key), "=", recon_lib:format_trace_output(true, Val)].

apply_limits(List, all) -> List;
apply_limits(_List, none) -> [];
@@ -598,9 +598,10 @@ to_hms(_) ->
{0,0,0}.

format_args(Arity) when is_integer(Arity) ->
"/"++integer_to_list(Arity);
["/", integer_to_list(Arity)];
format_args(Args) when is_list(Args) ->
"("++string:join([recon_lib:format_trace_output(Arg) || Arg <- Args], ", ")++")".
Active = recon_rec:is_active(),
["(", lists:join(", ", [recon_lib:format_trace_output(Active, Arg) || Arg <- Args]), ")"].

%%%%%%%%%%%%%%%
%%% HELPERS %%%

0 comments on commit 7da6555

Please sign in to comment.