Skip to content

Commit

Permalink
Allow return_to option in recon_trace calls
Browse files Browse the repository at this point in the history
  • Loading branch information
ferd committed May 18, 2016
1 parent e2bfbaa commit 8f960ab
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Recon wants to be a set of tools usable in production to diagnose Erlang problem

To build the library:

./rebar compile
rebar3 compile

Documentation for the library can be obtained at http://ferd.github.io/recon/

Expand All @@ -27,6 +27,8 @@ all stable changes of the first version of Recon.

*2.x*

- 2.3.2 (current Master)
- Allow the `return_to` option in `recon_trace`
- 2.3.1
- Updated `app_deps` script to run with rebar3 dependencies
- Minor docs update
Expand Down
Binary file removed rebar
Binary file not shown.
2 changes: 1 addition & 1 deletion src/recon.app.src
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{application, recon,
[{description, "Diagnostic tools for production use"},
{vsn, "2.3.1"},
{vsn, "2.3.2"},
{modules, [recon, recon_alloc, recon_lib, recon_trace]},
{registered, []},
{applications, [kernel, stdlib]},
Expand Down
21 changes: 19 additions & 2 deletions src/recon_trace.erl
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@
| {args, args | arity} % default: args
| {io_server, pid()} % default: group_leader()
| {formatter, formatterfun()} % default: internal formatter
| return_to | {return_to, boolean()} % default: false
%% match pattern options
| {scope, global | local} % default: global
].
Expand Down Expand Up @@ -308,6 +309,11 @@ calls(TSpecs = [_|_], Max) ->
%% <li>`{io_server, pid() | atom()}': by default, recon logs to the current
%% group leader, usually the shell. This option allows to redirect
%% trace output to a different IO server (such as a file handle).</li>
%% <li>`return_to': If this option is set (in conjunction with the match
%% option `{scope, local}'), the function to which the value is returned
%% is output in a trace. Note that this is distinct from giving the
%% *caller* since exception handling or calls in tail position may
%% hide the original caller.</li>
%% </ul>
%%
%% Also note that putting extremely large `Max' values (i.e. `99999999' or
Expand Down Expand Up @@ -420,15 +426,26 @@ trace_calls(TSpecs, Pid, Opts) ->

validate_opts(Opts) ->
PidSpecs = validate_pid_specs(proplists:get_value(pid, Opts, all)),
Scope = proplists:get_value(scope, Opts, global),
TraceOpts = case proplists:get_value(timestamp, Opts, formatter) of
formatter -> [];
trace -> [timestamp]
end ++
case proplists:get_value(args, Opts, args) of
args -> [];
arity -> [arity]
end ++
case proplists:get_value(return_to, Opts, undefined) of
true when Scope =:= local ->
[return_to];
true when Scope =:= global ->
io:format("Option return_to only works with option {scope, local}~n"),
%% Set it anyway
[return_to];
_ ->
[]
end,
MatchOpts = [proplists:get_value(scope, Opts, global)],
MatchOpts = [Scope],
{PidSpecs, TraceOpts, MatchOpts}.

%% Support the regular specs, but also allow `recon:pid_term()' and lists
Expand Down Expand Up @@ -498,7 +515,7 @@ format(TraceMsg) ->
{"~p:~p~s", [M,F,format_args(Args)]};
%% {trace, Pid, return_to, {M, F, Arity}}
{return_to, [{M,F,Arity}]} ->
{"~p:~p/~p", [M,F,Arity]};
{" '--> ~p:~p/~p", [M,F,Arity]};
%% {trace, Pid, return_from, {M, F, Arity}, ReturnValue}
{return_from, [{M,F,Arity}, Return]} ->
{"~p:~p/~p --> ~p", [M,F,Arity, Return]};
Expand Down

0 comments on commit 8f960ab

Please sign in to comment.