Skip to content

Commit

Permalink
tools: Use zip comprehensions
Browse files Browse the repository at this point in the history
  • Loading branch information
bjorng committed Oct 12, 2024
1 parent f97112c commit 8a743c1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
2 changes: 1 addition & 1 deletion lib/tools/src/lcnt.erl
Original file line number Diff line number Diff line change
Expand Up @@ -959,7 +959,7 @@ summate_stats([S|Ss], #stats{ tries = Tries, colls = Colls, time = Time, nt = Nt
summate_histogram(Tup,undefined) when is_tuple(Tup) -> Tup;
summate_histogram(undefined,Tup) when is_tuple(Tup) -> Tup;
summate_histogram(Hs1,Hs2) ->
list_to_tuple([ A + B || {A,B} <- lists:zip(tuple_to_list(Hs1),tuple_to_list(Hs2))]).
list_to_tuple([A + B || A <- tuple_to_list(Hs1) && B <- tuple_to_list(Hs2)]).

%% manipulators
filter_locks_type(Locks, undefined) -> Locks;
Expand Down
34 changes: 19 additions & 15 deletions lib/tools/src/tprof.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1123,12 +1123,14 @@ format_impl(Device, {Type, Total, Inspected}) ->
format_each(Device, Type, Total, Inspected).

format_each(Device, call_count, _Total, Inspected) ->
{Widths, Lines} = lists:foldl(
fun ({Mod, {F, A}, Calls, _Value, _VPC, Percent}, {Widths, Ln}) ->
Line = [lists:flatten(io_lib:format("~tw:~tw/~w", [Mod, F, A])),
integer_to_list(Calls), float_to_list(Percent, [{decimals, 2}])],
NewWidths = [erlang:max(Old, New) || {Old, New} <- lists:zip([string:length(L) || L <- Line], Widths)],
{NewWidths, [Line | Ln]}
{Widths, Lines} =
lists:foldl(
fun ({Mod, {F, A}, Calls, _Value, _VPC, Percent}, {Widths, Ln}) ->
Line = [lists:flatten(io_lib:format("~tw:~tw/~w", [Mod, F, A])),
integer_to_list(Calls), float_to_list(Percent, [{decimals, 2}])],
NewWidths = [max(Old, New) ||
Old <- [string:length(L) || L <- Line] && New <- Widths],
{NewWidths, [Line | Ln]}
end, {[0, 5, 5], []}, Inspected),

%% figure out formatting line
Expand All @@ -1146,15 +1148,17 @@ format_labelled(Device, Label, Total, Inspected) ->
%% The width of the value is either total or label
ValueWidth = erlang:max(length(Label), length(integer_to_list(Total))),

{Widths, Lines} = lists:foldl(
fun ({Mod, {F, A}, Calls, Value, VPC, Percent}, {Widths, Ln}) ->
Line = [lists:flatten(io_lib:format("~tw:~tw/~w", [Mod, F, A])),
integer_to_list(Calls), integer_to_list(Value),
float_to_list(VPC, [{decimals, 2}]),
float_to_list(Percent, [{decimals, 2}])],
NewWidths = [erlang:max(Old, New) || {Old, New} <- lists:zip([string:length(L) || L <- Line], Widths)],
{NewWidths, [Line | Ln]}
end, {[0, 5, ValueWidth, 8, 5], []}, Inspected),
{Widths, Lines} =
lists:foldl(
fun ({Mod, {F, A}, Calls, Value, VPC, Percent}, {Widths, Ln}) ->
Line = [lists:flatten(io_lib:format("~tw:~tw/~w", [Mod, F, A])),
integer_to_list(Calls), integer_to_list(Value),
float_to_list(VPC, [{decimals, 2}]),
float_to_list(Percent, [{decimals, 2}])],
NewWidths = [max(Old, New) ||
Old <- [string:length(L) || L <- Line] && New <- Widths],
{NewWidths, [Line | Ln]}
end, {[0, 5, ValueWidth, 8, 5], []}, Inspected),

%% figure out formatting line
Fmt = lists:flatten(io_lib:format("~~.~wts ~~~ws ~~~wts ~~~ws [~~~ws]~~n", Widths)),
Expand Down

0 comments on commit 8a743c1

Please sign in to comment.