Support for multiple sessions under the same name
This commit is contained in:
parent
48134b2027
commit
cb205fb35c
4 changed files with 41 additions and 9 deletions
|
@ -10,10 +10,10 @@ namespace Ryujinx.Profiler
|
||||||
String fileData = "";
|
String fileData = "";
|
||||||
foreach (var time in profile.Timers)
|
foreach (var time in profile.Timers)
|
||||||
{
|
{
|
||||||
fileData += $"{time.Key} - " +
|
fileData += $"{time.Key.Tag} - " +
|
||||||
$"Total: {profile.ConvertTicksToMS(time.Value.TotalTime)}ms, " +
|
$"Total: {profile.ConvertTicksToMS(time.Value.TotalTime)}ms, " +
|
||||||
$"Average: {profile.ConvertTicksToMS(time.Value.AverageTime)}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
|
// Ensure file directory exists before write
|
||||||
|
|
|
@ -7,11 +7,14 @@ namespace Ryujinx.Profiler
|
||||||
public class InternalProfile
|
public class InternalProfile
|
||||||
{
|
{
|
||||||
private Stopwatch SW;
|
private Stopwatch SW;
|
||||||
internal ConcurrentDictionary<string, TimingInfo> Timers;
|
internal ConcurrentDictionary<ProfileConfig, TimingInfo> Timers;
|
||||||
|
|
||||||
|
private object sessionLock = new object();
|
||||||
|
private int sessionCounter = 0;
|
||||||
|
|
||||||
public InternalProfile()
|
public InternalProfile()
|
||||||
{
|
{
|
||||||
Timers = new ConcurrentDictionary<string, TimingInfo>();
|
Timers = new ConcurrentDictionary<ProfileConfig, TimingInfo>();
|
||||||
SW = new Stopwatch();
|
SW = new Stopwatch();
|
||||||
SW.Start();
|
SW.Start();
|
||||||
}
|
}
|
||||||
|
@ -20,8 +23,8 @@ namespace Ryujinx.Profiler
|
||||||
{
|
{
|
||||||
long timestamp = SW.ElapsedTicks;
|
long timestamp = SW.ElapsedTicks;
|
||||||
|
|
||||||
Timers.AddOrUpdate(config.Name,
|
Timers.AddOrUpdate(config,
|
||||||
(string s) => CreateTimer(timestamp),
|
(c) => CreateTimer(timestamp),
|
||||||
((s, info) =>
|
((s, info) =>
|
||||||
{
|
{
|
||||||
info.BeginTime = timestamp;
|
info.BeginTime = timestamp;
|
||||||
|
@ -33,8 +36,8 @@ namespace Ryujinx.Profiler
|
||||||
{
|
{
|
||||||
long timestamp = SW.ElapsedTicks;
|
long timestamp = SW.ElapsedTicks;
|
||||||
|
|
||||||
Timers.AddOrUpdate(config.Name,
|
Timers.AddOrUpdate(config,
|
||||||
(s => new TimingInfo()),
|
(c => new TimingInfo()),
|
||||||
((s, time) => UpdateTimer(time, timestamp)));
|
((s, time) => UpdateTimer(time, timestamp)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,5 +64,14 @@ namespace Ryujinx.Profiler
|
||||||
{
|
{
|
||||||
return (((double)ticks) / Stopwatch.Frequency) * 1000.0;
|
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++;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
namespace Ryujinx.Profiler
|
namespace Ryujinx.Profiler
|
||||||
{
|
{
|
||||||
public class Profile
|
public static class Profile
|
||||||
{
|
{
|
||||||
// Static
|
// Static
|
||||||
private static InternalProfile ProfileInstance;
|
private static InternalProfile ProfileInstance;
|
||||||
|
@ -56,5 +56,12 @@ namespace Ryujinx.Profiler
|
||||||
method();
|
method();
|
||||||
End(config);
|
End(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int GetSession()
|
||||||
|
{
|
||||||
|
if (!ProfilingEnabled())
|
||||||
|
return 0;
|
||||||
|
return ProfileInstance.GetSession();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,19 @@ namespace Ryujinx.Profiler
|
||||||
public struct ProfileConfig
|
public struct ProfileConfig
|
||||||
{
|
{
|
||||||
public string Name;
|
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
|
public static class Profiles
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue