diff --git a/Ryujinx.Profiler/DumpProfile.cs b/Ryujinx.Profiler/DumpProfile.cs index dd8b5718a4..652ee32d9d 100644 --- a/Ryujinx.Profiler/DumpProfile.cs +++ b/Ryujinx.Profiler/DumpProfile.cs @@ -10,10 +10,10 @@ namespace Ryujinx.Profiler String fileData = ""; foreach (var time in profile.Timers) { - fileData += $"{time.Key} - " + + fileData += $"{time.Key.Tag} - " + $"Total: {profile.ConvertTicksToMS(time.Value.TotalTime)}ms, " + $"Average: {profile.ConvertTicksToMS(time.Value.AverageTime)}ms, " + - $"Count: {time.Value.Count}\n"; + $"Count: {time.Value.Count}\r\n"; } // Ensure file directory exists before write diff --git a/Ryujinx.Profiler/InternalProfile.cs b/Ryujinx.Profiler/InternalProfile.cs index 9a458edd85..0f4147d727 100644 --- a/Ryujinx.Profiler/InternalProfile.cs +++ b/Ryujinx.Profiler/InternalProfile.cs @@ -7,11 +7,14 @@ namespace Ryujinx.Profiler public class InternalProfile { private Stopwatch SW; - internal ConcurrentDictionary Timers; + internal ConcurrentDictionary Timers; + + private object sessionLock = new object(); + private int sessionCounter = 0; public InternalProfile() { - Timers = new ConcurrentDictionary(); + Timers = new ConcurrentDictionary(); SW = new Stopwatch(); SW.Start(); } @@ -20,8 +23,8 @@ namespace Ryujinx.Profiler { long timestamp = SW.ElapsedTicks; - Timers.AddOrUpdate(config.Name, - (string s) => CreateTimer(timestamp), + Timers.AddOrUpdate(config, + (c) => CreateTimer(timestamp), ((s, info) => { info.BeginTime = timestamp; @@ -33,8 +36,8 @@ namespace Ryujinx.Profiler { long timestamp = SW.ElapsedTicks; - Timers.AddOrUpdate(config.Name, - (s => new TimingInfo()), + Timers.AddOrUpdate(config, + (c => new TimingInfo()), ((s, time) => UpdateTimer(time, timestamp))); } @@ -61,5 +64,14 @@ namespace Ryujinx.Profiler { return (((double)ticks) / Stopwatch.Frequency) * 1000.0; } + + public int GetSession() + { + // Can be called from multiple threads so locked to ensure no duplicate sessions are generated + lock (sessionLock) + { + return sessionCounter++; + } + } } } diff --git a/Ryujinx.Profiler/Profile.cs b/Ryujinx.Profiler/Profile.cs index 2754f165a2..1c4577a0ed 100644 --- a/Ryujinx.Profiler/Profile.cs +++ b/Ryujinx.Profiler/Profile.cs @@ -2,7 +2,7 @@ namespace Ryujinx.Profiler { - public class Profile + public static class Profile { // Static private static InternalProfile ProfileInstance; @@ -56,5 +56,12 @@ namespace Ryujinx.Profiler method(); End(config); } + + public static int GetSession() + { + if (!ProfilingEnabled()) + return 0; + return ProfileInstance.GetSession(); + } } } diff --git a/Ryujinx.Profiler/ProfileConfig.cs b/Ryujinx.Profiler/ProfileConfig.cs index 842e87fcd4..701943b00d 100644 --- a/Ryujinx.Profiler/ProfileConfig.cs +++ b/Ryujinx.Profiler/ProfileConfig.cs @@ -7,6 +7,19 @@ namespace Ryujinx.Profiler public struct ProfileConfig { public string Name; + public int? Session; + + private string cachedTag; + + public string Tag + { + get + { + if (cachedTag == null) + cachedTag = $"{Name}{(Session == null ? "" : $" ({Session})")}"; + return cachedTag; + } + } } public static class Profiles