Performance counter values at a point in time
示例#1
0
        /// <summary>
        /// Resets the counter
        /// </summary>
        protected PerfCounterStats GetValuesAndReset()
        {
            PerfCounterStats pv = new PerfCounterStats
            {
                Id = this.Id,
                Sum = Interlocked.Exchange(ref _sum, 0),
                Count = Interlocked.Exchange(ref _count, 0),
                Min = Interlocked.Exchange(ref _min, Int32.MaxValue),
                Max = Interlocked.Exchange(ref _max, Int32.MinValue)
            };
            pv.Avg = pv.Count == 0 ? 0 : pv.Sum / pv.Count;
            pv.StartTime = this._lastReset;
            pv.EndTime = DateTime.Now;
            var df = (pv.EndTime - pv.StartTime).TotalSeconds;
            pv.Freq = pv.Count == 0 ? 0.0 : df / pv.Count;

            return pv;
        }
示例#2
0
 protected PerfCounterStats GetValues(bool reset)
 {
     PerfCounterStats pv = new PerfCounterStats
     {
         Id = this.Id,
         Sum = Interlocked.Exchange(ref _sum, reset ? 0L : _sum),
         Count = Interlocked.Exchange(ref _count, reset ? 0 : _count),
         Min = Interlocked.Exchange(ref _min, reset ? Int32.MaxValue : _min),
         Max = Interlocked.Exchange(ref _max, reset ? Int32.MinValue : _max),
         StartTime = _lastReset,
         EndTime = DateTime.Now
     };
     var dt = _data;
     if (reset)
     {
         var c = MaxUpdates;
         _lastReset = _lastUpdate = DateTime.Now;
         dt = Interlocked.Exchange(ref _data, new ConcurrentCircularBuffer<int>(c));
     }
     int[] dd = dt.ToArray();
     if (dd.Length > 0)
     {
         Array.Sort(dd);
         pv.Median = dd[dd.Length / 2];
         pv.Perc90 = dd[(int)((dd.Length - 1) * 0.90)];
         pv.Perc95 = dd[(int)((dd.Length - 1) * 0.95)];
         pv.Perc98 = dd[(int)((dd.Length - 1) * 0.98)];
     }
     if (pv.Count == 0)
     {
         pv.Min = 0;
         pv.Max = 0;
         pv.Freq = 0;
     }
     else
     {
         pv.Avg = (double) pv.Sum / pv.Count;
         pv.Freq = (double)pv.Count / (pv.EndTime - pv.StartTime).TotalSeconds;
     }
     return pv;
 }
示例#3
0
 public PerfCounterStats CalculateCurrentStats()
 {
     var pc = new PerfCounterStats();
     pc.Id = this.Id;
     pc.StartTime = this.FrameStart;
     pc.EndTime = DateTime.Now;
     pc.Count = Data.Count;
     if (Data.Count == 0) return pc;
     Data.Sort();
     pc.Min = Data[0];
     pc.Max = Data[Data.Count - 1];
     pc.Median = GetPercentile(Data, 50);
     pc.Perc95 = GetPercentile(Data, 95);
     pc.Perc98 = GetPercentile(Data, 98);
     pc.Perc90 = GetPercentile(Data, 90);
     pc.Sum = Data.Sum();
     return pc;
 }