internal void Populate(CMetric cMetric, DateTime now) { var summary = new Contracts.CSummary(); var quantiles = new CQuantile[_objectives.Count]; lock (_bufLock) { lock (_lock) { // Swap bufs even if hotBuf is empty to set new hotBufExpTime. SwapBufs(now); FlushColdBuf(); summary.SampleCount = _count; summary.SampleSum = _sum; for (var idx = 0; idx < _sortedObjectives.Length; idx++) { var rank = _sortedObjectives[idx]; var q = _headStream.Count == 0 ? double.NaN : _headStream.Query(rank); quantiles[idx] = new CQuantile { Quantile = rank, Value = q }; } } } if (quantiles.Length > 0) { Array.Sort(quantiles, _quantileComparer); } foreach (var quantile in quantiles) { summary.Quantiles.Add(quantile); } cMetric.CSummary = summary; }
internal void Init(ICollector parent, LabelValues labelValues, DateTime now) { base.Init(parent, labelValues); _objectives = ((Summary)parent)._objectives; _maxAge = ((Summary)parent)._maxAge; _ageBuckets = ((Summary)parent)._ageBuckets; _bufCap = ((Summary)parent)._bufCap; _sortedObjectives = new double[_objectives.Count]; _hotBuf = new SampleBuffer(_bufCap); _coldBuf = new SampleBuffer(_bufCap); _streamDuration = new TimeSpan(_maxAge.Ticks / _ageBuckets); _headStreamExpTime = now.Add(_streamDuration); _hotBufExpTime = _headStreamExpTime; _streams = new QuantileStream[_ageBuckets]; for (var i = 0; i < _ageBuckets; i++) { _streams[i] = QuantileStream.NewTargeted(_objectives); } _headStream = _streams[0]; for (var i = 0; i < _objectives.Count; i++) { _sortedObjectives[i] = _objectives[i].Quantile; } Array.Sort(_sortedObjectives); _wireMetric = new Contracts.CSummary(); foreach (var quantileEpsilonPair in _objectives) { _wireMetric.Quantiles.Add(new CQuantile { Quantile = quantileEpsilonPair.Quantile }); } }