Optimise formatting of channel stats

Avoids traversing the full list to format a single element

[#152240490]
This commit is contained in:
Diana Corbacho 2017-10-25 08:34:56 +01:00
parent 0d1987f0a0
commit 8e5aebe8a1
2 changed files with 9 additions and 7 deletions

View File

@ -76,10 +76,10 @@ format_queue_stats({disk_writes, _}) ->
format_queue_stats(Stat) ->
[Stat].
format_channel_stats({idle_since, Value}) ->
{idle_since, now_to_str(Value)};
format_channel_stats(Stat) ->
Stat.
format_channel_stats([{idle_since, Value} | Rest]) ->
[{idle_since, now_to_str(Value)} | Rest];
format_channel_stats(Stats) ->
Stats.
format_arguments({arguments, Value}) ->
{arguments, amqp_table(Value)};

View File

@ -246,9 +246,11 @@ aggregate_entry({Id, Metrics}, NextStats, Ops0,
end;
aggregate_entry({Id, Metrics}, NextStats, Ops0,
#state{table = channel_metrics} = State) ->
Ftd = rabbit_mgmt_format:format(Metrics,
{fun rabbit_mgmt_format:format_channel_stats/1, true}),
%% First metric must be `idle_since` (if available), as expected by
%% `rabbit_mgmt_format:format_channel_stats`. This is a performance
%% optimisation that avoids traversing the whole list when only
%% one element has to be formatted.
Ftd = rabbit_mgmt_format:format_channel_stats(Metrics),
Entry = ?channel_stats(Id, Ftd),
Ops = insert_op(channel_stats, Id, Entry, Ops0),
{NextStats, Ops, State};