diff --git a/Ryujinx.Profiler/InternalProfile.cs b/Ryujinx.Profiler/InternalProfile.cs index ead9ddcc27..e693ead21b 100644 --- a/Ryujinx.Profiler/InternalProfile.cs +++ b/Ryujinx.Profiler/InternalProfile.cs @@ -1,6 +1,8 @@ using System; using System.Collections.Concurrent; +using System.Collections.Generic; using System.Diagnostics; +using System.Linq; namespace Ryujinx.Profiler { @@ -73,5 +75,20 @@ namespace Ryujinx.Profiler return (sessionCounter++).ToString(); } } + + public Dictionary GetProfilingData() + { + // Forcibly get copy so user doesn't block profiling + ProfileConfig[] configs = Timers.Keys.ToArray(); + TimingInfo[] times = Timers.Values.ToArray(); + Dictionary outDict = new Dictionary(); + + for (int i = 0; i < configs.Length; i++) + { + outDict.Add(configs[i], times[i]); + } + + return outDict; + } } } diff --git a/Ryujinx.Profiler/Profile.cs b/Ryujinx.Profiler/Profile.cs index 25b10c498d..2db22f9dca 100644 --- a/Ryujinx.Profiler/Profile.cs +++ b/Ryujinx.Profiler/Profile.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; namespace Ryujinx.Profiler { @@ -63,5 +64,12 @@ namespace Ryujinx.Profiler return null; return ProfileInstance.GetSession(); } + + public static Dictionary GetProfilingData() + { + if (!ProfilingEnabled()) + return new Dictionary(); + return ProfileInstance.GetProfilingData(); + } } } diff --git a/Ryujinx.Profiler/UI/ProfileWindow.cs b/Ryujinx.Profiler/UI/ProfileWindow.cs index e680eaa9e1..f376bae4d7 100644 --- a/Ryujinx.Profiler/UI/ProfileWindow.cs +++ b/Ryujinx.Profiler/UI/ProfileWindow.cs @@ -1,16 +1,19 @@ using OpenTK; using OpenTK.Graphics.OpenGL; using System; +using System.Collections.Generic; using System.ComponentModel; +using Ryujinx.Profiler; using Ryujinx.Profiler.UI.SharpFontHelpers; namespace Ryujinx { public class ProfileWindow : GameWindow { - private bool visible = true; + private bool visible = true, initComplete = false; public bool visibleChanged; private FontService fontService; + private Dictionary profileData; public ProfileWindow() : base(400, 720) @@ -78,7 +81,8 @@ namespace Ryujinx /// There is no need to call the base implementation. protected override void OnUpdateFrame(FrameEventArgs e) { - // Nothing to do! + initComplete = true; + profileData = Profile.GetProfilingData(); } #endregion @@ -96,18 +100,40 @@ namespace Ryujinx visibleChanged = false; } - if (!visible) + if (!visible || !initComplete) { return; } GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); - GL.ClearColor(Color.White); - fontService.fontColor = Color.Black; - fontService.DrawText("This is a test", 50, 50, 32); + GL.ClearColor(Color.Black); + fontService.fontColor = Color.White; + int verticalIndex = 0; + int lineHeight = 12; - this.SwapBuffers(); + float maxWidth = 0; + + foreach (var entry in profileData) + { + float y = Height - (lineHeight + 2) * (verticalIndex++ + 1); + float width = fontService.DrawText(entry.Key.Tag, 50, y, lineHeight); + if (width > maxWidth) + { + maxWidth = width; + } + } + + verticalIndex = 0; + + foreach (var entry in profileData) + { + float y = Height - (lineHeight + 2) * (verticalIndex++ + 1); + fontService.DrawText($"{entry.Value.AverageTime:F3}", 75 + maxWidth, y, lineHeight); + fontService.DrawText($"{entry.Value.LastTime:F3}", 175 + maxWidth, y, lineHeight); + } + + SwapBuffers(); } #endregion } diff --git a/Ryujinx.Profiler/UI/SharpFontHelpers/FontService.cs b/Ryujinx.Profiler/UI/SharpFontHelpers/FontService.cs index 6f1bc1f4c8..b4ccdad42f 100644 --- a/Ryujinx.Profiler/UI/SharpFontHelpers/FontService.cs +++ b/Ryujinx.Profiler/UI/SharpFontHelpers/FontService.cs @@ -68,8 +68,10 @@ namespace Ryujinx.Profiler.UI.SharpFontHelpers GL.BindTexture(TextureTarget.Texture2D, 0); } - public void DrawText(string text, float x, float y, float height) + public float DrawText(string text, float x, float y, float height) { + float originalX = x; + // Use font map texture GL.BindTexture(TextureTarget.Texture2D, characterTextureSheet); @@ -102,6 +104,9 @@ namespace Ryujinx.Profiler.UI.SharpFontHelpers GL.BindTexture(TextureTarget.Texture2D, 0); GL.Disable(EnableCap.Texture2D); GL.Disable(EnableCap.Blend); + + // Return width of rendered text + return x - originalX; } private void DrawChar(CharacterInfo charInfo, float left, float right, float top, float bottom)