Variable name cleanup

This commit is contained in:
Andy Adshead 2019-01-26 20:54:35 +00:00
parent 3126ed303e
commit 8d3b23c3eb
6 changed files with 130 additions and 116 deletions

View file

@ -11,8 +11,8 @@ namespace Ryujinx.Profiler
private Stopwatch SW;
internal ConcurrentDictionary<ProfileConfig, TimingInfo> Timers;
private readonly object sessionLock = new object();
private int sessionCounter = 0;
private readonly object SessionLock = new object();
private int SessionCounter = 0;
public InternalProfile()
{
@ -69,9 +69,9 @@ namespace Ryujinx.Profiler
public string GetSession()
{
// Can be called from multiple threads so locked to ensure no duplicate sessions are generated
lock (sessionLock)
lock (SessionLock)
{
return (sessionCounter++).ToString();
return (SessionCounter++).ToString();
}
}

View file

@ -9,7 +9,7 @@ namespace Ryujinx.Profiler
public string Category;
public string SessionGroup, SessionItem;
private string cachedTag, cachedSession;
private string CachedTag, CachedSession;
public string Search => $"{Category}.{SessionGroup}.{SessionItem}";
@ -17,9 +17,9 @@ namespace Ryujinx.Profiler
{
get
{
if (cachedTag == null)
cachedTag = $"{Category}{(Session == "" ? "" : $" ({Session})")}";
return cachedTag;
if (CachedTag == null)
CachedTag = $"{Category}{(Session == "" ? "" : $" ({Session})")}";
return CachedTag;
}
}
@ -27,27 +27,27 @@ namespace Ryujinx.Profiler
{
get
{
if (cachedSession == null)
if (CachedSession == null)
{
if (SessionGroup != null && SessionItem != null)
{
cachedSession = $"{SessionGroup}: {SessionItem}";
CachedSession = $"{SessionGroup}: {SessionItem}";
}
else if (SessionGroup != null)
{
cachedSession = $"{SessionGroup}";
CachedSession = $"{SessionGroup}";
}
else if (SessionItem != null)
{
cachedSession = $"---: {SessionItem}";
CachedSession = $"---: {SessionItem}";
}
else
{
cachedSession = "";
CachedSession = "";
}
}
return cachedSession;
return CachedSession;
}
}
}

View file

@ -10,10 +10,10 @@ namespace Ryujinx.Profiler.UI
{
public class ProfileButton
{
private int padding;
private int Padding;
private FontService FontService;
private int X, Y, Right, Top, Height;
private int textX, textY;
private int TextX, TextY;
private string Label;
private Action Clicked;
private bool Visible;
@ -55,8 +55,8 @@ namespace Ryujinx.Profiler.UI
Height = height;
X = x;
Y = y;
textX = x + padding / 2;
textY = y + padding / 2;
TextX = x + padding / 2;
TextY = y + padding / 2;
Top = y + height + padding;
Right = x + width + padding;
}
@ -79,7 +79,7 @@ namespace Ryujinx.Profiler.UI
GL.Vertex2(X, Y);
GL.End();
FontService.DrawText(Label, textX, textY, Height);
FontService.DrawText(Label, TextX, TextY, Height);
}
public bool ProcessClick(int x, int y)

View file

@ -26,28 +26,28 @@ namespace Ryujinx
Pause = 6,
}
private bool visible = true, initComplete = false, viewportUpdated = true;
public bool visibleChanged;
private FontService fontService;
private List<KeyValuePair<ProfileConfig, TimingInfo>> rawPofileData, profileData;
private bool VisibleLocal = true, InitComplete = false, ViewportUpdated = true;
public bool VisibleChangedLocal;
private FontService FontServ;
private List<KeyValuePair<ProfileConfig, TimingInfo>> RawPofileData, ProfileData;
private float scrollPos = 0;
private float minScroll = 0, maxScroll = 0;
private float ScrollPos = 0;
private float MinScroll = 0, MaxScroll = 0;
private ProfileButton[] buttons;
private IComparer<KeyValuePair<ProfileConfig, TimingInfo>> sortAction;
private ProfileButton[] Buttons;
private IComparer<KeyValuePair<ProfileConfig, TimingInfo>> SortAction;
private string FilterText = "";
private double BackspaceDownTime, UpdateTimer;
private bool BackspaceDown = false, prevBackspaceDown = false, regexEnabled = false, ProfileUpdated = false;
private bool showInactive = true, Paused = false;
private bool BackspaceDown = false, PrevBackspaceDown = false, RegexEnabled = false, ProfileUpdated = false;
private bool ShowInactive = true, Paused = false;
public ProfileWindow()
: base(1280, 720)
{
Location = new Point(DisplayDevice.Default.Width - 1280, (DisplayDevice.Default.Height - 720) - 50);
Title = "Profiler";
sortAction = null;
SortAction = null;
BackspaceDownTime = 0;
// Large number to force an update on first update
@ -57,8 +57,8 @@ namespace Ryujinx
#region Public Methods
public void ToggleVisible()
{
visible = !visible;
visibleChanged = true;
VisibleLocal = !VisibleLocal;
VisibleChangedLocal = true;
}
#endregion
@ -70,26 +70,26 @@ namespace Ryujinx
protected override void OnLoad(EventArgs e)
{
GL.ClearColor(Color.MidnightBlue);
fontService = new FontService();
fontService.InitalizeTextures();
fontService.UpdateScreenHeight(Height);
FontServ = new FontService();
FontServ.InitalizeTextures();
FontServ.UpdateScreenHeight(Height);
buttons = new ProfileButton[7];
buttons[(int)ButtonIndex.TagTitle] = new ProfileButton(fontService, () => sortAction = new ProfileSorters.TagAscending());
buttons[(int)ButtonIndex.InstantTitle] = new ProfileButton(fontService, () => sortAction = new ProfileSorters.InstantAscending());
buttons[(int)ButtonIndex.AverageTitle] = new ProfileButton(fontService, () => sortAction = new ProfileSorters.AverageAscending());
buttons[(int)ButtonIndex.TotalTitle] = new ProfileButton(fontService, () => sortAction = new ProfileSorters.TotalAscending());
buttons[(int)ButtonIndex.FilterBar] = new ProfileButton(fontService, () =>
Buttons = new ProfileButton[7];
Buttons[(int)ButtonIndex.TagTitle] = new ProfileButton(FontServ, () => SortAction = new ProfileSorters.TagAscending());
Buttons[(int)ButtonIndex.InstantTitle] = new ProfileButton(FontServ, () => SortAction = new ProfileSorters.InstantAscending());
Buttons[(int)ButtonIndex.AverageTitle] = new ProfileButton(FontServ, () => SortAction = new ProfileSorters.AverageAscending());
Buttons[(int)ButtonIndex.TotalTitle] = new ProfileButton(FontServ, () => SortAction = new ProfileSorters.TotalAscending());
Buttons[(int)ButtonIndex.FilterBar] = new ProfileButton(FontServ, () =>
{
ProfileUpdated = true;
regexEnabled = !regexEnabled;
RegexEnabled = !RegexEnabled;
});
buttons[(int)ButtonIndex.ShowHideInactive] = new ProfileButton(fontService, () =>
Buttons[(int)ButtonIndex.ShowHideInactive] = new ProfileButton(FontServ, () =>
{
ProfileUpdated = true;
showInactive = !showInactive;
ShowInactive = !ShowInactive;
});
buttons[(int)ButtonIndex.Pause] = new ProfileButton(fontService, () =>
Buttons[(int)ButtonIndex.Pause] = new ProfileButton(FontServ, () =>
{
ProfileUpdated = true;
Paused = !Paused;
@ -105,7 +105,7 @@ namespace Ryujinx
/// <remarks>There is no need to call the base implementation.</remarks>
protected override void OnResize(EventArgs e)
{
viewportUpdated = true;
ViewportUpdated = true;
}
#endregion
@ -115,8 +115,8 @@ namespace Ryujinx
/// </summary>
protected override void OnClosing(CancelEventArgs e)
{
visible = false;
visibleChanged = true;
VisibleLocal = false;
VisibleChangedLocal = true;
e.Cancel = true;
base.OnClosing(e);
}
@ -130,12 +130,12 @@ namespace Ryujinx
/// <remarks>There is no need to call the base implementation.</remarks>
protected override void OnUpdateFrame(FrameEventArgs e)
{
initComplete = true;
InitComplete = true;
// Backspace handling
if (BackspaceDown)
{
if (!prevBackspaceDown)
if (!PrevBackspaceDown)
{
BackspaceDownTime = 0;
FilterBackspace();
@ -150,42 +150,42 @@ namespace Ryujinx
}
}
}
prevBackspaceDown = BackspaceDown;
PrevBackspaceDown = BackspaceDown;
// Get timing data if enough time has passed
UpdateTimer += e.Time;
if (!Paused && (UpdateTimer > Profile.GetUpdateRate()))
{
UpdateTimer %= Profile.GetUpdateRate();
rawPofileData = Profile.GetProfilingData().ToList();
RawPofileData = Profile.GetProfilingData().ToList();
ProfileUpdated = true;
}
// Filtering
if (ProfileUpdated)
{
if (showInactive)
if (ShowInactive)
{
profileData = rawPofileData;
ProfileData = RawPofileData;
}
else
{
profileData = rawPofileData.FindAll(kvp => kvp.Value.Instant > 0.001f);
ProfileData = RawPofileData.FindAll(kvp => kvp.Value.Instant > 0.001f);
}
if (sortAction != null)
if (SortAction != null)
{
profileData.Sort(sortAction);
ProfileData.Sort(SortAction);
}
if (regexEnabled)
if (RegexEnabled)
{
try
{
Regex filterRegex = new Regex(FilterText, RegexOptions.IgnoreCase);
if (FilterText != "")
{
profileData = profileData.Where((pair => filterRegex.IsMatch(pair.Key.Search))).ToList();
ProfileData = ProfileData.Where((pair => filterRegex.IsMatch(pair.Key.Search))).ToList();
}
}
catch (ArgumentException argException)
@ -196,7 +196,7 @@ namespace Ryujinx
else
{
// Regular filtering
profileData = profileData.Where((pair => pair.Key.Search.ToLower().Contains(FilterText.ToLower()))).ToList();
ProfileData = ProfileData.Where((pair => pair.Key.Search.ToLower().Contains(FilterText.ToLower()))).ToList();
}
ProfileUpdated = false;
@ -212,19 +212,19 @@ namespace Ryujinx
/// <remarks>There is no need to call the base implementation.</remarks>
protected override void OnRenderFrame(FrameEventArgs e)
{
if (visibleChanged)
if (VisibleChangedLocal)
{
Visible = visible;
visibleChanged = false;
Visible = VisibleLocal;
VisibleChangedLocal = false;
}
if (!visible || !initComplete)
if (!VisibleLocal || !InitComplete)
{
return;
}
// Update viewport
if (viewportUpdated)
if (ViewportUpdated)
{
GL.Viewport(0, 0, Width, Height);
@ -232,16 +232,16 @@ namespace Ryujinx
GL.LoadIdentity();
GL.Ortho(0, Width, 0, Height, 0.0, 4.0);
fontService.UpdateScreenHeight(Height);
FontServ.UpdateScreenHeight(Height);
viewportUpdated = false;
ViewportUpdated = false;
}
// Frame setup
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
GL.ClearColor(Color.Black);
fontService.fontColor = Color.White;
FontServ.fontColor = Color.White;
int verticalIndex = 0;
int lineHeight = 16;
int titleHeight = 24;
@ -252,7 +252,7 @@ namespace Ryujinx
float width;
float maxWidth = 0;
float yOffset = scrollPos - titleHeight;
float yOffset = ScrollPos - titleHeight;
float xOffset = 10;
// Background lines to make reading easier
@ -260,7 +260,7 @@ namespace Ryujinx
GL.Scissor(0, filterHeight, Width, Height - titleHeight - filterHeight);
GL.Begin(PrimitiveType.Triangles);
GL.Color3(0.2f, 0.2f, 0.2f);
for (int i = 0; i < profileData.Count; i += 2)
for (int i = 0; i < ProfileData.Count; i += 2)
{
float top = GetLineY(yOffset, lineHeight, linePadding, false, i - 1);
float bottom = GetLineY(yOffset, lineHeight, linePadding, false, i);
@ -278,14 +278,14 @@ namespace Ryujinx
GL.Vertex2(0, bottom);
}
GL.End();
maxScroll = (lineHeight + linePadding) * (profileData.Count - 1);
MaxScroll = (lineHeight + linePadding) * (ProfileData.Count - 1);
// Display category
verticalIndex = 0;
foreach (var entry in profileData)
foreach (var entry in ProfileData)
{
float y = GetLineY(yOffset, lineHeight, linePadding, true, verticalIndex++);
width = fontService.DrawText(entry.Key.Category, xOffset, y, lineHeight);
width = FontServ.DrawText(entry.Key.Category, xOffset, y, lineHeight);
if (width > maxWidth)
{
maxWidth = width;
@ -293,7 +293,7 @@ namespace Ryujinx
}
GL.Disable(EnableCap.ScissorTest);
width = fontService.DrawText("Category", xOffset, Height - titleFontHeight, titleFontHeight);
width = FontServ.DrawText("Category", xOffset, Height - titleFontHeight, titleFontHeight);
if (width > maxWidth)
maxWidth = width;
@ -304,10 +304,10 @@ namespace Ryujinx
maxWidth = 0;
verticalIndex = 0;
GL.Enable(EnableCap.ScissorTest);
foreach (var entry in profileData)
foreach (var entry in ProfileData)
{
float y = GetLineY(yOffset, lineHeight, linePadding, true, verticalIndex++);
width = fontService.DrawText(entry.Key.SessionGroup, xOffset, y, lineHeight);
width = FontServ.DrawText(entry.Key.SessionGroup, xOffset, y, lineHeight);
if (width > maxWidth)
{
maxWidth = width;
@ -315,7 +315,7 @@ namespace Ryujinx
}
GL.Disable(EnableCap.ScissorTest);
width = fontService.DrawText("Group", xOffset, Height - titleFontHeight, titleFontHeight);
width = FontServ.DrawText("Group", xOffset, Height - titleFontHeight, titleFontHeight);
if (width > maxWidth)
maxWidth = width;
@ -325,10 +325,10 @@ namespace Ryujinx
maxWidth = 0;
verticalIndex = 0;
GL.Enable(EnableCap.ScissorTest);
foreach (var entry in profileData)
foreach (var entry in ProfileData)
{
float y = GetLineY(yOffset, lineHeight, linePadding, true, verticalIndex++);
width = fontService.DrawText(entry.Key.SessionItem, xOffset, y, lineHeight);
width = FontServ.DrawText(entry.Key.SessionItem, xOffset, y, lineHeight);
if (width > maxWidth)
{
maxWidth = width;
@ -336,15 +336,15 @@ namespace Ryujinx
}
GL.Disable(EnableCap.ScissorTest);
width = fontService.DrawText("Item", xOffset, Height - titleFontHeight, titleFontHeight);
width = FontServ.DrawText("Item", xOffset, Height - titleFontHeight, titleFontHeight);
if (width > maxWidth)
maxWidth = width;
xOffset += maxWidth + columnSpacing;
buttons[(int)ButtonIndex.TagTitle].UpdateSize(0, Height - titleFontHeight, 0, (int)xOffset, titleFontHeight);
Buttons[(int)ButtonIndex.TagTitle].UpdateSize(0, Height - titleFontHeight, 0, (int)xOffset, titleFontHeight);
// Time bars
if (profileData.Count != 0)
if (ProfileData.Count != 0)
{
width = Width - xOffset - 370;
long maxAverage, maxTotal;
@ -353,7 +353,7 @@ namespace Ryujinx
// Get max values
var maxInstant = maxAverage = maxTotal = 0;
foreach (KeyValuePair<ProfileConfig, TimingInfo> kvp in profileData)
foreach (KeyValuePair<ProfileConfig, TimingInfo> kvp in ProfileData)
{
maxInstant = Math.Max(maxInstant, kvp.Value.Instant);
maxAverage = Math.Max(maxAverage, kvp.Value.AverageTime);
@ -362,7 +362,7 @@ namespace Ryujinx
GL.Enable(EnableCap.ScissorTest);
GL.Begin(PrimitiveType.Triangles);
foreach (var entry in profileData)
foreach (var entry in ProfileData)
{
// Instant
GL.Color3(Color.Blue);
@ -413,44 +413,44 @@ namespace Ryujinx
GL.Disable(EnableCap.ScissorTest);
}
fontService.DrawText("Blue: Instant, Green: Avg, Red: Total", xOffset, Height - titleFontHeight, titleFontHeight);
FontServ.DrawText("Blue: Instant, Green: Avg, Red: Total", xOffset, Height - titleFontHeight, titleFontHeight);
xOffset = Width - 360;
// Display timestamps
verticalIndex = 0;
GL.Enable(EnableCap.ScissorTest);
foreach (var entry in profileData)
foreach (var entry in ProfileData)
{
float y = GetLineY(yOffset, lineHeight, linePadding, true, verticalIndex++);
fontService.DrawText($"{Profile.ConvertTicksToMS(entry.Value.Instant):F3} ({entry.Value.InstantCount})", xOffset, y, lineHeight);
fontService.DrawText($"{Profile.ConvertTicksToMS(entry.Value.AverageTime):F3}", columnSpacing + 120 + xOffset, y, lineHeight);
fontService.DrawText($"{Profile.ConvertTicksToMS(entry.Value.TotalTime):F3}", columnSpacing + columnSpacing + 200 + xOffset, y, lineHeight);
FontServ.DrawText($"{Profile.ConvertTicksToMS(entry.Value.Instant):F3} ({entry.Value.InstantCount})", xOffset, y, lineHeight);
FontServ.DrawText($"{Profile.ConvertTicksToMS(entry.Value.AverageTime):F3}", columnSpacing + 120 + xOffset, y, lineHeight);
FontServ.DrawText($"{Profile.ConvertTicksToMS(entry.Value.TotalTime):F3}", columnSpacing + columnSpacing + 200 + xOffset, y, lineHeight);
}
GL.Disable(EnableCap.ScissorTest);
float yHeight = Height - titleFontHeight;
fontService.DrawText("Instant (ms, count)", xOffset, yHeight, titleFontHeight);
buttons[(int)ButtonIndex.InstantTitle].UpdateSize((int)xOffset, (int)yHeight, 0, (int)(columnSpacing + 100), titleFontHeight);
FontServ.DrawText("Instant (ms, count)", xOffset, yHeight, titleFontHeight);
Buttons[(int)ButtonIndex.InstantTitle].UpdateSize((int)xOffset, (int)yHeight, 0, (int)(columnSpacing + 100), titleFontHeight);
fontService.DrawText("Average (ms)", columnSpacing + 120 + xOffset, yHeight, titleFontHeight);
buttons[(int)ButtonIndex.AverageTitle].UpdateSize((int)(columnSpacing + 120 + xOffset), (int)yHeight, 0, (int)(columnSpacing + 100), titleFontHeight);
FontServ.DrawText("Average (ms)", columnSpacing + 120 + xOffset, yHeight, titleFontHeight);
Buttons[(int)ButtonIndex.AverageTitle].UpdateSize((int)(columnSpacing + 120 + xOffset), (int)yHeight, 0, (int)(columnSpacing + 100), titleFontHeight);
fontService.DrawText("Total (ms)", columnSpacing + columnSpacing + 200 + xOffset, yHeight, titleFontHeight);
buttons[(int)ButtonIndex.TotalTitle].UpdateSize((int)(columnSpacing + columnSpacing + 200 + xOffset), (int)yHeight, 0, Width, titleFontHeight);
FontServ.DrawText("Total (ms)", columnSpacing + columnSpacing + 200 + xOffset, yHeight, titleFontHeight);
Buttons[(int)ButtonIndex.TotalTitle].UpdateSize((int)(columnSpacing + columnSpacing + 200 + xOffset), (int)yHeight, 0, Width, titleFontHeight);
// Show/Hide Inactive
float widthShowHideButton = buttons[(int)ButtonIndex.ShowHideInactive].UpdateSize($"{(showInactive ? "Hide" : "Show")} Inactive", 5, 5, 4, 16);
float widthShowHideButton = Buttons[(int)ButtonIndex.ShowHideInactive].UpdateSize($"{(ShowInactive ? "Hide" : "Show")} Inactive", 5, 5, 4, 16);
// Play/Pause
width = buttons[(int)ButtonIndex.Pause].UpdateSize(Paused ? "Play" : "Pause", 15 + (int)widthShowHideButton, 5, 4, 16) + widthShowHideButton;
width = Buttons[(int)ButtonIndex.Pause].UpdateSize(Paused ? "Play" : "Pause", 15 + (int)widthShowHideButton, 5, 4, 16) + widthShowHideButton;
// Filter bar
fontService.DrawText($"{(regexEnabled ? "Regex " : "Filter")}: {FilterText}", 25 + width, 7, 16);
buttons[(int) ButtonIndex.FilterBar].UpdateSize((int)(25 + width), 0, 0, Width, filterHeight);
FontServ.DrawText($"{(RegexEnabled ? "Regex " : "Filter")}: {FilterText}", 25 + width, 7, 16);
Buttons[(int) ButtonIndex.FilterBar].UpdateSize((int)(25 + width), 0, 0, Width, filterHeight);
// Draw buttons
foreach (ProfileButton button in buttons)
foreach (ProfileButton button in Buttons)
{
button.Draw();
}
@ -522,7 +522,7 @@ namespace Ryujinx
protected override void OnMouseUp(MouseButtonEventArgs e)
{
foreach (ProfileButton button in buttons)
foreach (ProfileButton button in Buttons)
{
if (button.ProcessClick(e.X, Height - e.Y))
return;
@ -535,11 +535,11 @@ namespace Ryujinx
protected override void OnMouseWheel(MouseWheelEventArgs e)
{
scrollPos += e.Delta * -30;
if (scrollPos < minScroll)
scrollPos = minScroll;
if (scrollPos > maxScroll)
scrollPos = maxScroll;
ScrollPos += e.Delta * -30;
if (ScrollPos < MinScroll)
ScrollPos = MinScroll;
if (ScrollPos > MaxScroll)
ScrollPos = MaxScroll;
}
}
}

View file

@ -4,18 +4,19 @@ namespace Ryujinx.Profiler.UI
{
public class ProfileWindowManager
{
private ProfileWindow window;
private ProfileWindow Window;
private Thread ProfileThread;
public ProfileWindowManager()
{
if (Profile.ProfilingEnabled())
{
Thread profileThread = new Thread(() =>
ProfileThread = new Thread(() =>
{
window = new ProfileWindow();
window.Run(60, 60);
Window = new ProfileWindow();
Window.Run(60, 60);
});
profileThread.Start();
ProfileThread.Start();
}
}
@ -23,8 +24,21 @@ namespace Ryujinx.Profiler.UI
{
if (Profile.ProfilingEnabled())
{
window.ToggleVisible();
Window.ToggleVisible();
}
}
public void Close()
{
if (Window != null)
{
Window.Close();
Window.Dispose();
}
ProfileThread.Join();
Window = null;
}
}
}

View file

@ -19,7 +19,7 @@ namespace Ryujinx.Profiler.UI.SharpFontHelpers
private const int SheetWidth = 256;
private const int SheetHeight = 256;
private int ScreenWidth, ScreenHeight;
private int characterTextureSheet;
private int CharacterTextureSheet;
private CharacterInfo[] characters;
public Color fontColor = Color.Black;
@ -62,8 +62,8 @@ namespace Ryujinx.Profiler.UI.SharpFontHelpers
}
// Convert raw data into texture
characterTextureSheet = GL.GenTexture();
GL.BindTexture(TextureTarget.Texture2D, characterTextureSheet);
CharacterTextureSheet = GL.GenTexture();
GL.BindTexture(TextureTarget.Texture2D, CharacterTextureSheet);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
@ -93,7 +93,7 @@ namespace Ryujinx.Profiler.UI.SharpFontHelpers
if (draw)
{
// Use font map texture
GL.BindTexture(TextureTarget.Texture2D, characterTextureSheet);
GL.BindTexture(TextureTarget.Texture2D, CharacterTextureSheet);
// Enable blending and textures
GL.Enable(EnableCap.Texture2D);