/// <nodoc /> public static CounterSet ToCounterSet(this CounterCollection counters) { var counterSet = new CounterSet(); foreach ((var counter, var counterName) in counters.GetCounters()) { counterSet.Add($"{counterName}.Count", (long)counter.Value, counter.Name); if (counter.IsStopwatch) { counterSet.Add($"{counterName}.AverageMs", counter.Value != 0 ? (long)counter.Duration.TotalMilliseconds / counter.Value : 0); counterSet.Add($"{counterName}.DurationMs", (long)counter.Duration.TotalMilliseconds); } } return(counterSet); }