Exemplo n.º 1
0
        void DrawUIView(InternalLabeler labeler)
        {
            DrawBorderLines(Color.Gray, _memoryMonitor.LineDrawer);
            GearsetResources.Console.SolidBoxDrawer.ShowGradientBoxOnce(Position, Position + Size, new Color(56, 56, 56, 150), new Color(16, 16, 16, 127));

            if (ScaleNob.IsMouseOver)
            {
                ScaleNob.DrawBorderLines(Color.Gray);
            }

            labeler.ShowLabel(LabelName.Title, Position + new Vector2(0, -12), "Managed Memory - (allocation per tick in KB)");
        }
Exemplo n.º 2
0
        internal void Draw(InternalLabeler labeler, ProfilerManager.FrameLog frameLog)
        {
            if (GearsetResources.CurrentRenderPass != RenderPass.BasicEffectPass)
            {
                return;
            }

            if (frameLog == null || Visible == false || Config.PerformanceGraphConfig.VisibleLevelsFlags == 0)
            {
                labeler.HideLabel("__performanceGraph");
                return;
            }

            DrawBorderLines(Color.Gray, Profiler.LineDrawer);
            GearsetResources.Console.SolidBoxDrawer.ShowGradientBoxOnce(Position, Position + Size, new Color(56, 56, 56, 150), new Color(16, 16, 16, 127));

            if (ScaleNob.IsMouseOver)
            {
                ScaleNob.DrawBorderLines(Color.Gray);
            }

            labeler.ShowLabel("__performanceGraph", Position + new Vector2(0, -12), "Performance Graph");

            FrameCounter++;
            if (FrameCounter > SkipFrames)
            {
                FrameCounter = 0;

                //If the frame buffer has capacity will just create a new one; otherwise we'll pop the oldest off and use that.
                Frame frame;
                if (_frames.Count == MaxFrames)
                {
                    frame = _frames.Dequeue();
                    frame.TimingInfos.Clear();
                }
                else
                {
                    frame = new Frame();
                }

                _frames.Enqueue(frame);

                //Populate the frame metrics
                for (var barId = 0; barId < frameLog.Levels.Length; barId++)
                {
                    var bar = frameLog.Levels[barId];
                    for (var j = 0; j < bar.MarkCount; ++j)
                    {
                        frame.TimingInfos.Add(new TimingInfo(
                                                  barId,
                                                  bar.Markers[j].BeginTime,
                                                  bar.Markers[j].EndTime,
                                                  bar.Markers[j].Color));
                    }
                }
            }

            const float frameSpan = 1.0f / 60.0f * 1000f;

            var msToPs = Height / frameSpan;

            //Only render the actual number of frames we are capturing - we may have space for e.g. 120 (2 seconds) but the user is only viewing 60 (1 second)
            var barWidth   = Width / DisplayedFrameCount;
            var graphFloor = Position.Y + Size.Y;
            var position   = new Vector2(Position.X, graphFloor);

            var s = new Vector2(barWidth, msToPs);

            //Set a pointer to the first frame to renders
            var frameId = MaxFrames - DisplayedFrameCount;

            foreach (var frame in _frames)
            {
                //Bail when we have drawn enough
                if (frameId >= MaxFrames)
                {
                    break;
                }

                frameId++;

                foreach (var timeInfo in frame.TimingInfos)
                {
                    if (IsVisibleLevelsFlagSet(timeInfo.Level) == false)
                    {
                        continue;
                    }

                    var durationMilliseconds = timeInfo.EndMilliseconds - timeInfo.StartMilliseconds;
                    if (durationMilliseconds <= 0)
                    {
                        continue;
                    }

                    s.Y        = -durationMilliseconds * msToPs;
                    position.Y = graphFloor - (timeInfo.StartMilliseconds * msToPs);

                    Profiler.TempBoxDrawer.ShowGradientBoxOnce(position, position + s, timeInfo.Color, timeInfo.Color);
                }

                position.X += barWidth;
            }
        }
Exemplo n.º 3
0
        internal void Draw(ProfilerManager.FrameLog frameLog)
        {
            if (GearsetResources.CurrentRenderPass != RenderPass.BasicEffectPass)
            {
                return;
            }

            if (frameLog == null || Visible == false || Config.TimeRulerConfig.VisibleLevelsFlags == 0)
            {
                return;
            }

            var width = Width;

            // Adjust size and position based of number of levels we should draw.
            var   height  = BarPadding;
            float maxTime = 0;

            for (var levelId = 0; levelId < frameLog.Levels.Length; levelId++)
            {
                var level = frameLog.Levels[levelId];

                if (level.MarkCount <= 0 || IsVisibleLevelsFlagSet(levelId) == false)
                {
                    continue;
                }

                height += BarHeight + BarPadding;
                maxTime = Math.Max(maxTime, level.Markers[level.MarkCount - 1].EndTime);
            }

            height += BarPadding;

            Size = new Vector2(width, height);

            DrawBorderLines(Color.Gray, Profiler.LineDrawer);

            if (ScaleNob.IsMouseOver)
            {
                ScaleNob.DrawBorderLines(Color.Gray);
            }

            // Auto display frame adjustment. If the entire process of frame doesn't finish in less than 16.6ms
            // then it will adjust display frame duration as 33.3ms.
            const float frameSpan  = 1.0f / 60.0f * 1000f;
            var         sampleSpan = _sampleFrames * frameSpan;

            if (maxTime > sampleSpan)
            {
                _frameAdjust = Math.Max(0, _frameAdjust) + 1;
            }
            else
            {
                _frameAdjust = Math.Min(0, _frameAdjust) - 1;
            }

            if (Math.Abs(_frameAdjust) > AutoAdjustDelay)
            {
                _sampleFrames = Math.Min(MaxSampleFrames, _sampleFrames);
                _sampleFrames = Math.Max(TargetSampleFrames, (int)(maxTime / frameSpan) + 1);

                _frameAdjust = 0;
            }

            // Compute factor that converts from ms to pixel.
            var msToPs = (width - BarPadding * 2) / sampleSpan;

            var position = Position;

            GearsetResources.Console.SolidBoxDrawer.ShowGradientBoxOnce(position, position + Size, new Color(56, 56, 56, 150), new Color(16, 16, 16, 127));

            // Draw markers for each level.
            var size = new Vector2(0, BarHeight);
            var y    = position.Y;

            for (var levelId = 0; levelId < frameLog.Levels.Length; levelId++)
            {
                if (IsVisibleLevelsFlagSet(levelId) == false)
                {
                    continue;
                }

                var level = frameLog.Levels[levelId];

                position.Y = y + BarPadding;
                if (level.MarkCount > 0)
                {
                    for (var j = 0; j < level.MarkCount; ++j)
                    {
                        var bt = level.Markers[j].BeginTime;
                        var et = level.Markers[j].EndTime;
                        var sx = (int)(BarPadding + Position.X + bt * msToPs);
                        var ex = (int)(BarPadding + Position.X + et * msToPs);
                        position.X = sx;
                        size.X     = Math.Max(ex - sx, 1);
                        Profiler.TempBoxDrawer.ShowGradientBoxOnce(position, position + size, level.Markers[j].Color, level.Markers[j].Color);
                    }
                }

                y += BarHeight + BarPadding;
            }

            // Draw grid lines (each one represents 1 ms of time)
            position = Position;
            size     = new Vector2(1, height);
            for (var t = 1.0f; t < sampleSpan; t += 1.0f)
            {
                position.X = (int)(Position.X + t * msToPs);
                GearsetResources.Console.SolidBoxDrawer.ShowGradientBoxOnce(position, position + size, Color.Gray, Color.Gray);
            }

            // Draw frame extents (start and end of a single frame).
            //for (var i = 0; i <= _sampleFrames; ++i)
            //{
            //    position.X = (int)(Position.X + frameSpan * i * msToPs);
            //    GearsetResources.Console.SolidBoxDrawer.ShowGradientBoxOnce(position, position + s, Color.Green, Color.Green);
            //}
        }