Capture actual timing data

This commit is contained in:
Andy Adshead 2019-01-23 21:53:50 +00:00
parent e8ded454d5
commit 5f9ba68c99
2 changed files with 69 additions and 4 deletions

View file

@ -1,10 +1,22 @@
using System;
using Ryujinx.Common.Logging;
using System.Collections.Concurrent;
using System.Diagnostics;
namespace Ryujinx.Profiler
{
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 ProfilerSettings Settings;
@ -27,14 +39,14 @@ namespace Ryujinx.Profiler
{
if (!ProfilingEnabled())
return;
Logger.PrintInfo(LogClass.Gpu, $"Begin {config.Name}");
ProfileInstance.BeginProfile(config);
}
public static void End(ProfileConfig config)
{
if (!ProfilingEnabled())
return;
Logger.PrintInfo(LogClass.Gpu, $"End {config.Name}");
ProfileInstance.EndProfile(config);
}
public static void Method(ProfileConfig config, Action method)
@ -47,5 +59,58 @@ namespace Ryujinx.Profiler
method();
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;
}
}
}

View file

@ -15,7 +15,7 @@ namespace Ryujinx.Profiler
{
public static ProfileConfig Test = new ProfileConfig()
{
Name = "Test",
Name = "CPU.Test",
};
}
}