Esempio n. 1
0
        /// <summary>
        /// Resets all frame statistics. Run exactly once per frame.
        /// </summary>
        public void NewFrame()
        {
            // Reset the counters we keep track of
            for (int i = 0; i < ActiveCounters.Length; ++i)
            {
                if (ActiveCounters[i])
                {
                    long count = FrameStatistics.COUNTERS[i];
                    var  type  = (StatisticsCounterType)i;

                    if (!globalStatistics.TryGetValue(type, out var global))
                    {
                        globalStatistics[type] = global = GlobalStatistics.Get <long>(threadName, type.ToString());
                    }

                    global.Value = count;
                    currentFrame.Counts[type]    = count;
                    currentFrame.FramesPerSecond = Clock.FramesPerSecond;

                    FrameStatistics.COUNTERS[i] = 0;
                }
            }

            if (PendingFrames.Count < max_pending_frames - 1)
            {
                PendingFrames.Enqueue(currentFrame);
                currentFrame = FramesPool.Get();
            }

            currentFrame.Clear();

            if (HandleGC)
            {
                for (int i = 0; i < lastAmountGarbageCollects.Length; ++i)
                {
                    int amountCollections = GC.CollectionCount(i);

                    if (lastAmountGarbageCollects[i] != amountCollections)
                    {
                        lastAmountGarbageCollects[i] = amountCollections;
                        currentFrame.GarbageCollections.Add(i);
                    }
                }
            }

            double dampRate = Math.Max(Clock.ElapsedFrameTime, 0) / 1000;

            averageFrameTime = Interpolation.Damp(averageFrameTime, Clock.ElapsedFrameTime, 0.01, dampRate);

            //check for dropped (stutter) frames
            traceCollector?.NewFrame(Clock.ElapsedFrameTime, Math.Max(10, Math.Max(1000 / Clock.MaximumUpdateHz, averageFrameTime) * 4));

            consumeStopwatchElapsedTime();
        }
Esempio n. 2
0
        /// <summary>
        /// Resets all frame statistics. Run exactly once per frame.
        /// </summary>
        public void NewFrame()
        {
            if (currentFrame != null)
            {
                currentFrame.Postprocess();
                PendingFrames.Enqueue(currentFrame);
                if (PendingFrames.Count >= max_pending_frames)
                {
                    FrameStatistics oldFrame;
                    PendingFrames.TryDequeue(out oldFrame);
                    FramesHeap.FreeObject(oldFrame);
                }
            }

            currentFrame = FramesHeap.ReserveObject();
            currentFrame.Clear();

            if (HandleGC)
            {
                for (int i = 0; i < lastAmountGarbageCollects.Length; ++i)
                {
                    int amountCollections = GC.CollectionCount(i);
                    if (lastAmountGarbageCollects[i] != amountCollections)
                    {
                        lastAmountGarbageCollects[i] = amountCollections;
                        currentFrame.GarbageCollections.Add(i);
                    }
                }
            }

            for (int i = 0; i < (int)StatisticsCounterType.AmountTypes; ++i)
            {
                AtomicCounter counter = Counters[i];
                if (counter != null)
                {
                    currentFrame.Counts[(StatisticsCounterType)i] = counter.Reset();
                }
            }

            //check for dropped (stutter) frames
            if (Clock.ElapsedFrameTime > spike_time)
            {
                newDroppedFrame();
            }

            //reset frame totals
            currentCollectionTypeStack.Clear();
            //backgroundMonitorStackTrace = null;
            consumeStopwatchElapsedTime();
        }
Esempio n. 3
0
        /// <summary>
        /// Resets all frame statistics. Run exactly once per frame.
        /// </summary>
        public void NewFrame()
        {
            // Reset the counters we keep track of
            for (int i = 0; i < activeCounters.Length; ++i)
            {
                if (activeCounters[i])
                {
                    currentFrame.Counts[(StatisticsCounterType)i] = FrameStatistics.COUNTERS[i];
                    FrameStatistics.COUNTERS[i] = 0;
                }
            }

            PendingFrames.Enqueue(currentFrame);
            if (PendingFrames.Count >= max_pending_frames)
            {
                FrameStatistics oldFrame;
                PendingFrames.TryDequeue(out oldFrame);
                FramesHeap.FreeObject(oldFrame);
            }

            currentFrame = FramesHeap.ReserveObject();
            currentFrame.Clear();

            if (HandleGC)
            {
                for (int i = 0; i < lastAmountGarbageCollects.Length; ++i)
                {
                    int amountCollections = GC.CollectionCount(i);
                    if (lastAmountGarbageCollects[i] != amountCollections)
                    {
                        lastAmountGarbageCollects[i] = amountCollections;
                        currentFrame.GarbageCollections.Add(i);
                    }
                }
            }

            //check for dropped (stutter) frames
            if (Clock.ElapsedFrameTime > spike_time)
            {
                newDroppedFrame();
            }

            //reset frame totals
            currentCollectionTypeStack.Clear();
            //backgroundMonitorStackTrace = null;
            consumeStopwatchElapsedTime();
        }
        /// <summary>
        /// Resets all frame statistics. Run exactly once per frame.
        /// </summary>
        public void NewFrame()
        {
            // Reset the counters we keep track of
            for (int i = 0; i < activeCounters.Length; ++i)
            {
                if (activeCounters[i])
                {
                    currentFrame.Counts[(StatisticsCounterType)i] = FrameStatistics.COUNTERS[i];
                    FrameStatistics.COUNTERS[i] = 0;
                }
            }

            PendingFrames.Enqueue(currentFrame);
            if (PendingFrames.Count >= max_pending_frames)
            {
                PendingFrames.TryDequeue(out FrameStatistics oldFrame);
                FramesHeap.FreeObject(oldFrame);
            }

            currentFrame = FramesHeap.ReserveObject();
            currentFrame.Clear();

            if (HandleGC)
            {
                for (int i = 0; i < lastAmountGarbageCollects.Length; ++i)
                {
                    int amountCollections = GC.CollectionCount(i);
                    if (lastAmountGarbageCollects[i] != amountCollections)
                    {
                        lastAmountGarbageCollects[i] = amountCollections;
                        currentFrame.GarbageCollections.Add(i);
                    }
                }
            }

            //check for dropped (stutter) frames
            traceCollector.NewFrame(Clock.ElapsedFrameTime, Math.Max(10, Math.Max(1000 / Clock.MaximumUpdateHz, AverageFrameTime) * 4));

            //reset frame totals
            currentCollectionTypeStack.Clear();
            consumeStopwatchElapsedTime();
        }
Esempio n. 5
0
        /// <summary>
        /// Resets all frame statistics. Run exactly once per frame.
        /// </summary>
        internal void NewFrame()
        {
            if (currentFrame != null)
            {
                PendingFrames.Enqueue(currentFrame);
                if (PendingFrames.Count > 100)
                {
                    FrameStatistics oldFrame;
                    PendingFrames.TryDequeue(out oldFrame);
                }
            }

            currentFrame = FramesHeap.ReserveObject();
            currentFrame.Clear();

            if (HandleGC)
            {
                for (int i = 0; i < lastAmountGarbageCollects.Length; ++i)
                {
                    int amountCollections = GC.CollectionCount(i);
                    if (lastAmountGarbageCollects[i] != amountCollections)
                    {
                        lastAmountGarbageCollects[i] = amountCollections;
                        currentFrame.GarbageCollections.Add(i);
                    }
                }
            }

            //check for dropped (stutter) frames
            if (Clock.ElapsedFrameTime > spikeTime)
            {
                NewDroppedFrame();
            }

            //reset frame totals
            CurrentCollectionTypeStack.Clear();
            //backgroundMonitorStackTrace = null;
            consumeStopwatchElapsedTime();
        }