Capture actual timing data
This commit is contained in:
parent
e8ded454d5
commit
5f9ba68c99
2 changed files with 69 additions and 4 deletions
|
@ -1,10 +1,22 @@
|
||||||
using System;
|
using System;
|
||||||
using Ryujinx.Common.Logging;
|
using System.Collections.Concurrent;
|
||||||
|
using System.Diagnostics;
|
||||||
|
|
||||||
namespace Ryujinx.Profiler
|
namespace Ryujinx.Profiler
|
||||||
{
|
{
|
||||||
public class Profile
|
public class Profile
|
||||||
{
|
{
|
||||||
|
private struct TimingInfo
|
||||||
|
{
|
||||||
|
public long BeginTime, LastTime, TotalTime, Count;
|
||||||
|
public long AverageTime
|
||||||
|
{
|
||||||
|
get => (Count == 0) ? -1 : TotalTime / Count;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Static
|
||||||
private static Profile ProfileInstance;
|
private static Profile ProfileInstance;
|
||||||
private static ProfilerSettings Settings;
|
private static ProfilerSettings Settings;
|
||||||
|
|
||||||
|
@ -27,14 +39,14 @@ namespace Ryujinx.Profiler
|
||||||
{
|
{
|
||||||
if (!ProfilingEnabled())
|
if (!ProfilingEnabled())
|
||||||
return;
|
return;
|
||||||
Logger.PrintInfo(LogClass.Gpu, $"Begin {config.Name}");
|
ProfileInstance.BeginProfile(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void End(ProfileConfig config)
|
public static void End(ProfileConfig config)
|
||||||
{
|
{
|
||||||
if (!ProfilingEnabled())
|
if (!ProfilingEnabled())
|
||||||
return;
|
return;
|
||||||
Logger.PrintInfo(LogClass.Gpu, $"End {config.Name}");
|
ProfileInstance.EndProfile(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Method(ProfileConfig config, Action method)
|
public static void Method(ProfileConfig config, Action method)
|
||||||
|
@ -47,5 +59,58 @@ namespace Ryujinx.Profiler
|
||||||
method();
|
method();
|
||||||
End(config);
|
End(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Non-static
|
||||||
|
private Stopwatch SW;
|
||||||
|
private ConcurrentDictionary<string, TimingInfo> Timers;
|
||||||
|
|
||||||
|
public Profile()
|
||||||
|
{
|
||||||
|
Timers = new ConcurrentDictionary<string, TimingInfo>();
|
||||||
|
SW = new Stopwatch();
|
||||||
|
SW.Start();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void BeginProfile(ProfileConfig config)
|
||||||
|
{
|
||||||
|
long timestamp = SW.ElapsedTicks;
|
||||||
|
|
||||||
|
Timers.AddOrUpdate(config.Name,
|
||||||
|
(string s) => CreateTimer(timestamp),
|
||||||
|
((s, info) =>
|
||||||
|
{
|
||||||
|
info.BeginTime = timestamp;
|
||||||
|
return info;
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void EndProfile(ProfileConfig config)
|
||||||
|
{
|
||||||
|
long timestamp = SW.ElapsedTicks;
|
||||||
|
|
||||||
|
Timers.AddOrUpdate(config.Name,
|
||||||
|
(s => new TimingInfo()),
|
||||||
|
((s, time) => UpdateTimer(time, timestamp)));
|
||||||
|
}
|
||||||
|
|
||||||
|
private TimingInfo CreateTimer(long timestamp)
|
||||||
|
{
|
||||||
|
return new TimingInfo()
|
||||||
|
{
|
||||||
|
BeginTime = timestamp,
|
||||||
|
LastTime = 0,
|
||||||
|
Count = 0,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private TimingInfo UpdateTimer(TimingInfo time, long timestamp)
|
||||||
|
{
|
||||||
|
time.Count++;
|
||||||
|
time.LastTime = timestamp - time.BeginTime;
|
||||||
|
time.TotalTime += time.LastTime;
|
||||||
|
|
||||||
|
return time;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ namespace Ryujinx.Profiler
|
||||||
{
|
{
|
||||||
public static ProfileConfig Test = new ProfileConfig()
|
public static ProfileConfig Test = new ProfileConfig()
|
||||||
{
|
{
|
||||||
Name = "Test",
|
Name = "CPU.Test",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue