2019-04-25 22:53:10 -06:00
|
|
|
|
using Ryujinx.Common;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Diagnostics;
|
2019-04-27 06:57:42 -06:00
|
|
|
|
using System.IO;
|
2019-04-25 22:53:10 -06:00
|
|
|
|
|
|
|
|
|
namespace Ryujinx.Profiler
|
|
|
|
|
{
|
|
|
|
|
public static class Profile
|
|
|
|
|
{
|
|
|
|
|
public static float UpdateRate => _settings.UpdateRate;
|
|
|
|
|
public static long HistoryLength => _settings.History;
|
|
|
|
|
|
|
|
|
|
public static ProfilerKeyboardHandler Controls => _settings.Controls;
|
|
|
|
|
|
|
|
|
|
private static InternalProfile _profileInstance;
|
|
|
|
|
private static ProfilerSettings _settings;
|
|
|
|
|
|
|
|
|
|
[Conditional("USE_PROFILING")]
|
2019-07-01 20:39:22 -06:00
|
|
|
|
public static void Initialize()
|
2019-04-25 22:53:10 -06:00
|
|
|
|
{
|
2019-04-27 06:57:42 -06:00
|
|
|
|
var config = ProfilerConfiguration.Load(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ProfilerConfig.jsonc"));
|
2019-04-25 22:53:10 -06:00
|
|
|
|
|
|
|
|
|
_settings = new ProfilerSettings()
|
|
|
|
|
{
|
|
|
|
|
Enabled = config.Enabled,
|
|
|
|
|
FileDumpEnabled = config.DumpPath != "",
|
|
|
|
|
DumpLocation = config.DumpPath,
|
|
|
|
|
UpdateRate = (config.UpdateRate <= 0) ? -1 : 1.0f / config.UpdateRate,
|
|
|
|
|
History = (long)(config.History * PerformanceCounter.TicksPerSecond),
|
|
|
|
|
MaxLevel = config.MaxLevel,
|
|
|
|
|
Controls = config.Controls,
|
|
|
|
|
MaxFlags = config.MaxFlags,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static bool ProfilingEnabled()
|
|
|
|
|
{
|
|
|
|
|
#if USE_PROFILING
|
|
|
|
|
if (!_settings.Enabled)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (_profileInstance == null)
|
|
|
|
|
_profileInstance = new InternalProfile(_settings.History, _settings.MaxFlags);
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
#else
|
|
|
|
|
return false;
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Conditional("USE_PROFILING")]
|
|
|
|
|
public static void FinishProfiling()
|
|
|
|
|
{
|
|
|
|
|
if (!ProfilingEnabled())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (_settings.FileDumpEnabled)
|
|
|
|
|
DumpProfile.ToFile(_settings.DumpLocation, _profileInstance);
|
|
|
|
|
|
|
|
|
|
_profileInstance.Dispose();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Conditional("USE_PROFILING")]
|
|
|
|
|
public static void FlagTime(TimingFlagType flagType)
|
|
|
|
|
{
|
|
|
|
|
if (!ProfilingEnabled())
|
|
|
|
|
return;
|
|
|
|
|
_profileInstance.FlagTime(flagType);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Conditional("USE_PROFILING")]
|
2019-07-01 20:39:22 -06:00
|
|
|
|
public static void RegisterFlagReceiver(Action<TimingFlag> receiver)
|
2019-04-25 22:53:10 -06:00
|
|
|
|
{
|
|
|
|
|
if (!ProfilingEnabled())
|
|
|
|
|
return;
|
2019-07-01 20:39:22 -06:00
|
|
|
|
_profileInstance.RegisterFlagReceiver(receiver);
|
2019-04-25 22:53:10 -06:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Conditional("USE_PROFILING")]
|
|
|
|
|
public static void Begin(ProfileConfig config)
|
|
|
|
|
{
|
|
|
|
|
if (!ProfilingEnabled())
|
|
|
|
|
return;
|
|
|
|
|
if (config.Level > _settings.MaxLevel)
|
|
|
|
|
return;
|
|
|
|
|
_profileInstance.BeginProfile(config);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Conditional("USE_PROFILING")]
|
|
|
|
|
public static void End(ProfileConfig config)
|
|
|
|
|
{
|
|
|
|
|
if (!ProfilingEnabled())
|
|
|
|
|
return;
|
|
|
|
|
if (config.Level > _settings.MaxLevel)
|
|
|
|
|
return;
|
|
|
|
|
_profileInstance.EndProfile(config);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string GetSession()
|
|
|
|
|
{
|
|
|
|
|
#if USE_PROFILING
|
|
|
|
|
if (!ProfilingEnabled())
|
|
|
|
|
return null;
|
|
|
|
|
return _profileInstance.GetSession();
|
|
|
|
|
#else
|
|
|
|
|
return "";
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static List<KeyValuePair<ProfileConfig, TimingInfo>> GetProfilingData()
|
|
|
|
|
{
|
|
|
|
|
#if USE_PROFILING
|
|
|
|
|
if (!ProfilingEnabled())
|
|
|
|
|
return new List<KeyValuePair<ProfileConfig, TimingInfo>>();
|
|
|
|
|
return _profileInstance.GetProfilingData();
|
|
|
|
|
#else
|
|
|
|
|
return new List<KeyValuePair<ProfileConfig, TimingInfo>>();
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static TimingFlag[] GetTimingFlags()
|
|
|
|
|
{
|
|
|
|
|
#if USE_PROFILING
|
|
|
|
|
if (!ProfilingEnabled())
|
|
|
|
|
return new TimingFlag[0];
|
|
|
|
|
return _profileInstance.GetTimingFlags();
|
|
|
|
|
#else
|
|
|
|
|
return new TimingFlag[0];
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static (long[], long[]) GetTimingAveragesAndLast()
|
|
|
|
|
{
|
|
|
|
|
#if USE_PROFILING
|
|
|
|
|
if (!ProfilingEnabled())
|
|
|
|
|
return (new long[0], new long[0]);
|
|
|
|
|
return _profileInstance.GetTimingAveragesAndLast();
|
|
|
|
|
#else
|
|
|
|
|
return (new long[0], new long[0]);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|