Skip to content

Commit

Permalink
[Android] Introduce NetTraceToMibcConverter task & streamline testing…
Browse files Browse the repository at this point in the history
… targets

NetTraceToMibcConverter

- Used in profiled AOT scenarios where a .nettrace file is given as input and is converted to a .mibc file that can be fed into the AOT compiler. This previously was in the AotCompiler task, but for clarity purposes is now separated out.

Streamline Android testing targets

- The testing targets function the same, but are now structured similarly to iOS and Wasm.

- Introduced new testing properties to support profiled AOT:

RunProfileAOT - true/false to control the mode the aot compiler is set in.

NetTracePath - The path to a .nettrace file that will be converted into a .mibc file and fed into the aot compiler

RuntimeComponents - The list of native components to include in the test app build (diagnostics_tracing)

DiagnosticsPorts - The ip address:port where the runtime will listen when running diagnostic tooling

DiagnosticStartup - The mode the runtime will use at startup for diagnostic scenarios. Suspend will halt the app very early and wait, while nosuspend will wait for a connection, but not halt the runtime
  • Loading branch information
Steve Pfister committed Jul 18, 2022
1 parent 5821443 commit 3363776
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 36 deletions.
1 change: 1 addition & 0 deletions eng/Subsets.props
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
<DefaultMonoSubsets Condition="'$(TargetOS)' == 'Browser'">$(DefaultMonoSubsets)mono.wasmruntime+</DefaultMonoSubsets>
<DefaultMonoSubsets Condition="'$(MonoCrossAOTTargetOS)' != ''">$(DefaultMonoSubsets)mono.aotcross+</DefaultMonoSubsets>
<DefaultMonoSubsets>$(DefaultMonoSubsets)mono.runtime+mono.corelib+mono.packages+mono.tools+</DefaultMonoSubsets>
<DefaultMonoSubsets Condition="'$(TargetsMobile)' != 'true'">$(DefaultMonoSubsets)host+</DefaultMonoSubsets>

<DefaultLibrariesSubsets Condition="'$(BuildTargetFramework)' == '$(NetCoreAppCurrent)' or
'$(BuildTargetFramework)' == '' or
Expand Down
3 changes: 2 additions & 1 deletion src/mono/msbuild/android/build/AndroidApp.targets
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@

<MonoAOTCompilerDefaultAotArguments Include="static" />
<MonoAOTCompilerDefaultAotArguments Include="dwarfdebug" />
<MonoAOTCompilerDefaultAotArguments Include="direct-icalls" />
<MonoAOTCompilerDefaultAotArguments Condition="'$(_AOTMode)' == 'Full'" Include="direct-icalls" />

<MonoAOTCompilerDefaultAotArguments Include="nimt-trampolines=2000" />
<MonoAOTCompilerDefaultAotArguments Include="ntrampolines=10000" />
Expand Down Expand Up @@ -137,6 +137,7 @@
EnvironmentVariables="@(AndroidEnv)"
ForceAOT="$(RunAOTCompilation)"
ForceInterpreter="$(MonoForceInterpreter)"
ProfileAOT="$(RunProfileAOT)"
StripDebugSymbols="False"
RuntimeComponents="$(RuntimeComponents)"
DiagnosticPorts="$(DiagnosticPorts)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

<ItemGroup>
<ProjectReference Include="$(RepoTasksDir)AotCompilerTask\MonoAOTCompiler.csproj" />
<ProjectReference Include="$(RepoTasksDir)NetTraceToMibcConverterTask\NetTraceToMibcConverter.csproj" />

<PackageFile Include="build\$(MSBuildProjectName).props" TargetPath="build" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
<PropertyGroup>
<MonoAOTCompilerTasksAssemblyPath Condition="'$(MSBuildRuntimeType)' == 'Core'">$(MSBuildThisFileDirectory)..\tasks\${TargetFrameworkForNETCoreTasks}\MonoAOTCompiler.dll</MonoAOTCompilerTasksAssemblyPath>
<MonoAOTCompilerTasksAssemblyPath Condition="'$(MSBuildRuntimeType)' != 'Core'">$(MSBuildThisFileDirectory)..\tasks\${TargetFrameworkForNETFrameworkTasks}\MonoAOTCompiler.dll</MonoAOTCompilerTasksAssemblyPath>
<NetTraceToMibcConverterTasksAssemblyPath Condition="'$(MSBuildRuntimeType)' == 'Core'">$(MSBuildThisFileDirectory)..\tasks\${TargetFrameworkForNETCoreTasks}\NetTraceToMibcConverter.dll</NetTraceToMibcConverterTasksAssemblyPath>
<NetTraceToMibcConverterTasksAssemblyPath Condition="'$(MSBuildRuntimeType)' != 'Core'">$(MSBuildThisFileDirectory)..\tasks\${TargetFrameworkForNETFrameworkTasks}\NetTraceToMibcConverter.dll</NetTraceToMibcConverterTasksAssemblyPath>
</PropertyGroup>
<UsingTask TaskName="MonoAOTCompiler" AssemblyFile="$(MonoAOTCompilerTasksAssemblyPath)" />
<UsingTask TaskName="NetTraceToMibcConverter" AssemblyFile="$(NetTraceToMibcConverterTasksAssemblyPath)" />
</Project>
6 changes: 6 additions & 0 deletions src/tasks/AndroidAppBuilder/AndroidAppBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ public class AndroidAppBuilderTask : Task
/// </summary>
public bool ForceAOT { get; set; }

/// <summary>
/// Indicates if the assemblies to aot were gathered from a profile
/// </summary>
public bool ProfileAOT { get; set; }

/// <summary>
/// Static linked runtime
/// </summary>
Expand Down Expand Up @@ -108,6 +113,7 @@ public override bool Execute()
apkBuilder.KeyStorePath = KeyStorePath;
apkBuilder.ForceInterpreter = ForceInterpreter;
apkBuilder.ForceAOT = ForceAOT;
apkBuilder.ProfileAOT = ProfileAOT;
apkBuilder.EnvironmentVariables = EnvironmentVariables;
apkBuilder.StaticLinkedRuntime = StaticLinkedRuntime;
apkBuilder.RuntimeComponents = RuntimeComponents;
Expand Down
6 changes: 6 additions & 0 deletions src/tasks/AndroidAppBuilder/ApkBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class ApkBuilder
public string? KeyStorePath { get; set; }
public bool ForceInterpreter { get; set; }
public bool ForceAOT { get; set; }
public bool ProfileAOT { get; set; }
public ITaskItem[] EnvironmentVariables { get; set; } = Array.Empty<ITaskItem>();
public bool InvariantGlobalization { get; set; }
public bool EnableRuntimeLogging { get; set; }
Expand Down Expand Up @@ -322,6 +323,11 @@ public ApkBuilder(TaskLoggingHelper logger)
}
}

if (ProfileAOT)
{
defines.AppendLine("add_definitions(-DPROFILE_AOT=1)");
}

if (!string.IsNullOrEmpty(DiagnosticPorts))
{
defines.AppendLine("add_definitions(-DDIAGNOSTIC_PORTS=\"" + DiagnosticPorts + "\")");
Expand Down
9 changes: 7 additions & 2 deletions src/tasks/AndroidAppBuilder/Templates/monodroid.c
Original file line number Diff line number Diff line change
Expand Up @@ -273,9 +273,14 @@ mono_droid_runtime_init (const char* executable, int managed_argc, char* managed
LOG_INFO("AOT Enabled");
#if STATIC_AOT
register_aot_modules();
#endif
#endif // STATIC_AOT

#if PROFILE_AOT
mono_jit_set_aot_mode(MONO_AOT_MODE_NORMAL);
#else
mono_jit_set_aot_mode(MONO_AOT_MODE_FULL);
#endif
#endif // PROFILE_AOT
#endif // FORCE_INTERPRETER

MonoDomain *domain = mono_jit_init_version ("dotnet.android", "mobile");
assert (domain);
Expand Down
27 changes: 0 additions & 27 deletions src/tasks/NetTraceToMibcConverterTask/NetTraceToMibcConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Reflection.Metadata;
using System.Text;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
using System.Reflection.PortableExecutable;
using System.Text.Json.Serialization;

public class NetTraceToMibcConverter : Microsoft.Build.Utilities.Task
Expand Down Expand Up @@ -56,8 +54,6 @@ public class NetTraceToMibcConverter : Microsoft.Build.Utilities.Task
[Output]
public string? MibcProfilePath { get; set; }

private FileCache? _cache;

private bool ProcessAndValidateArguments()
{
if (!File.Exists(MibcConverterBinaryPath))
Expand Down Expand Up @@ -99,22 +95,13 @@ public override bool Execute()
Log.LogError(laee.Message);
return false;
}
/*finally
{
//if (_cache != null)
//{
// _cache.Save(CacheFilePath!);
//}
}*/
}

private bool ExecuteInternal()
{
if (!ProcessAndValidateArguments())
return false;

_cache = new FileCache(CacheFilePath, Log);

if (!ProcessNettrace(NetTracePath))
return false;

Expand All @@ -125,20 +112,6 @@ private bool ProcessNettrace(string netTraceFile)
{
var outputMibcPath = Path.Combine(OutputDir, Path.ChangeExtension(Path.GetFileName(netTraceFile), ".mibc"));

if (_cache!.Enabled)
{
string hash = Utils.ComputeHash(netTraceFile);
if (!_cache!.UpdateAndCheckHasFileChanged($"-mibc-source-file-{Path.GetFileName(netTraceFile)}", hash))
{
Log.LogMessage(MessageImportance.Low, $"Skipping generating {outputMibcPath} from {netTraceFile} because source file hasn't changed");
return true;
}
else
{
Log.LogMessage(MessageImportance.Low, $"Generating {outputMibcPath} from {netTraceFile} because the source file's hash has changed.");
}
}

StringBuilder pgoArgsStr = new StringBuilder(string.Empty);
pgoArgsStr.Append($"create-mibc");
pgoArgsStr.Append($" --trace {netTraceFile} ");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>$(TargetFrameworkForNETCoreTasks)</TargetFramework>
<TargetFrameworks>$(TargetFrameworkForNETCoreTasks);$(TargetFrameworkForNETFrameworkTasks)</TargetFrameworks>
<OutputType>Library</OutputType>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
Expand All @@ -14,18 +14,16 @@
</ItemGroup>
<ItemGroup>
<Compile Include="NetTraceToMibcConverter.cs" />
<Compile Include="..\Common\CompilerCache.cs" />
<Compile Include="..\Common\ProxyFile.cs" />
<Compile Include="..\Common\FileCache.cs" />
<Compile Include="..\Common\Utils.cs" />
<Compile Include="..\Common\LogAsErrorException.cs" />
<Compile Include="$(RepoRoot)src\libraries\System.Private.CoreLib\src\System\Diagnostics\CodeAnalysis\NullableAttributes.cs" Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework'" />
</ItemGroup>

<!-- GetFilesToPackage assists to place `MonoAOTCompiler.dll` in a NuGet package in Microsoft.NET.Runtime.MonoAOTCompiler.Task.pkgproj for external use -->
<!-- GetFilesToPackage assists to place the task dlls in a pkgproj for external use -->
<Target Name="GetFilesToPackage" Returns="@(FilesToPackage)">
<ItemGroup>
<_PublishFramework Remove="@(_PublishFramework)" />
<_PublishFramework Include="$(TargetFramework)" />
<_PublishFramework Include="$(TargetFrameworks)" />

<FilesToPackage Include="$(OutputPath)%(_PublishFramework.Identity)\$(AssemblyName).dll" TargetPath="tasks\%(_PublishFramework.Identity)" />
<FilesToPackage Include="$(OutputPath)%(_PublishFramework.Identity)\$(AssemblyName).pdb" TargetPath="tasks\%(_PublishFramework.Identity)" />
Expand Down

0 comments on commit 3363776

Please sign in to comment.