Inital seperated config support

This commit is contained in:
Andy Adshead 2019-02-15 11:05:10 +00:00
parent 7c011cfca7
commit 6283bae8ad
5 changed files with 115 additions and 7 deletions

View file

@ -1,4 +1,5 @@
using System;
using Ryujinx.Common;
using System;
using System.Collections.Generic;
using System.Diagnostics;
@ -12,6 +13,23 @@ namespace Ryujinx.Profiler
private static InternalProfile _profileInstance;
private static ProfilerSettings _settings;
[Conditional("USE_PROFILING")]
public static void Initalize()
{
var config = ProfilerConfiguration.Load("ProfilerConfig.jsonc");
_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,
};
}
public static bool ProfilingEnabled()
{
#if USE_PROFILING
@ -27,12 +45,6 @@ namespace Ryujinx.Profiler
#endif
}
[Conditional("USE_PROFILING")]
public static void Configure(ProfilerSettings settings)
{
_settings = settings;
}
[Conditional("USE_PROFILING")]
public static void FinishProfiling()
{

View file

@ -0,0 +1,18 @@
{
"$schema": "./_schema.json",
// Enable profiling (Only available on a profiling enabled build)
"enabled": true,
// Set profile file dump location, if blank file dumping disabled. (e.g. `ProfileDump.csv`)
"dump_path": "",
// Update rate for profiler UI, in hertz. -1 updates every time a frame is issued
"update_rate": 4,
// Set how long to keep profiling data in seconds, reduce if profiling is taking too much RAM
"history": 5,
// Set the maximum profiling level. Higher values may cause a heavy load on your system but will allow you to profile in more detail
"max_level": 0
}

View file

@ -0,0 +1,70 @@
using OpenTK.Input;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using Utf8Json;
using Utf8Json.Resolvers;
namespace Ryujinx.Profiler
{
public class ProfilerConfiguration
{
public bool Enabled { get; private set; }
public string DumpPath { get; private set; }
public float UpdateRate { get; private set; }
public int MaxLevel { get; private set; }
public float History { get; private set; }
/// <summary>
/// Loads a configuration file from disk
/// </summary>
/// <param name="path">The path to the JSON configuration file</param>
public static ProfilerConfiguration Load(string path)
{
var resolver = CompositeResolver.Create(
new[] { new ConfigurationEnumFormatter<Key>() },
new[] { StandardResolver.AllowPrivateSnakeCase }
);
if (!File.Exists(path))
{
throw new FileNotFoundException($"Profiler configuration file {path} not found");
}
using (Stream stream = File.OpenRead(path))
{
return JsonSerializer.Deserialize<ProfilerConfiguration>(stream, resolver);
}
}
private class ConfigurationEnumFormatter<T> : IJsonFormatter<T>
where T : struct
{
public void Serialize(ref JsonWriter writer, T value, IJsonFormatterResolver formatterResolver)
{
formatterResolver.GetFormatterWithVerify<string>()
.Serialize(ref writer, value.ToString(), formatterResolver);
}
public T Deserialize(ref JsonReader reader, IJsonFormatterResolver formatterResolver)
{
if (reader.ReadIsNull())
{
return default(T);
}
var enumName = formatterResolver.GetFormatterWithVerify<string>()
.Deserialize(ref reader, formatterResolver);
if (Enum.TryParse<T>(enumName, out T result))
{
return result;
}
return default(T);
}
}
}
}

View file

@ -30,4 +30,10 @@
<ProjectReference Include="..\Ryujinx.Common\Ryujinx.Common.csproj" />
</ItemGroup>
<ItemGroup Condition="'$(Configuration)' == 'Profile Debug' Or '$(Configuration)' == 'Profile Release'">
<None Update="ProfilerConfig.jsonc">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>

View file

@ -26,6 +26,8 @@ namespace Ryujinx
Configuration.Load(Path.Combine(ApplicationDirectory, "Config.jsonc"));
Configuration.Configure(device);
Profile.Initalize();
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
AppDomain.CurrentDomain.ProcessExit += CurrentDomain_ProcessExit;