vanheusden.com

callgrind & dotnet/c#

what is this about

One may want to profile a program, maybe it is unexpectedly slow.

On Linux we have callgrind, part of valgrind, for that.

how

In your .csproj-file, add the following in the PropertyGroup:


  <PropertyGroup>
    <PublishAot>true</PublishAot>
    <StripSymbols>false</StripSymbols>
  </PropertyGroup>

Then compile your program as follows:

dotnet publish -r linux-x64 -c Release
(or -c Debug).
This produces a binary that can also be used with gdb by the way.

Then set the following environment variables:

export COMPlus_EnableDiagnostics=0
export DOTNET_GCHeapHardLimit=1C0000000

export COMPlus_PerfMapEnabled=1
export COMPlus_EnableEventLog=1

Last step: invoke callgrind with your application!

valgrind --fair-sched=yes --tool=callgrind bin/Release/net9.0/linux-x64/native/your_program_name

The result can be viewed with kcachegrind.

example

Click on the image for a bigger view:




For contact info, see this page.