iOS / macOS
Below is a guide for profiling .NET iOS and .NET MacOS applications:
Profiling in .NET
See Profiling App Launch for information about how to profile the app's launch.
Note Only debug builds have profiling support enabled by default.
mlaunch
This document references the mlaunch tool, the easiest way to get it is to install Xamarin.iOS if you don't have it installed already. Latest package as of this writing: xamarin.ios-15.10.0.5.pkg.
Once installed, the mlaunch tool can be found here:
/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/bin/mlaunch
The mlaunch tool is also installed with the iOS workload for .NET, but the location on disk depends on the actual version installed, so it's a bit harder to find.
In any case, creating an alias will allow the instructions below to work:
Otherwise replace mlaunch with the full path according to the location on disk on your system.
Mobile apps
Initial configuration
We need the dotnet-dsrouter and dotnet-trace tools, so let's install them:
Note This pull request for
dotnet-dsrouteris required for profiling on device to work: https://github.com/dotnet/diagnostics/pull/3134
Simulator
The first step is to launch the tool that provides a connection between the app and the .NET tracing tools:
Launch the app and make it suspend upon launch (waiting for the .NET tooling to connect):
At this point it's necessary to wait until the following line shows up in the terminal:
The runtime has been configured to pause during startup and is awaiting a Diagnostics IPC ResumeStartup command from a Diagnostic Port
Once that's printed, go ahead and start profiling:
How to find a simulator to use
Execute the following to get the list of all available simulators on your machine:
Then pick an applicable device, and copy the UDID (50BCC90D-7E56-4AFB-89C5-3688BF345998 would be an example here), and pass the following to mlaunch:
It's also possible to specify a runtime/devicetype combination; the valid values can be queried with simctl like this:
and
and then finally pass the selected values to mlaunch like this:
Device
Note This pull request for
dotnet-dsrouteris required for profiling on device to work: https://github.com/dotnet/diagnostics/pull/3134
The first step is to connect an iOS device to the Mac using a USB cable.
The process is very similar to the process for the simulator:
Launch the tool that bridges the app and the .NET tracing tools:
Compared to the simulator, this:
Adds
--forward-port iOSChanges the local ports, both client (
~/my-dev-portvs~/my-sim-port) and server (:9001vs:9000) - it's easier to debug any problems when using different ports.
Install & launch the app and make it suspend upon launch:
At this point it's necessary to wait until the following line shows up in the terminal:
The runtime has been configured to pause during startup and is awaiting a Diagnostics IPC ResumeStartup command from a Diagnostic Port
Once that's printed, go ahead and start profiling:
Desktop
Profiling on the desktop (both macOS and Mac Catalyst apps are the same) is much easier.
Launch the executable, passing the
DOTNET_DiagnosticPortsvariable directly:At this point it's necessary to wait until the following line shows up in the terminal:
The runtime has been configured to pause during startup and is awaiting a Diagnostics IPC ResumeStartup command from a Diagnostic Port
Once that's printed, go ahead and start profiling:
Analyzing the results
In this guide I've selected to save the profiling results as speedscope files. These can be viewed in various ways, for instance online at https://speedscope.app.
References
Last updated