#Source generator profiling?
1 messages · Page 1 of 1 (latest)
hi @zealous lotus ! nice to meet you, here Nico from Unity :D. You can use any native profiler tool like Jetbrains dotTrace, Superliminal, or even ETW (in example, https://github.com/google/UIforETW/releases/tag/v1.56) to profile the execution of the roslyn compiler for the assembly-csharp.dll, there you will be able to see the cost of the source gen for your project's source code. consider that if you are using assembly definitons, replace any mention to assembly-chsarp in this post to the name of your assembly definition file.
In order to do this, you need to profile the dotnet.exe executable (usually located in C:\Program Files\dotnet\dotnet.exe) being executed with two arguments, the roslyn compiler dll path used by unity, and the RSP file path which contains build commands that unity used to build the dll. The roslyn dll is called csc.dll and is located in the unity install folder, usually under Data/DotNetSdkRoslyn, but this location might vary in unity versions. Then to locate the rsp file, in Unity 2021.3 using entities 0.51, you can open the editor.log file and look for Assembly-Csharp.rsp, which will show the entire path to the rsp file. Again, the location might vary between unity and entities versions. You can test your arguments are correct by executing the following command line in the root folder of your project: [DOTNETEXE PATH] [ROSLYN DLL] @[RSP PATH], in my case it was something like: "C:\Program Files\dotnet\dotnet.exe" "C:\Program Files\Unity\Hub\Editor\2021.3.4f1\Editor\Data\DotNetSdkRoslyn\csc.dll"@C:\Users\nico\Downloads\mytestproject\Library\Bee\artifacts\1900b0aEDbg.dag\Assembly-CSharp.rsp. Remember the quotation marks are needed whenever you have a space in a path while using windows command line.
With all this info, the profilers usually have three fields to fill, the path of the executable, which will be just the path to dotnet.exe, then the arguments, where you will need to put [ROSLYN DLL] @[RSP PATH] (in my case "C:\Program Files\Unity\Hub\Editor\2021.3.4f1\Editor\Data\DotNetSdkRoslyn\csc.dll"@C:\Users\nico\Downloads\mytestproject\Library\Bee\artifacts\1900b0aEDbg.dag\Assembly-CSharp.rsp) and the working directory, which would be your project folder.
Once you capture the profiling session, you can look for source gen function calls like the ones seen in the following screenshot from dottrace
if you need any further help dont hesitate to reply here 😄
Thank you Nico for the in depth answer! I'll try it out
Just wanted to mention it works great 👍