コード例 #1
0
            internal void Populate(Metric metric, DateTime now)
            {
                var summary   = new Contracts.Summary();
                var quantiles = new Quantile[_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 Quantile
                            {
                                quantile = rank,
                                Value    = q
                            };
                        }
                    }
                }

                if (quantiles.Length > 0)
                {
                    Array.Sort(quantiles, _quantileComparer);
                }

                foreach (var quantile in quantiles)
                {
                    summary.Quantiles.Add(quantile);
                }

                metric.Summary = summary;
            }
コード例 #2
0
            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.Summary();

                foreach (var quantileEpsilonPair in _objectives)
                {
                    _wireMetric.Quantiles.Add(new Quantile
                    {
                        quantile = quantileEpsilonPair.Quantile
                    });
                }
            }