From 399a73c22270b1223f426194b85d11a98e7dcc0b Mon Sep 17 00:00:00 2001 From: mdh1418 Date: Fri, 30 Aug 2024 14:49:56 -0400 Subject: [PATCH 1/5] [ProfiledAOT] Add tracing script The supported scenario for collecting profiles involves the diagnostics tools dotnet-trace and dotnet-dsrouter. To maintain a single step profile workflow, add a script to automatically record a trace. --- src/profiled-aot/recordTrace.sh | 34 +++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100755 src/profiled-aot/recordTrace.sh diff --git a/src/profiled-aot/recordTrace.sh b/src/profiled-aot/recordTrace.sh new file mode 100755 index 00000000000..794576e1264 --- /dev/null +++ b/src/profiled-aot/recordTrace.sh @@ -0,0 +1,34 @@ +#!/bin/bash +dotnet="$1" + +# Get the PID of dotnet-dsrouter +dsrouter_pid=$(pgrep -f "dotnet dsrouter") + +if [ -z "$dsrouter_pid" ]; then + dotnet dsrouter android > >(while IFS= read -r line + do + # Print the line to the terminal + echo "$line" + # Check if the line contains 'pid=' + if [[ $line == *"pid="* ]]; then + # Extract the PID value + pid_value=$(echo $line | grep -o 'pid=[0-9]*' | cut -d '=' -f2) + echo "Found pid: $pid_value" + # You can add code here to do something with the PID value + echo "$pid_value" > /tmp/pid_value.txt + break # Exit the loop after finding the first value + fi + done) & + + dsrouter_pid=$(pgrep -f "dotnet dsrouter") + trap "kill $dsrouter_pid" EXIT +fi + +# # Run dotnet trace collect using the obtained PID and specified format +dotnet trace collect --name dotnet-dsrouter --providers Microsoft-Windows-DotNETRuntime:0x1F000080018:5 --duration 00:00:00:05 # --stopping-event-provider-name Microsoft-Windows-DotNETRuntime --stopping-event-event-name Method/JittingStarted --stopping-event-payload-filter MethodName:PrintA + +# Check if there were any errors when running the command +if [ $? -ne 0 ]; then + echo "Error occurred while running the command." + exit 1 +fi \ No newline at end of file From e0c3f4d0ac6ca692aa9cb4532d3bc9f12947ffe6 Mon Sep 17 00:00:00 2001 From: mdh1418 Date: Fri, 30 Aug 2024 14:50:56 -0400 Subject: [PATCH 2/5] [ProfiledAOT] Introduce new profiler targets --- src/profiled-aot/Directory.Build.targets | 56 +----------------------- src/profiled-aot/new.profiler.targets | 37 ++++++++++++++++ src/profiled-aot/old.profiler.targets | 56 ++++++++++++++++++++++++ 3 files changed, 95 insertions(+), 54 deletions(-) create mode 100644 src/profiled-aot/new.profiler.targets create mode 100644 src/profiled-aot/old.profiler.targets diff --git a/src/profiled-aot/Directory.Build.targets b/src/profiled-aot/Directory.Build.targets index 81e53cc0ecf..8b4971fdb8f 100644 --- a/src/profiled-aot/Directory.Build.targets +++ b/src/profiled-aot/Directory.Build.targets @@ -1,56 +1,4 @@ - - apk - false - false - - - - - - - - - Clean; - _ClearSystemProperties; - BuildAndStartAotProfiling; - _Sleep; - FinishAotProfiling; - _StripAppMethods; - _SaveMethodNames; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + diff --git a/src/profiled-aot/new.profiler.targets b/src/profiled-aot/new.profiler.targets new file mode 100644 index 00000000000..fe9e6e59f19 --- /dev/null +++ b/src/profiled-aot/new.profiler.targets @@ -0,0 +1,37 @@ + + + <_RecordDependsOnTargets> + Clean; + Build; + Install; + _ProfileApp; + Uninstall; + + <_ProfileAppDependsOnTargets> + _ResolveMonoAndroidSdks; + _SetupDiagnosticsTracingProperties; + StartAndroidActivity; + _StartTracing; + StopAndroidPackage; + + $(MSBuildThisFileDirectory)recordTrace.sh + + + + + + + + + + ANDROID_SDK_ROOT=$(AndroidSdkPath) + + + + + + + + + + \ No newline at end of file diff --git a/src/profiled-aot/old.profiler.targets b/src/profiled-aot/old.profiler.targets new file mode 100644 index 00000000000..a4ba9852864 --- /dev/null +++ b/src/profiled-aot/old.profiler.targets @@ -0,0 +1,56 @@ + + + apk + false + false + + + + + + + + + Clean; + _ClearSystemProperties; + BuildAndStartAotProfiling; + _Sleep; + FinishAotProfiling; + _StripAppMethods; + _SaveMethodNames; + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From 5ba947d71cb1c6eef5d0df4fed64b4eb064033b4 Mon Sep 17 00:00:00 2001 From: mdh1418 Date: Fri, 30 Aug 2024 14:51:14 -0400 Subject: [PATCH 3/5] [ProfiledAot] Update profiled aot proj --- src/profiled-aot/build.proj | 59 ++++++++++++++++++++++++++++++------- 1 file changed, 48 insertions(+), 11 deletions(-) diff --git a/src/profiled-aot/build.proj b/src/profiled-aot/build.proj index e34b76e4be0..752023e96fb 100644 --- a/src/profiled-aot/build.proj +++ b/src/profiled-aot/build.proj @@ -1,22 +1,59 @@ - + - - android - android-arm64 + android obj/$(App)/ $(Intermediate)$(App).csproj + android-arm64 + <_RecordProfileDependsOnTargets> + _CheckDiagnosticsTools; + _SetupAppForProfiling; + _Restore; + + <_LegacyRecordProfileDependsOnTargets> + _SetupAppForProfiling; + _Restore; + - - - - + + + + + + + + + + + + + + + + DOTNET_MULTILEVEL_LOOKUP=0 + - <_FilesToCopy Include="$(App)/*" /> + <_FilesToCopy Include="src/$(App)/*" /> + + + + + + - + + + + - + + + + + + + + \ No newline at end of file From 46e063b6380a5428eea4f1a62c6b73605cf5aeea Mon Sep 17 00:00:00 2001 From: mdh1418 Date: Fri, 30 Aug 2024 14:52:16 -0400 Subject: [PATCH 4/5] [targets] Update Microsoft.Android.Sdk.Aot.Targets --- .../targets/Microsoft.Android.Sdk.Aot.targets | 34 ++++++++++++++++--- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.Aot.targets b/src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.Aot.targets index 1ae80b94409..c2687868150 100644 --- a/src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.Aot.targets +++ b/src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.Aot.targets @@ -23,6 +23,7 @@ They run in a context of an inner build with a single $(RuntimeIdentifier). --> + @@ -39,7 +40,7 @@ They run in a context of an inner build with a single $(RuntimeIdentifier). + DependsOnTargets="_CreatePropertiesCache;_AndroidAotInputs;_AndroidBeforeAotCompilation;_AndroidAotCompilation"> @@ -71,9 +72,7 @@ They run in a context of an inner build with a single $(RuntimeIdentifier). - + @@ -102,11 +101,37 @@ They run in a context of an inner build with a single $(RuntimeIdentifier). <_MonoAOTAssemblies Update="@(_MonoAOTAssemblies)" ProcessArguments="$(AndroidExtraAotOptions)" /> + + + + + <_ToolPath>$([System.IO.Path]::GetDirectoryName('$(DotnetPgoToolPath)')) + + + + + + + + + + <_MonoAOTCompilerPath>@(MonoAotCrossCompiler->WithMetadataValue('RuntimeIdentifier', '$(RuntimeIdentifier)')) <_LLVMPath Condition=" '$(EnableLLVM)' == 'true' ">$([System.IO.Path]::GetDirectoryName ('$(_MonoAOTCompilerPath)')) + + + From d67bb24b7c85c29eba7567997b867794ed80644f Mon Sep 17 00:00:00 2001 From: mdh1418 Date: Fri, 13 Sep 2024 13:07:33 -0400 Subject: [PATCH 5/5] Fix new profile consumption --- .../targets/Microsoft.Android.Sdk.Aot.targets | 1 - src/profiled-aot/Directory.Build.props | 7 ++++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.Aot.targets b/src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.Aot.targets index c2687868150..aac59f5086e 100644 --- a/src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.Aot.targets +++ b/src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.Aot.targets @@ -88,7 +88,6 @@ They run in a context of an inner build with a single $(RuntimeIdentifier). AotOutputDirectory="$(_AndroidAotBinDirectory)" RuntimeIdentifier="$(RuntimeIdentifier)" EnableLLVM="$(EnableLLVM)" - Profiles="@(AndroidAotProfile)" StripLibraries="$(_AndroidAotStripLibraries)" ZipAlignmentPages="$(AndroidZipAlignment)"> diff --git a/src/profiled-aot/Directory.Build.props b/src/profiled-aot/Directory.Build.props index f395b28b993..c20370664b5 100644 --- a/src/profiled-aot/Directory.Build.props +++ b/src/profiled-aot/Directory.Build.props @@ -3,10 +3,15 @@ Release true true - false $(NoWarn);CA1305 + + + false + + +