Skip to content

Instantly share code, notes, and snippets.

@EgorBo
Last active July 14, 2021 23:43
Show Gist options
  • Select an option

  • Save EgorBo/548cc5d80b92e80fe97f99246e48368c to your computer and use it in GitHub Desktop.

Select an option

Save EgorBo/548cc5d80b92e80fe97f99246e48368c to your computer and use it in GitHub Desktop.
run.ps1
$nettracePath = "C:\prj\net.nettrace"
$mibcPath = "C:\prj\my.mibc"
Remove-Item "bin" -Recurse -ErrorAction Ignore
Remove-Item "obj" -Recurse -ErrorAction Ignore
Remove-Item $nettracePath -Recurse -ErrorAction Ignore
Remove-Item $mibcPath -Recurse -ErrorAction Ignore
dotnet publish -c Release -r win-x64
$env:COMPlus_EnableEventPipe=1
$env:COMPlus_EventPipeConfig="Microsoft-Windows-DotNETRuntime:0x1F000080018:5"
$env:COMPlus_EventPipeOutputPath=$nettracePath
$env:COMPlus_ReadyToRun=0
$env:COMPlus_TieredPGO=1
$env:COMPlus_TieredCompilation=1
$env:COMPlus_TC_CallCounting=0
$env:COMPlus_TC_QuickJitForLoops=1
$env:COMPlus_JitCollect64BitCounts=1
# collect traces...
bin\Release\net6.0\win-x64\publish\ConsoleApp26.exe
# wait some time while the traces are being prepared
Start-Sleep -Seconds 5
# not sure why it's "used by another process" still so I make a copy:
Copy-Item $nettracePath -Destination "$nettracePath.nettrace"
dotnet-pgo create-mibc -t "$nettracePath.nettrace" -o $mibcPath
dotnet-pgo dump $mibcPath "$mibcPath.txt"
# reset the env vars
$env:COMPlus_EnableEventPipe=0
$env:COMPlus_EventPipeConfig=
$env:COMPlus_EventPipeOutputPath=
$env:COMPlus_ReadyToRun=1
$env:COMPlus_TieredPGO=1
$env:COMPlus_TC_CallCounting=1
Remove-Item "bin" -Recurse
Remove-Item "obj" -Recurse
dotnet publish -c Release -r win-x64 /p:PublishReadyToRun=true /p:PublishReadyToRunUseCrossgen2=true /p:PublishReadyToRunComposite=true "/p:PublishReadyToRunCrossgen2ExtraArgs=--embed-pgo-data%3b--mibc%3b$mibcPath"
# Final run
bin\Release\net6.0\win-x64\publish\ConsoleApp26.exe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment