Example #1
0
        internal void Draw(InternalLabeler labeler, Profiler.FrameLog frameLog)
        {
            if (Visible == false || Config.ProfilerSummaryConfig.VisibleLevelsFlags == 0)
            {
                labeler.HideLabel("__profilerSummary");
                return;
            }

            var font = GearsetResources.Font;

            // Generate log string.
            _logString.Length        = 0;
            _logStringTimings.Length = 0;
            foreach (var markerInfo in Profiler.Markers)
            {
                for (var i = 0; i < Profiler.MaxLevels; ++i)
                {
                    if (!markerInfo.Logs[i].Initialized)
                    {
                        continue;
                    }

                    if (Levels[i].Enabled == false)
                    {
                        continue;
                    }

                    if (_logString.Length > 0)
                    {
                        _logString.Append("\n");
                        _logStringTimings.Append("\n");
                    }

                    _logString.Append(" Level ");
                    _logString.AppendNumber(i);

                    _logString.Append(" ");

                    //Indent!
                    for (var x = 0; x < i; x++)
                    {
                        _logString.Append("--");
                    }

                    _logString.Append(markerInfo.Name);

                    //_logStringTimings.Append(" Avg.:");
                    _logStringTimings.AppendNumber(markerInfo.Logs[i].SnapAvg);
                    _logStringTimings.Append(" ms ");
                }
            }

            var namesSize   = font.MeasureString(_logString);
            var timingsSize = font.MeasureString(_logStringTimings);

            Size = namesSize + new Vector2(timingsSize.X, 0) + new Vector2(Padding * 5, Padding * 2);

            if (GearsetResources.CurrentRenderPass == RenderPass.BasicEffectPass)
            {
                DrawBorderLines(Color.Gray);
                GearsetResources.Console.SolidBoxDrawer.ShowGradientBoxOnce(Position, Position + Size, new Color(56, 56, 56, 150), new Color(16, 16, 16, 127));

                //Fixed size based on summary contrents
                //if (ScaleNob.IsMouseOver)
                //    ScaleNob.DrawBorderLines(Color.Gray);

                labeler.ShowLabel("__profilerSummary", Position + new Vector2(0, -12), "Profiler Summary");

                // Draw log color boxes.
                var position = Position;
                position += new Vector2(Padding);

                foreach (var markerInfo in Profiler.Markers)
                {
                    for (var i = 0; i < Profiler.MaxLevels; ++i)
                    {
                        if (Levels[i].Enabled == false)
                        {
                            continue;
                        }

                        if (markerInfo.Logs[i].Initialized == false)
                        {
                            continue;
                        }

                        Profiler.TempBoxDrawer.ShowGradientBoxOnce(position, position + new Vector2(10), markerInfo.Logs[i].Color, markerInfo.Logs[i].Color);

                        position.Y += font.LineSpacing;
                    }
                }
            }

            if (GearsetResources.CurrentRenderPass == RenderPass.SpriteBatchPass)
            {
                // Draw log string.
                var position = Position;
                position += new Vector2(Padding * 3, Padding);
                GearsetResources.SpriteBatch.DrawString(font, _logString, position, new Color(180, 180, 180));

                position  = Position;
                position += new Vector2(namesSize.X + (Padding * 5), Padding);
                GearsetResources.SpriteBatch.DrawString(font, _logStringTimings, position, new Color(220, 220, 220));
            }
        }
Example #2
0
        internal void Draw(InternalLabeler labeler, Profiler.FrameLog frameLog)
        {
            if (GearsetResources.CurrentRenderPass != RenderPass.BasicEffectPass)
            {
                return;
            }

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

            DrawBorderLines(Color.Gray);
            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 (Levels[timeInfo.Level].Enabled == 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;
            }
        }
Example #3
0
        internal void Draw(Profiler.FrameLog frameLog)
        {
            if (GearsetResources.CurrentRenderPass != RenderPass.BasicEffectPass)
            {
                return;
            }

            if (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 || Levels[levelId].Enabled == 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);

            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 (Levels[levelId].Enabled == 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);
            //}
        }