Skip to content

Commit

Permalink
chore: Adjust profile generation
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromelaban committed Oct 17, 2024
1 parent 4a742fd commit c16c0bd
Showing 1 changed file with 74 additions and 75 deletions.
149 changes: 74 additions & 75 deletions src/Uno.Wasm.Bootstrap/GenerateUnoNativeAssetsTask.AOTProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,103 +38,102 @@
using Newtonsoft.Json.Linq;
using Uno.Wasm.Bootstrap.Extensions;

namespace Uno.Wasm.Bootstrap
namespace Uno.Wasm.Bootstrap;

public partial class GenerateUnoNativeAssetsTask_v0
{
public partial class GenerateUnoNativeAssetsTask_v0
/// <summary>
/// Applies a temporary workaround for https://github.com/mono/mono/issues/19824
/// </summary>
private string? TransformAOTProfile()
{
/// <summary>
/// Applies a temporary workaround for https://github.com/mono/mono/issues/19824
/// </summary>
private string? TransformAOTProfile()
{
var profilePath = AotProfile;
var profilePath = AotProfile;

Check failure on line 50 in src/Uno.Wasm.Bootstrap/GenerateUnoNativeAssetsTask.AOTProfile.cs

View workflow job for this annotation

GitHub Actions / Build and Deploy Job

The name 'AotProfile' does not exist in the current context

if (profilePath != null)
if (profilePath != null)
{
var reader = new Mono.Profiler.Aot.ProfileReader();
Mono.Profiler.Aot.ProfileData profile;
using (FileStream stream = File.OpenRead(profilePath))
{
var reader = new Mono.Profiler.Aot.ProfileReader();
Mono.Profiler.Aot.ProfileData profile;
using (FileStream stream = File.OpenRead(profilePath))
{
profile = reader.ReadAllData(stream);
}
profile = reader.ReadAllData(stream);
}

var excludedMethodsList = AOTProfileExcludedMethods
.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries)
.ToList();
var excludedMethodsList = AOTProfileExcludedMethods

Check failure on line 61 in src/Uno.Wasm.Bootstrap/GenerateUnoNativeAssetsTask.AOTProfile.cs

View workflow job for this annotation

GitHub Actions / Build and Deploy Job

The name 'AOTProfileExcludedMethods' does not exist in the current context
.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries)
.ToList();

var excludedAssemblies = MixedModeExcludedAssembly?.ToDictionary(i => i.ItemSpec, i => i.ItemSpec)
?? new Dictionary<string, string>();
var excludedAssemblies = MixedModeExcludedAssembly?.ToDictionary(i => i.ItemSpec, i => i.ItemSpec)

Check failure on line 65 in src/Uno.Wasm.Bootstrap/GenerateUnoNativeAssetsTask.AOTProfile.cs

View workflow job for this annotation

GitHub Actions / Build and Deploy Job

The name 'MixedModeExcludedAssembly' does not exist in the current context
?? new Dictionary<string, string>();

if (excludedMethodsList.Any() || excludedAssemblies.Any())
{
// LoadIntoBufferAsync uses exception filtering
excludedMethodsList.AddRange(DefaultAOTProfileExcludedMethods);

TryDumpProfileMethods(profile, "AOTProfileDump.Original.txt");
if (excludedMethodsList.Any() || excludedAssemblies.Any())
{
// LoadIntoBufferAsync uses exception filtering
excludedMethodsList.AddRange(DefaultAOTProfileExcludedMethods);

var excludedMethods = excludedMethodsList.Select(e => new Regex(e)).ToList();
TryDumpProfileMethods(profile, "AOTProfileDump.Original.txt");

var q = from m in profile.Methods
where !excludedMethods.Any(e => e.Match(m.Type.FullName + '.' + m.Name).Success)
&& !excludedAssemblies.ContainsKey(m.Type.Module.Name)
select m;
var excludedMethods = excludedMethodsList.Select(e => new Regex(e)).ToList();

profile.Methods = q.ToArray();
var q = from m in profile.Methods
where !excludedMethods.Any(e => e.Match(m.Type.FullName + '.' + m.Name).Success)
&& !excludedAssemblies.ContainsKey(m.Type.Module.Name)
select m;

TryDumpProfileMethods(profile, "AOTProfileDump.Filtered.txt");
profile.Methods = q.ToArray();

var writer = new Mono.Profiler.Aot.ProfileWriter();
TryDumpProfileMethods(profile, "AOTProfileDump.Filtered.txt");

var outputFile = Path.Combine(IntermediateOutputPath, "aot-filtered.profile");
using (var outStream = File.Create(outputFile))
{
writer.WriteAllData(outStream, profile);
}
var writer = new Mono.Profiler.Aot.ProfileWriter();

return outputFile;
var outputFile = Path.Combine(IntermediateOutputPath, "aot-filtered.profile");

Check failure on line 88 in src/Uno.Wasm.Bootstrap/GenerateUnoNativeAssetsTask.AOTProfile.cs

View workflow job for this annotation

GitHub Actions / Build and Deploy Job

The name 'IntermediateOutputPath' does not exist in the current context
using (var outStream = File.Create(outputFile))
{
writer.WriteAllData(outStream, profile);
}
}

return profilePath;
return outputFile;
}
}

private IEnumerable<string> DefaultAOTProfileExcludedMethods =>
new[]
{
@"ManifestBasedResourceGroveler\.InternalGetSatelliteAssembly", // https://github.com/dotnet/runtime/issues/45698

@"System\.Reflection\.Assembly\.GetExecutingAssembly", // https://github.com/dotnet/runtime/issues/47996
@"System\.RuntimeType\.GetType",
@"System\.RuntimeTypeHandle\.internal_from_name",
@"System\.RuntimeTypeHandle\.GetTypeByName",
@"System\.Type\.GetType",
@"System\.Runtime\.Loader\.AssemblyLoadContext\.InternalLoadFromPath",
@"System\.Runtime\.Loader\.AssemblyLoadContext\.InternalLoadFile",
@"System\.Runtime\.Loader\.AssemblyLoadContext\.LoadFromAssemblyName",
@"System\.Reflection\.Assembly\.Load",
@"System\.Reflection\.Assembly\.InternalLoad",
@"System\.Reflection\.RuntimeAssembly\.InternalGetSatelliteAssembly",
@"System\.Reflection\.RuntimeAssembly\.InternalLoad",
};

private void TryDumpProfileMethods(Mono.Profiler.Aot.ProfileData profile, string filePath)
{
if (GenerateAOTProfileDebugList)
{
var sb = new StringBuilder();
return profilePath;

Check failure on line 98 in src/Uno.Wasm.Bootstrap/GenerateUnoNativeAssetsTask.AOTProfile.cs

View workflow job for this annotation

GitHub Actions / Build and Deploy Job

Nullability of reference types in value of type '?' doesn't match target type 'string'.
}

foreach (var method in profile.Methods)
{
var genericParameters = string.Join("|", method.GenericInst?.Types.Select(t => t.ToString()) ?? []);
private IEnumerable<string> DefaultAOTProfileExcludedMethods =>
new[]
{
@"ManifestBasedResourceGroveler\.InternalGetSatelliteAssembly", // https://github.com/dotnet/runtime/issues/45698

@"System\.Reflection\.Assembly\.GetExecutingAssembly", // https://github.com/dotnet/runtime/issues/47996
@"System\.RuntimeType\.GetType",
@"System\.RuntimeTypeHandle\.internal_from_name",
@"System\.RuntimeTypeHandle\.GetTypeByName",
@"System\.Type\.GetType",
@"System\.Runtime\.Loader\.AssemblyLoadContext\.InternalLoadFromPath",
@"System\.Runtime\.Loader\.AssemblyLoadContext\.InternalLoadFile",
@"System\.Runtime\.Loader\.AssemblyLoadContext\.LoadFromAssemblyName",
@"System\.Reflection\.Assembly\.Load",
@"System\.Reflection\.Assembly\.InternalLoad",
@"System\.Reflection\.RuntimeAssembly\.InternalGetSatelliteAssembly",
@"System\.Reflection\.RuntimeAssembly\.InternalLoad",
};

private void TryDumpProfileMethods(Mono.Profiler.Aot.ProfileData profile, string filePath)
{
if (GenerateAOTProfileDebugList)

Check failure on line 122 in src/Uno.Wasm.Bootstrap/GenerateUnoNativeAssetsTask.AOTProfile.cs

View workflow job for this annotation

GitHub Actions / Build and Deploy Job

The name 'GenerateAOTProfileDebugList' does not exist in the current context
{
var sb = new StringBuilder();

sb.AppendLine($"{method.Type.Module.Name};{method.Type.FullName}.{method.Name};{method.GenericInst?.Id};{genericParameters}");
}
foreach (var method in profile.Methods)
{
var genericParameters = string.Join("|", method.GenericInst?.Types.Select(t => t.ToString()) ?? []);

File.WriteAllText(Path.Combine(IntermediateOutputPath, filePath), sb.ToString());
sb.AppendLine($"{method.Type.Module.Name};{method.Type.FullName}.{method.Name};{method.GenericInst?.Id};{genericParameters}");
}
}

private bool UseAotProfile
=> !string.IsNullOrEmpty(AotProfile) && _runtimeExecutionMode == RuntimeExecutionMode.InterpreterAndAOT;
File.WriteAllText(Path.Combine(IntermediateOutputPath, filePath), sb.ToString());

Check failure on line 133 in src/Uno.Wasm.Bootstrap/GenerateUnoNativeAssetsTask.AOTProfile.cs

View workflow job for this annotation

GitHub Actions / Build and Deploy Job

The name 'IntermediateOutputPath' does not exist in the current context
}
}

private bool UseAotProfile
=> !string.IsNullOrEmpty(AotProfile) && _runtimeExecutionMode == RuntimeExecutionMode.InterpreterAndAOT;

Check failure on line 138 in src/Uno.Wasm.Bootstrap/GenerateUnoNativeAssetsTask.AOTProfile.cs

View workflow job for this annotation

GitHub Actions / Build and Deploy Job

The name 'AotProfile' does not exist in the current context
}

0 comments on commit c16c0bd

Please sign in to comment.