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..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 @@ -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). - + @@ -89,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)"> @@ -102,11 +100,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)')) + + + 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 + + + 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/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 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 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