|
29 | 29 | reduce_call_trees/1, |
30 | 30 | top_call_trees/0, top_call_trees/1, top_call_trees/2, |
31 | 31 | print_sorted_call_stat/2, |
32 | | - sorted_call_stat/1, |
| 32 | + sorted_call_stat/1, sorted_call_stat/2, |
33 | 33 | call_stat/1, call_stat/2]). |
34 | 34 |
|
35 | 35 | %% API - utilities |
|
181 | 181 | -type tb_acc_list() :: [[tr()]]. |
182 | 182 | -type tb_acc() :: tb_acc_tree() | tb_acc_list(). |
183 | 183 |
|
| 184 | +-type sorted_call_stat_options() :: #{sort_by => call_stat_field()}. |
| 185 | +%% Options for sorted call statistics. |
| 186 | +%% |
| 187 | +%% `sort_by' is the field name to sort by (default: `acc_time'). |
| 188 | + |
| 189 | +-type call_stat_field() :: count | acc_time | own_time. |
| 190 | + |
184 | 191 | -type call() :: {call, {module(), atom(), list()}}. |
185 | 192 | -type result() :: {return | exception, any()}. % Result of a function call. |
186 | 193 | -type simple_tr() :: call() | result(). |
@@ -482,7 +489,14 @@ print_sorted_call_stat(KeyF, Limit) -> |
482 | 489 | %% @see call_stat/1 |
483 | 490 | -spec sorted_call_stat(selector(Key)) -> [{Key, call_count(), acc_time(), own_time()}]. |
484 | 491 | sorted_call_stat(KeyF) -> |
485 | | - lists:reverse(sort_by_time(call_stat(KeyF))). |
| 492 | + sorted_call_stat(KeyF, #{}). |
| 493 | + |
| 494 | +%% @doc TODO |
| 495 | +-spec sorted_call_stat(selector(Key), sorted_call_stat_options()) -> |
| 496 | + [{Key, call_count(), acc_time(), own_time()}]. |
| 497 | +sorted_call_stat(KeyF, Options) -> |
| 498 | + SortBy = maps:get(sort_by, Options, acc_time), |
| 499 | + lists:reverse(sort_call_stat(SortBy, call_stat(KeyF))). |
486 | 500 |
|
487 | 501 | %% @doc Returns call time statistics for traces selected from `tab()'. |
488 | 502 | %% |
@@ -1018,8 +1032,15 @@ filter_range(_PrefF, #tr{event = Event}, _State, _MaxDepth) when ?is_msg(Event) |
1018 | 1032 |
|
1019 | 1033 | %% Call stat |
1020 | 1034 |
|
1021 | | -sort_by_time(MapStat) -> |
1022 | | - lists:keysort(3, [{Key, Count, AccTime, OwnTime} || {Key, {Count, AccTime, OwnTime}} <- maps:to_list(MapStat)]). |
| 1035 | +-spec sort_call_stat(call_stat_field(), #{Key => {call_count(), acc_time(), own_time()}}) -> |
| 1036 | + [{Key, call_count(), acc_time(), own_time()}]. |
| 1037 | +sort_call_stat(SortBy, MapStat) -> |
| 1038 | + Rows = [{Key, Count, AccTime, OwnTime} || {Key, {Count, AccTime, OwnTime}} <- maps:to_list(MapStat)], |
| 1039 | + lists:keysort(sort_by_pos(SortBy), Rows). |
| 1040 | + |
| 1041 | +sort_by_pos(count) -> 2; |
| 1042 | +sort_by_pos(acc_time) -> 3; |
| 1043 | +sort_by_pos(own_time) -> 4. |
1023 | 1044 |
|
1024 | 1045 | call_stat_step(_KeyF, #tr{event = Event}, State) when ?is_msg(Event) -> |
1025 | 1046 | State; |
|
0 commit comments