Merge branch 'profiling' into actually_profiling

This commit is contained in:
Andy Adshead 2019-02-02 03:31:44 +00:00
commit 22fd2efa14
8 changed files with 49 additions and 40 deletions

View file

@ -150,10 +150,11 @@ namespace Ryujinx.Profiler
{ {
_preserve = PerformanceCounter.ElapsedTicks; _preserve = PerformanceCounter.ElapsedTicks;
// Make sure to clear queue // Skip clearing queue if already clearing
lock (_timerQueueClearLock) if (Monitor.TryEnter(_timerQueueClearLock))
{ {
ClearTimerQueue(); ClearTimerQueue();
Monitor.Exit(_timerQueueClearLock);
} }
return Timers; return Timers;

View file

@ -66,6 +66,8 @@ namespace Ryujinx.Profiler
{ {
if (!ProfilingEnabled()) if (!ProfilingEnabled())
return; return;
if (config.Level > _settings.MaxLevel)
return;
_profileInstance.BeginProfile(config); _profileInstance.BeginProfile(config);
} }
@ -74,6 +76,8 @@ namespace Ryujinx.Profiler
{ {
if (!ProfilingEnabled()) if (!ProfilingEnabled())
return; return;
if (config.Level > _settings.MaxLevel)
return;
_profileInstance.EndProfile(config); _profileInstance.EndProfile(config);
} }

View file

@ -10,6 +10,8 @@ namespace Ryujinx.Profiler
public string SessionGroup; public string SessionGroup;
public string SessionItem; public string SessionItem;
public int Level;
// Private cached variables // Private cached variables
private string _cachedTag; private string _cachedTag;
private string _cachedSession; private string _cachedSession;

View file

@ -11,6 +11,7 @@ namespace Ryujinx.Profiler
public bool FileDumpEnabled { get; set; } = false; public bool FileDumpEnabled { get; set; } = false;
public string DumpLocation { get; set; } = ""; public string DumpLocation { get; set; } = "";
public float UpdateRate { get; set; } = 0.1f; public float UpdateRate { get; set; } = 0.1f;
public int MaxLevel { get; set; } = 0;
// 19531225 = 5 seconds in ticks // 19531225 = 5 seconds in ticks
public long History { get; set; } = 19531225; public long History { get; set; } = 19531225;

View file

@ -157,7 +157,7 @@ namespace Ryujinx.Profiler
if (toRemove > 0) if (toRemove > 0)
{ {
_timestamps.RemoveRange(toPreserveStart + toPreserveLen, toRemove); _timestamps.RemoveRange(toPreserveLen, toRemove);
} }
} }
} }

View file

@ -22,26 +22,30 @@ namespace Ryujinx.Profiler.UI
int left, right; int left, right;
float top, bottom; float top, bottom;
int verticalIndex = 0; int verticalIndex = 0;
float barHeight = (LineHeight - LinePadding); float graphRight = xOffset + width;
long history = Profile.HistoryLength; float barHeight = (LineHeight - LinePadding);
long timeWidthTicks = (long)(history / (double)_graphZoom); long history = Profile.HistoryLength;
long graphPositionTicks = (long)(_graphPosition * PerformanceCounter.TicksPerMillisecond); double timeWidthTicks = history / (double)_graphZoom;
long graphPositionTicks = (long)(_graphPosition * PerformanceCounter.TicksPerMillisecond);
long ticksPerPixel = (long)(timeWidthTicks / width);
// Reset start point if out of bounds // Reset start point if out of bounds
if (timeWidthTicks + graphPositionTicks > history) if (timeWidthTicks + graphPositionTicks > history)
{ {
graphPositionTicks = history - timeWidthTicks; graphPositionTicks = history - (long)timeWidthTicks;
_graphPosition = (float)graphPositionTicks / PerformanceCounter.TicksPerMillisecond; _graphPosition = (float)graphPositionTicks / PerformanceCounter.TicksPerMillisecond;
} }
graphPositionTicks = _captureTime - graphPositionTicks;
// Draw timing flags // Draw timing flags
GL.Enable(EnableCap.ScissorTest); GL.Enable(EnableCap.ScissorTest);
GL.Color3(0.25f, 0.25f, 0.25f); GL.Color3(0.25f, 0.25f, 0.25f);
GL.Begin(PrimitiveType.Lines); GL.Begin(PrimitiveType.Lines);
foreach (TimingFlag timingFlag in _timingFlags) foreach (TimingFlag timingFlag in _timingFlags)
{ {
int x = (int)(xOffset + width - ((float)(_captureTime - (timingFlag.Timestamp + graphPositionTicks)) / timeWidthTicks) * width); int x = (int)(graphRight - ((graphPositionTicks - timingFlag.Timestamp) / timeWidthTicks) * width);
GL.Vertex2(x, 0); GL.Vertex2(x, 0);
GL.Vertex2(x, Height); GL.Vertex2(x, Height);
} }
@ -51,30 +55,30 @@ namespace Ryujinx.Profiler.UI
GL.Begin(PrimitiveType.Triangles); GL.Begin(PrimitiveType.Triangles);
foreach (var entry in _sortedProfileData) foreach (var entry in _sortedProfileData)
{ {
int furthest = 0; long furthest = 0;
bottom = GetLineY(yOffset, LineHeight, LinePadding, true, verticalIndex);
top = bottom + barHeight;
// Skip rendering out of bounds bars
if (top < 0 || bottom > Height)
continue;
GL.Color3(Color.Green); GL.Color3(Color.Green);
foreach (Timestamp timestamp in entry.Value.GetAllTimestamps()) foreach (Timestamp timestamp in entry.Value.GetAllTimestamps())
{ {
right = (int)(xOffset + width - ((float)(_captureTime - (timestamp.EndTime + graphPositionTicks)) / timeWidthTicks) * width);
// Skip drawing multiple timestamps on same pixel // Skip drawing multiple timestamps on same pixel
if (right <= furthest) if (timestamp.EndTime < furthest)
continue; continue;
furthest = timestamp.EndTime + ticksPerPixel;
left = (int)(xOffset + width - ((float)(_captureTime - (timestamp.BeginTime + graphPositionTicks)) / timeWidthTicks) * width); left = (int)(graphRight - ((graphPositionTicks - timestamp.BeginTime) / timeWidthTicks) * width);
bottom = GetLineY(yOffset, LineHeight, LinePadding, true, verticalIndex); right = (int)(graphRight - ((graphPositionTicks - timestamp.EndTime) / timeWidthTicks) * width);
top = bottom + barHeight;
// Make sure width is at least 1px // Make sure width is at least 1px
right = Math.Max(left + 1, right); right = Math.Max(left + 1, right);
furthest = right;
// Skip rendering out of bounds bars
if (top < 0 || bottom > Height)
continue;
GL.Vertex2(left, bottom); GL.Vertex2(left, bottom);
GL.Vertex2(left, top); GL.Vertex2(left, top);
GL.Vertex2(right, top); GL.Vertex2(right, top);
@ -84,30 +88,23 @@ namespace Ryujinx.Profiler.UI
GL.Vertex2(left, bottom); GL.Vertex2(left, bottom);
} }
GL.Color3(Color.Red);
// Currently capturing timestamp // Currently capturing timestamp
GL.Color3(Color.Red);
long entryBegin = entry.Value.BeginTime; long entryBegin = entry.Value.BeginTime;
if (entryBegin != -1) if (entryBegin != -1)
{ {
left = (int)(xOffset + width + _graphPosition - (((float)_captureTime - entryBegin) / timeWidthTicks) * width); left = (int)(graphRight - ((graphPositionTicks - entryBegin) / timeWidthTicks) * width);
bottom = GetLineY(yOffset, LineHeight, LinePadding, true, verticalIndex);
top = bottom + barHeight;
right = (int)(xOffset + width);
// Make sure width is at least 1px // Make sure width is at least 1px
left = Math.Min(left - 1, right); left = Math.Min(left - 1, (int)graphRight);
// Skip rendering out of bounds bars GL.Vertex2(left, bottom);
if (top < 0 || bottom > Height) GL.Vertex2(left, top);
continue; GL.Vertex2(graphRight, top);
GL.Vertex2(left, bottom); GL.Vertex2(graphRight, top);
GL.Vertex2(left, top); GL.Vertex2(graphRight, bottom);
GL.Vertex2(right, top); GL.Vertex2(left, bottom);
GL.Vertex2(right, top);
GL.Vertex2(right, bottom);
GL.Vertex2(left, bottom);
} }
verticalIndex++; verticalIndex++;
@ -120,7 +117,7 @@ namespace Ryujinx.Profiler.UI
// Dummy draw for measure // Dummy draw for measure
float labelWidth = _fontService.DrawText(label, 0, 0, LineHeight, false); float labelWidth = _fontService.DrawText(label, 0, 0, LineHeight, false);
_fontService.DrawText(label, xOffset + width - labelWidth - LinePadding, FilterHeight + LinePadding, LineHeight); _fontService.DrawText(label, graphRight - labelWidth - LinePadding, FilterHeight + LinePadding, LineHeight);
_fontService.DrawText($"-{MathF.Round((float)((timeWidthTicks / PerformanceCounter.TicksPerMillisecond) + _graphPosition), 2)} ms", xOffset + LinePadding, FilterHeight + LinePadding, LineHeight); _fontService.DrawText($"-{MathF.Round((float)((timeWidthTicks / PerformanceCounter.TicksPerMillisecond) + _graphPosition), 2)} ms", xOffset + LinePadding, FilterHeight + LinePadding, LineHeight);
} }

View file

@ -75,6 +75,7 @@ namespace Ryujinx
DumpLocation = profilePath, DumpLocation = profilePath,
UpdateRate = (float)((updateRateHz <= 0) ? -1 : 1.0f / updateRateHz), UpdateRate = (float)((updateRateHz <= 0) ? -1 : 1.0f / updateRateHz),
History = (long)(Convert.ToDouble(parser.Value("Profiling_History")) * PerformanceCounter.TicksPerSecond), History = (long)(Convert.ToDouble(parser.Value("Profiling_History")) * PerformanceCounter.TicksPerSecond),
MaxLevel = Convert.ToInt32(parser.Value("Profiling_Max_Level")),
}); });
SystemLanguage SetLanguage = Enum.Parse<SystemLanguage>(parser.Value("System_Language")); SystemLanguage SetLanguage = Enum.Parse<SystemLanguage>(parser.Value("System_Language"));

View file

@ -34,6 +34,9 @@ Profiling_Update_Rate = 4
#Set how long to keep profiling data in seconds, reduce if profiling is taking too much RAM #Set how long to keep profiling data in seconds, reduce if profiling is taking too much RAM
Profiling_History = 5 Profiling_History = 5
#Set the maximum profiling level. Higher values may cause a heavy load on your system but will allow you to profile in more detail.
Profiling_Max_Level = 0
#System Language list: https://gist.github.com/HorrorTroll/b6e4a88d774c3c9b3bdf54d79a7ca43b #System Language list: https://gist.github.com/HorrorTroll/b6e4a88d774c3c9b3bdf54d79a7ca43b
#Change System Language #Change System Language
System_Language = AmericanEnglish System_Language = AmericanEnglish