aboutsummaryrefslogtreecommitdiffstats
path: root/lib/tools
diff options
context:
space:
mode:
authorBjörn-Egil Dahlberg <[email protected]>2010-06-03 11:33:28 +0200
committerBjörn-Egil Dahlberg <[email protected]>2010-06-09 14:26:05 +0200
commit7727bce757f709e94ea39dae3cbcf09c370e6b12 (patch)
tree378771ea5b8720b6490dcbc395a1fd112e109aa4 /lib/tools
parenta65462258ce6a4ed0cb63a9fa6ee2cd686a5edfa (diff)
downloadotp-7727bce757f709e94ea39dae3cbcf09c370e6b12.tar.gz
otp-7727bce757f709e94ea39dae3cbcf09c370e6b12.tar.bz2
otp-7727bce757f709e94ea39dae3cbcf09c370e6b12.zip
Rename sorting choices for eprof
- Added {sort, mfa} option
Diffstat (limited to 'lib/tools')
-rw-r--r--lib/tools/src/eprof.erl91
1 files changed, 49 insertions, 42 deletions
diff --git a/lib/tools/src/eprof.erl b/lib/tools/src/eprof.erl
index 6c38df8018..2b71b16c82 100644
--- a/lib/tools/src/eprof.erl
+++ b/lib/tools/src/eprof.erl
@@ -129,42 +129,6 @@ init([]) ->
%% analyze
-sum_bp_total_n_us(Mfas) ->
- lists:foldl(fun ({_, {Ci,Usi}}, {Co, Uso}) -> {Co + Ci, Uso + Usi} end, {0,0}, Mfas).
-
-string_bp_mfa(Mfas, Tus) -> string_bp_mfa(Mfas, Tus, {0,0,0,0,0}, []).
-string_bp_mfa([], _, Ws, Strings) -> {Ws, lists:reverse(Strings)};
-string_bp_mfa([{Mfa, {Count, Time}}|Mfas], Tus, {MfaW, CountW, PercW, TimeW, TpCW}, Strings) ->
- Smfa = s(Mfa),
- Scount = s(Count),
- Stime = s(Time),
- Sperc = s("~.2f", [100*(Time/Tus)]),
- Stpc = s("~.2f", [Time/Count]),
-
- string_bp_mfa(Mfas, Tus, {
- erlang:max(MfaW, length(Smfa)),
- erlang:max(CountW,length(Scount)),
- erlang:max(PercW, length(Sperc)),
- erlang:max(TimeW, length(Stime)),
- erlang:max(TpCW, length(Stpc))
- }, [[Smfa, Scount, Sperc, Stime, Stpc] | Strings]).
-
-print_bp_mfa(Mfas, {_Tn, Tus}, Fd, Opts) ->
- Fmfas = filter_mfa(sort_mfa(Mfas, proplists:get_value(sort, Opts)), proplists:get_value(thresholds, Opts)),
- {{MfaW, CountW, PercW, TimeW, TpCW}, Strs} = string_bp_mfa(Fmfas, Tus),
- Ws = {
- erlang:max(length("FUNCTION"), MfaW),
- erlang:max(length("CALLS"), CountW),
- erlang:max(length(" %"), PercW),
- erlang:max(length("TIME"), TimeW),
- erlang:max(length("uS / CALLS"), TpCW)
- },
- print(Fd, Ws, ["FUNCTION", "CALLS", " %", "TIME", "uS / CALLS"]),
- print(Fd, Ws, ["--------", "-----", "---", "----", "----------"]),
-
- lists:foreach(fun (String) -> print(Fd, Ws, String) end, Strs),
- ok.
-
handle_call({analyze, _, _}, _, #state{ bpd = #bpd{ p = {0,nil}, us = 0, n = 0} = Bpd } = S) when is_record(Bpd, bpd) ->
{reply, nothing_to_analyze, S};
@@ -187,7 +151,7 @@ handle_call({analyze, Type, _Opts}, _, S) ->
%% profile
-handle_call({profile, _Rootset, _Pattern, _M,_F,_A}, _From, #state{ profiling = true } = S)->
+handle_call({profile, _Rootset, _Pattern, _M,_F,_A}, _From, #state{ profiling = true } = S) ->
{reply, {error, already_profiling}, S};
handle_call({profile, Rootset, Pattern, M,F,A}, From, #state{fd = Fd } = S) ->
@@ -214,6 +178,9 @@ handle_call({profile, Rootset, Pattern, M,F,A}, From, #state{fd = Fd } = S) ->
{reply, error, #state{ fd = Fd}}
end;
+handle_call({profile, _Rootset, _Pattern}, _From, #state{ profiling = true } = S) ->
+ {reply, {error, already_profiling}, S};
+
handle_call({profile, Rootset, Pattern}, From, #state{ fd = Fd } = S) ->
set_pattern_trace(false, S#state.pattern),
@@ -443,18 +410,22 @@ collect_bpdfp(Mfa, Tree, Data) ->
end, {0,0, Tree}, Data).
%% manipulators
-
-sort_mfa(Bpfs, ascending) when is_list(Bpfs) ->
+sort_mfa(Bpfs, mfa) when is_list(Bpfs) ->
lists:sort(fun
- ({_,{_,A}}, {_,{_,B}}) when A > B -> true;
+ ({A,_}, {B,_}) when A < B -> true;
(_, _) -> false
end, Bpfs);
-sort_mfa(Bpfs, descending) when is_list(Bpfs) ->
+sort_mfa(Bpfs, time) when is_list(Bpfs) ->
+ lists:sort(fun
+ ({_,{A,_}}, {_,{B,_}}) when A < B -> true;
+ (_, _) -> false
+ end, Bpfs);
+sort_mfa(Bpfs, calls) when is_list(Bpfs) ->
lists:sort(fun
({_,{_,A}}, {_,{_,B}}) when A < B -> true;
(_, _) -> false
end, Bpfs);
-sort_mfa(Bpfs, _) when is_list(Bpfs) -> sort_mfa(Bpfs, ascending).
+sort_mfa(Bpfs, _) when is_list(Bpfs) -> sort_mfa(Bpfs, calls).
filter_mfa(Bpfs, Ts) when is_list(Ts) ->
filter_mfa(Bpfs, [], proplists:get_value(calls, Ts, 0), proplists:get_value(time, Ts, 0));
@@ -463,8 +434,44 @@ filter_mfa([], Out, _, _) -> lists:reverse(Out);
filter_mfa([{_, {C, T}}=Bpf|Bpfs], Out, Ct, Tt) when C >= Ct, T >= Tt -> filter_mfa(Bpfs, [Bpf|Out], Ct, Tt);
filter_mfa([_|Bpfs], Out, Ct, Tt) -> filter_mfa(Bpfs, Out, Ct, Tt).
+sum_bp_total_n_us(Mfas) ->
+ lists:foldl(fun ({_, {Ci,Usi}}, {Co, Uso}) -> {Co + Ci, Uso + Usi} end, {0,0}, Mfas).
+
%% strings and format
+string_bp_mfa(Mfas, Tus) -> string_bp_mfa(Mfas, Tus, {0,0,0,0,0}, []).
+string_bp_mfa([], _, Ws, Strings) -> {Ws, lists:reverse(Strings)};
+string_bp_mfa([{Mfa, {Count, Time}}|Mfas], Tus, {MfaW, CountW, PercW, TimeW, TpCW}, Strings) ->
+ Smfa = s(Mfa),
+ Scount = s(Count),
+ Stime = s(Time),
+ Sperc = s("~.2f", [100*(Time/Tus)]),
+ Stpc = s("~.2f", [Time/Count]),
+
+ string_bp_mfa(Mfas, Tus, {
+ erlang:max(MfaW, length(Smfa)),
+ erlang:max(CountW,length(Scount)),
+ erlang:max(PercW, length(Sperc)),
+ erlang:max(TimeW, length(Stime)),
+ erlang:max(TpCW, length(Stpc))
+ }, [[Smfa, Scount, Sperc, Stime, Stpc] | Strings]).
+
+print_bp_mfa(Mfas, {_Tn, Tus}, Fd, Opts) ->
+ Fmfas = filter_mfa(sort_mfa(Mfas, proplists:get_value(sort, Opts)), proplists:get_value(filter, Opts)),
+ {{MfaW, CountW, PercW, TimeW, TpCW}, Strs} = string_bp_mfa(Fmfas, Tus),
+ Ws = {
+ erlang:max(length("FUNCTION"), MfaW),
+ erlang:max(length("CALLS"), CountW),
+ erlang:max(length(" %"), PercW),
+ erlang:max(length("TIME"), TimeW),
+ erlang:max(length("uS / CALLS"), TpCW)
+ },
+ print(Fd, Ws, ["FUNCTION", "CALLS", " %", "TIME", "uS / CALLS"]),
+ print(Fd, Ws, ["--------", "-----", "---", "----", "----------"]),
+
+ lists:foreach(fun (String) -> print(Fd, Ws, String) end, Strs),
+ ok.
+
s({M,F,A}) -> s("~w:~w/~w",[M,F,A]);
s(Term) -> s("~p", [Term]).
s(Format, Terms) -> lists:flatten(io_lib:format(Format, Terms)).