Display some actual timing data

This commit is contained in:
Andy Adshead 2019-01-26 02:24:39 +00:00
commit f20a449c78
4 changed files with 64 additions and 8 deletions

View file

@ -1,6 +1,8 @@
using System; using System;
using System.Collections.Concurrent; using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Linq;
namespace Ryujinx.Profiler namespace Ryujinx.Profiler
{ {
@ -73,5 +75,20 @@ namespace Ryujinx.Profiler
return (sessionCounter++).ToString(); return (sessionCounter++).ToString();
} }
} }
public Dictionary<ProfileConfig, TimingInfo> GetProfilingData()
{
// Forcibly get copy so user doesn't block profiling
ProfileConfig[] configs = Timers.Keys.ToArray();
TimingInfo[] times = Timers.Values.ToArray();
Dictionary<ProfileConfig, TimingInfo> outDict = new Dictionary<ProfileConfig, TimingInfo>();
for (int i = 0; i < configs.Length; i++)
{
outDict.Add(configs[i], times[i]);
}
return outDict;
}
} }
} }

View file

@ -1,4 +1,5 @@
using System; using System;
using System.Collections.Generic;
namespace Ryujinx.Profiler namespace Ryujinx.Profiler
{ {
@ -63,5 +64,12 @@ namespace Ryujinx.Profiler
return null; return null;
return ProfileInstance.GetSession(); return ProfileInstance.GetSession();
} }
public static Dictionary<ProfileConfig, TimingInfo> GetProfilingData()
{
if (!ProfilingEnabled())
return new Dictionary<ProfileConfig, TimingInfo>();
return ProfileInstance.GetProfilingData();
}
} }
} }

View file

@ -1,16 +1,19 @@
using OpenTK; using OpenTK;
using OpenTK.Graphics.OpenGL; using OpenTK.Graphics.OpenGL;
using System; using System;
using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using Ryujinx.Profiler;
using Ryujinx.Profiler.UI.SharpFontHelpers; using Ryujinx.Profiler.UI.SharpFontHelpers;
namespace Ryujinx namespace Ryujinx
{ {
public class ProfileWindow : GameWindow public class ProfileWindow : GameWindow
{ {
private bool visible = true; private bool visible = true, initComplete = false;
public bool visibleChanged; public bool visibleChanged;
private FontService fontService; private FontService fontService;
private Dictionary<ProfileConfig, TimingInfo> profileData;
public ProfileWindow() public ProfileWindow()
: base(400, 720) : base(400, 720)
@ -78,7 +81,8 @@ namespace Ryujinx
/// <remarks>There is no need to call the base implementation.</remarks> /// <remarks>There is no need to call the base implementation.</remarks>
protected override void OnUpdateFrame(FrameEventArgs e) protected override void OnUpdateFrame(FrameEventArgs e)
{ {
// Nothing to do! initComplete = true;
profileData = Profile.GetProfilingData();
} }
#endregion #endregion
@ -96,18 +100,40 @@ namespace Ryujinx
visibleChanged = false; visibleChanged = false;
} }
if (!visible) if (!visible || !initComplete)
{ {
return; return;
} }
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
GL.ClearColor(Color.White); GL.ClearColor(Color.Black);
fontService.fontColor = Color.Black; fontService.fontColor = Color.White;
fontService.DrawText("This is a test", 50, 50, 32); 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 #endregion
} }

View file

@ -68,8 +68,10 @@ namespace Ryujinx.Profiler.UI.SharpFontHelpers
GL.BindTexture(TextureTarget.Texture2D, 0); 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 // Use font map texture
GL.BindTexture(TextureTarget.Texture2D, characterTextureSheet); GL.BindTexture(TextureTarget.Texture2D, characterTextureSheet);
@ -102,6 +104,9 @@ namespace Ryujinx.Profiler.UI.SharpFontHelpers
GL.BindTexture(TextureTarget.Texture2D, 0); GL.BindTexture(TextureTarget.Texture2D, 0);
GL.Disable(EnableCap.Texture2D); GL.Disable(EnableCap.Texture2D);
GL.Disable(EnableCap.Blend); 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) private void DrawChar(CharacterInfo charInfo, float left, float right, float top, float bottom)