Skip to content
Permalink
Browse files
Fix linking mechanism in record formatting
  • Loading branch information
ferd committed Oct 8, 2018
1 parent a6cdc3a commit 4474d4fed130dc9976fbdbec7bdad92e1a930cfe
Showing 3 changed files with 34 additions and 20 deletions.
@@ -1,5 +1,5 @@
{profiles, [
{test, [
{erl_ops, [nowarn_expor_all, {d, 'TEST'}]}
{erl_opts, [nowarn_export_all, {d, 'TEST'}]}
]}
]}.
@@ -28,8 +28,8 @@
-type limit() :: all | none | field() | [field()].
-type listentry() :: {module(), record_name(), [field()], limit()}.
-type import_result() :: {imported, module(), record_name(), arity()}
| {overwritten, module(), record_name(), arity()}
| {ignored, module(), record_name(), arity(), module()}.
| {overwritten, module(), record_name(), arity()}
| {ignored, module(), record_name(), arity(), module()}.

%% @doc import record definitions from a module. If a record definition of the same name
%% and arity has already been imported from another module then the new
@@ -70,8 +70,10 @@ list() ->
F = fun({Module, Name, Fields, Limits}) ->
Fnames = lists:map(fun atom_to_list/1, Fields),
Flds = join(",", Fnames),
io:format("~p: #~p(~p){~s} ~p~n", [Module, Name, length(Fields), Flds, Limits])
io:format("~p: #~p(~p){~s} ~p~n",
[Module, Name, length(Fields), Flds, Limits])
end,
io:format("Module: #Name(Size){<Fields>} Limits~n==========~n", []),
lists:foreach(F, get_list()).

%% @doc returns a list of active record definitions
@@ -151,16 +153,19 @@ lookup_record(RecName, FieldCount) ->
ensure_table_exists() ->
case ets:info(ets_table_name()) of
undefined ->
Pid = case whereis(recon_ets) of
undefined ->
P = spawn(fun() -> ets_keeper() end),
register(recon_ets, P),
P;
P -> P
end,
ets:new(ets_table_name(), [set, public, named_table]),
ets:give_away(ets_table_name(), Pid, none);
_ -> ok
case whereis(recon_ets) of
undefined ->
%% attach to the currently running session
spawn_link(fun() ->
register(recon_ets, self()),
ets:new(ets_table_name(), [set, public, named_table]),
ets_keeper()
end);
P ->
P
end;
_ ->
ok
end.

ets_table_name() -> recon_record_definitions.
@@ -170,7 +175,8 @@ rec_info({Name, Fields}, Module) ->

rem_for_module({_, _, Module, _} = Rec, Module) ->
ets:delete_object(ets_table_name(), Rec);
rem_for_module(_, _) -> ok.
rem_for_module(_, _) ->
ok.

ets_keeper() ->
receive
@@ -224,7 +230,7 @@ apply_limits(_List, all) -> [];
apply_limits(List, Field) when is_atom(Field) ->
[{Field, proplists:get_value(Field, List)}, {more, '...'}];
apply_limits(List, Limits) ->
lists:filter(fun({K, _}) -> lists:member(K, Limits) end, List) ++ [{more, '...'}].
[lists:filter(fun({K, _}) -> lists:member(K, Limits) end, List), {more, '...'}].

%%%%%%%%%%%%%%%
%%% HELPERS %%%
@@ -169,6 +169,13 @@
%%% The only output still sent to the Group Leader is the rate limit being
%%% tripped, and any errors. The rest will be sent to the other IO
%%% server (see [http://erlang.org/doc/apps/stdlib/io_protocol.html]).
%%%
%%% == Record Printing ==
%%%
%%% Thanks to code contributed by Bartek Górny, record printing can be added
%%% to traces by first importing records in an active session with
%%% `recon_rec:import([Module, ...])', after which the records declared in
%%% the module list will be supported.
%%% @end
-module(recon_trace).

@@ -598,10 +605,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) ->
Active = recon_rec:is_active(),
["(", join(", ", [format_trace_output(Active, Arg) || Arg <- Args]), ")"].
[$(, join(", ", [format_trace_output(Active, Arg) || Arg <- Args]), $)].


%% @doc formats call arguments and return values - most types are just printed out, except for
@@ -614,10 +621,11 @@ format_trace_output(true, Args) when is_tuple(Args) ->
recon_rec:format_tuple(Args);
format_trace_output(true, Args) when is_list(Args) ->
case io_lib:printable_list(Args) of
true -> io_lib:format("~p", [Args]);
true ->
io_lib:format("~p", [Args]);
false ->
L = lists:map(fun(A) -> format_trace_output(true, A) end, Args),
"[" ++ join(", ", L) ++ "]"
[$[, join(", ", L), $]]
end;
format_trace_output(true, Args) when is_map(Args) ->
ItemList = maps:to_list(Args),

0 comments on commit 4474d4f

Please sign in to comment.