how to check, if a function has been called
Ulf Wiger
ulf@REDACTED
Thu Jul 21 00:47:13 CEST 2005
Den 2005-07-20 23:41:22 skrev MEENA SELVAM <meena_selvam@REDACTED>:
> Hi,
> When I run a erlang program , how can i check a method
> has been called.. apart from putting prints
>
> just typing a function name or similar..?
> meena
You can use the dbg.erl module, which makes use of the
built-in trace support in Erlang.
Example:
Eshell V5.4.8 (abort with ^G)
1> dbg:tracer().
{ok,<0.32.0>}
2> dbg:tp(lists,sort,'_',[]).
{ok,[{matched,nonode@REDACTED,2}]}
3> dbg:p(all,[c]).
{ok,[{matched,nonode@REDACTED,25}]}
4> lists:sort([4,3,1,5,2]).
(<0.30.0>) call lists:sort([4,3,1,5,2]) <== Here!
[1,2,3,4,5]
If you want to see what the function returns:
Eshell V5.4.8 (abort with ^G)
1> dbg:tracer().
{ok,<0.32.0>}
2> dbg:tp(lists,sort,'_',dbg:fun2ms(fun(_) -> return_trace() end)).
{ok,[{matched,nonode@REDACTED,2},{saved,1}]}
3> dbg:p(all,[c]).
{ok,[{matched,nonode@REDACTED,25}]}
4> lists:sort([4,3,1,5,2]).
(<0.30.0>) call lists:sort([4,3,1,5,2])
[1,2,3,4,5](<0.30.0>) returned from lists:sort/1 -> [1,2,3,4,5] <=== !
dbg:tp/4 defines a trace pattern on exported functions.
dbg:tpl/4 does the same for non-exported functions.
Regards,
Uffe
More information about the erlang-questions
mailing list