Support for multiple sessions under the same name

This commit is contained in:
Andy Adshead 2019-01-23 23:52:02 +00:00
parent 48134b2027
commit cb205fb35c
4 changed files with 41 additions and 9 deletions

View file

@ -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

View file

@ -7,11 +7,14 @@ namespace Ryujinx.Profiler
public class InternalProfile
{
private Stopwatch SW;
internal ConcurrentDictionary<string, TimingInfo> Timers;
internal ConcurrentDictionary<ProfileConfig, TimingInfo> Timers;
private object sessionLock = new object();
private int sessionCounter = 0;
public InternalProfile()
{
Timers = new ConcurrentDictionary<string, TimingInfo>();
Timers = new ConcurrentDictionary<ProfileConfig, TimingInfo>();
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++;
}
}
}
}

View file

@ -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();
}
}
}

View file

@ -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