Optimise formatting of channel stats
Avoids traversing the full list to format a single element [#152240490]
This commit is contained in:
		
							parent
							
								
									0d1987f0a0
								
							
						
					
					
						commit
						8e5aebe8a1
					
				|  | @ -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)}; | ||||
|  |  | |||
|  | @ -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}; | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue