Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'add-print_p-option' of https://github.com/slfritchie/eper

… into slfritchie-add-print_p-option
  • Loading branch information...
commit 0c1ad06c6f6ab496a49ab045a7826090a9cece2b 2 parents 145d552 + dbb37c7
mats cronqvist authored
Showing with 21 additions and 16 deletions.
  1. +21 −16 src/redbug.erl
View
37 src/redbug.erl
@@ -33,6 +33,8 @@
, print_call = true % print calls (see `return_only')
, print_form = "~s~n" % format for printing
, print_file = "" % file to print to (standard_io)
+ , print_msec = false % print milliseconds in timestamps?
+ , print_p = 999999 % Limit for "~P" formatting depth
, print_re = "" % regexp that must match to print
, max_queue = 5000 % max # of msgs before suicide
, max_msg_size = 50000 % max message size before suicide
@@ -97,6 +99,8 @@ help() ->
, "buffered (no) buffer messages till end of trace"
, "print_form (\"~s~n\") print msgs using this format"
, "print_file (standard_io) print to this file"
+ , "print_msec (false) print milliseconds on timestamps"
+ , "print_p (999999) formatting depth for \"~P\""
, "print_re (\"\") print only strings that match this"
, " trc file related opts"
, "file (none) use a trc file based on this name"
@@ -262,9 +266,9 @@ maybe_new_target(Cnf = #cnf{target=Target}) ->
false-> Cnf#cnf{target=to_atom(Str++"@"++element(2,inet:gethostname()))}
end.
-maybe_print(Cnf) ->
+maybe_print(#cnf{print_p = Print_p, print_msec = MsecP} = Cnf) ->
PF = the_print_fun(Cnf),
- Cnf#cnf{print_pid=spawn_link(fun()->printi(PF) end)}.
+ Cnf#cnf{print_pid=spawn_link(fun()->printi(PF,Print_p,MsecP) end)}.
the_print_fun(Cnf) ->
PrintFun = mk_the_print_fun(Cnf),
@@ -377,37 +381,38 @@ slist(L) when is_list(L) -> usort(L);
slist(X) -> [X].
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-printi(PrintFun) ->
+printi(PrintFun,FmtP_Depth,MsecP) ->
receive
{trace_consumer,TC} ->
erlang:monitor(process,TC),
- printl(PrintFun)
+ printl(PrintFun,FmtP_Depth,MsecP)
end.
-printl(PrintFun) ->
+printl(PrintFun,FmtP_Depth,MsecP) ->
receive
{'DOWN',_,_,_,R} -> io:fwrite("quitting: ~p~n",[R]);
- X -> outer(PrintFun,X), printl(PrintFun)
+ X -> outer(PrintFun,FmtP_Depth,MsecP,X), printl(PrintFun,FmtP_Depth,MsecP)
end.
-outer(_,[]) -> ok;
-outer(PrintFun,[Msg|Msgs]) ->
+outer(_,_,_,[]) -> ok;
+outer(PrintFun,FmtP_Depth,MsecP,[Msg|Msgs]) ->
case Msg of
{'call',{MFA,Bin},PI,TS} ->
- PrintFun(flat("~n~s <~p> ~p",[ts(TS),PI,MFA])),
- foreach(fun(L)->PrintFun(flat(" ~s",[L])) end, stak(Bin));
+ PrintFun(flat("~n~s <~p> ~P",[ts(TS,MsecP),PI,MFA,FmtP_Depth])),
+ foreach(fun(L)->PrintFun(flat(" ~P",[L,FmtP_Depth])) end, stak(Bin));
{'retn',{MFA,Val},PI,TS} ->
- PrintFun(flat("~n~s <~p> ~p -> ~p",[ts(TS),PI,MFA,Val]));
+ PrintFun(flat("~n~s <~p> ~p -> ~P",[ts(TS,MsecP),PI,MFA,Val,FmtP_Depth]));
{'send',{MSG,To},PI,TS} ->
- PrintFun(flat("~n~s <~p> <~p> <<< ~p",[ts(TS),PI,To,MSG]));
+ PrintFun(flat("~n~s <~p> <~p> <<< ~P",[ts(TS,MsecP),PI,To,MSG,FmtP_Depth]));
{'recv',MSG,PI,TS} ->
- PrintFun(flat("~n~s <~p> <<< ~p",[ts(TS),PI,MSG]));
+ PrintFun(flat("~n~s <~p> <<< ~P",[ts(TS,MsecP),PI,MSG,FmtP_Depth]));
_ ->
- PrintFun(flat("~n~p", [Msg]))
+ PrintFun(flat("~n~P", [Msg,FmtP_Depth]))
end,
- outer(PrintFun,Msgs).
+ outer(PrintFun,FmtP_Depth,MsecP,Msgs).
-ts({H,M,S,_Us}) -> flat("~2.2.0w:~2.2.0w:~2.2.0w",[H,M,S]).
+ts({H,M,S,_Us},false) -> flat("~2.2.0w:~2.2.0w:~2.2.0w",[H,M,S]);
+ts({H,M,S,Us},_) -> flat("~2.2.0w:~2.2.0w:~2.2.0w.~3.3.0w",[H,M,S,Us div 1000]).
flat(Form,List) -> flatten(io_lib:fwrite(Form,List)).
Please sign in to comment.
Something went wrong with that request. Please try again.