Use dotTrace Command-Line Profiler
Sometimes it is necessary to automate the process of gathering performance snapshots, for example, if you want to make profiling a part of your continuous integration builds (for example, this can be a build step that performs profiling of your integration tests). For this purpose, dotTrace offers a set of command-line tools for Windows, macOS, and Linux:
OS | Tools | Distribution |
|---|---|---|
Windows |
| |
macOS |
| |
Linux |
|
Profile applications using the command-line tool
Depending on your profiling scenario, run dotTrace.exe with the options you need. For example:
To run and profile a standalone application App.exe using the Timeline profiling type:
dotTrace.exe start --save-to=c:\Snapshots\snapshot.dtt --profiling-type=Timeline c:\MyApp\App.exeTo run and profile a standalone application App.exe (using the default Sampling profiling type) and control the session using the profiling API:
dotTrace.exe start --save-to=c:\Snapshots\snapshot.dtp c:\MyApp\App.exe --use-apiTo attach to a running application with
PID=1234and profile it using the sampling profiling type:dotTrace.exe attach 1234 --save-to=c:\Snapshots\snapshot.dtpTo see the full list of available options, run the tool without any arguments:
dotTrace.exe
After the profiled application finishes working, the command-line profiler will automatically save a performance snapshot.
If you want to take snapshots manually at any time, you can do this by sending messages to stdin of the profiler or to a file on disk.
Analyze the snapshot using the standalone dotTrace, or dotTrace in Rider.
Depending on your profiling scenario, run dotTrace.sh with the options you need. For example:
To run and profile a Mono application myMonoApp:
./dotTrace.sh start --framework=Mono /usr/bin/mono /home/Projects/MyMonoApp/myMonoApp --profiling-type=Timeline --timeout=10s --save-to=./snapshots/snapshot.dttNote that we must specify
/usr/bin/monoas a profiling target and use theTimelineprofiling type (other types are not supported for Mono on macOS and Linux).To run and profile a .NET Core 3.1 (or later) application MyNetCoreApp.dll:
./dotTrace.sh start --framework=NetCore /usr/bin/dotnet /home/Projects/MyNetCoreApp/MyNetCoreApp.dll --timeout=10s --save-to=./snapshots/snapshot.dtpTo run and profile a .NET Core 3.0 (or earlier) application MyNetCoreApp.dll:
./dotTrace.sh start --framework=NetCore /usr/bin/dotnet /home/Projects/MyNetCoreApp/MyNetCoreApp.dll --support-earlier-net-core --timeout=10s --save-to=./snapshots/snapshot.dtpTo attach to a running application with
PID=1234and profile it using the sampling profiling type:./dotTrace.sh attach 1234 --save-to=./snapshots/snapshot.dtpTo see the full list of available options, run the tool without any arguments:
./dotTrace.sh
After the profiled application finishes working, the command-line profiler will automatically save a performance snapshot.
Analyze the snapshot using the standalone dotTrace, or dotTrace in Rider.
Control profiling session with stdin or file
Sometimes it's necessary to have direct control over the profiling process, for example, get a snapshot at some exact moment by a direct command. This can be done by:
sending messages to stdin of
dotTrace.exe|dotTrace.sh,writing messages to a file on disk.
To start MyApp.exe and control profiling using stdin messages
You can start profiling using the
attachorstartcommand.If you want to control a session using stdin:
dotTrace.exe start --service-input=stdin c:\MyApp\MyApp.exeIf you want to control a session using a file:
dotTrace.exe start --service-input=file.txt c:\MyApp\MyApp.exeNote that you must create the file before running the session.
Get a snapshot by sending the following command to stdin or writing it to file.txt:
##dotTrace["get-snapshot", {pid:1234}]If
pidis specified, dotTrace will take a snapshot of the process with the specified PID. Otherwise, dotTrace will take snapshots of all profiled processes.To stop profiling and kill the profiled application, send the following command to stdin or file.txt:
##dotTrace["disconnect"]
dotTrace informs you about how the profiling process is going by sending special service messages to stdout. This might be especially helpful in case you control profiling by some external script. An example of the output:
To start myApp and control profiling using stdin messages
You can start profiling using the
attachorstartcommand.If you want to control a session using stdin:
./dotTrace.sh start --framework=NetCore --service-input=stdin ~/MyApp/myAppIf you want to control a session using a file:
./dotTrace.sh start --framework=NetCore --service-input=file.txt ~/MyApp/myAppNote that you must create the file before running the session.
Get a snapshot by sending the following command to stdin or writing it to file.txt:
##dotTrace["get-snapshot", {pid:1234}]If
pidis specified, dotTrace will take a snapshot of the process with the specified PID. Otherwise, dotTrace will take snapshots of all profiled processes.To stop profiling and kill the profiled application, send the following command to stdin or file.txt:
##dotTrace["disconnect"]
dotTrace informs you about how the profiling process is going by sending special service messages to stdout. This might be especially helpful in case you control profiling by some external script. An example of the output:
Command-line profiler exit code
By default, if the tool finishes its work successfully, its exit code is 0. This may be inconvenient in some cases. For example, if you run the tool on a CI server, you may need to get the exit code of the profiled application (for example, a unit test runner). To make the profiler return the exit code of the profiling target, use the --propagate-exit-code argument.
For example (on Windows):
(Optional, Windows only) Configure profiling using an XML file
In the section above, we have provided the profiling configuration (profiling target, profiling method, and so on) as the dotTrace.exe arguments. If you do not want to configure a session this way, you can provide the configuration in an XML file.
To simplify file creation, you can use the Configuration2Xml32.exe (and the 64-bit version Configuration2Xml64.exe) tool. This tool allows you to create the XML configuration file using the familiar user interface of the dotTrace Home window.
To create or modify a configuration file using Configuration2Xml
Run the Configuration2Xml32.exe or Configuration2Xml64.exe tool which is located in the dotTrace installation directory (by default, C:\Users\[username]\AppData\Local\JetBrains\Installations\dotTrace[N]).
To create a new profiling configuration, select the menu.
To modify an existing profiling configuration, select .
Specify profiling options as you normally do in the dotTrace Home window.
Click Save and specify the filename and path for the configuration file.
Click Save.
To run the profiling session configured via an XML file
Run the following command in the command line:
dotTrace.exe xmlfile <path_to_config> --save-to=<path_to_snapshot>where:
<path_to_config>- path to the XML configuration file.<path_to_snapshot>- path to the resulting snapshot file. Note that you can specify either the full path (including the snapshot filename) or only the path to the directory without the filename. In the latter case, the snapshot file will get a random name.
For example:
dotTrace.exe xmlfile config.xml --save-to=c:\Snapshots\snapshot.dtp
Install and use the command-line tool as a .NET Core tool
If you have .NET Core 3.1.0 or later on your machine, you can install and use the dotTrace command-line tool as a .NET Core global and local tool.
Install dotTrace command-line tool
To install the dotTrace command-line tool as a global .NET Core tool in the default location, run the following command line:
dotnet tool install --global JetBrains.dotTrace.GlobalToolsTo install the dotTrace command-line tool as a local tool, you can execute the following locally:
dotnet new tool-manifest dotnet tool install JetBrains.dotTrace.GlobalToolsFor further instructions, refer to the official Microsoft documentation.
Run the dotTrace command-line tool
Use the
dottracecommand to run profiling. The command accepts the same arguments asdotTrace.exe(on Windows) ordotTrace.sh(on Linux and macOS). For example, to start timeline profiling of MyApp.exe, open the solution directory and run:dottrace start --profiling-type=Timeline .\MyApp\bin\Release\MyApp.exe