예제 #1
0
        internal PerformanceMonitor(IFrameBasedClock clock, IEnumerable <StatisticsCounterType> counters)
        {
            Clock        = clock;
            currentFrame = FramesHeap.ReserveObject();

            foreach (var c in counters)
            {
                activeCounters[(int)c] = true;
            }

            for (int i = 0; i < FrameStatistics.NUM_PERFORMANCE_COLLECTION_TYPES; i++)
            {
                var t = (PerformanceCollectionType)i;
                endCollectionDelegates[i] = new InvokeOnDisposal(() => endCollecting(t));
            }
        }
예제 #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();
        }
예제 #3
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();
        }