private TimerMetric(TimeUnit durationUnit, TimeUnit rateUnit, MeterMetric meter, HistogramMetric histogram, bool clear) { DurationUnit = durationUnit; RateUnit = rateUnit; _meter = meter; _histogram = histogram; if (clear) { Clear(); } }
public IImmutableDictionary <MetricName, IMetric> GetSample(MetricType typeFilter = MetricType.All) { if (typeFilter.HasFlagFast(MetricType.All)) { return(NoSample); } var filtered = new Dictionary <MetricName, IMetric>(); foreach (var entry in _inner) { switch (entry.Value) { case GaugeMetric _ when typeFilter.HasFlagFast(MetricType.Gauge): case CounterMetric _ when typeFilter.HasFlagFast(MetricType.Counter): case MeterMetric _ when typeFilter.HasFlagFast(MetricType.Meter): case HistogramMetric _ when typeFilter.HasFlagFast(MetricType.Histogram): case TimerMetric _ when typeFilter.HasFlagFast(MetricType.Timer): continue; default: filtered.Add(entry.Key, entry.Value); break; } } return(filtered.ToImmutableSortedDictionary(k => k.Key, v => { return v.Value switch { GaugeMetric gauge => gauge.Copy(), CounterMetric counter => counter.Copy(), MeterMetric meter => meter.Copy(), HistogramMetric histogram => histogram.Copy(), TimerMetric timer => timer.Copy(), _ => throw new ArgumentException() }; }));