dotnet / diagnostics

This repository contains the source code for various .NET Core runtime diagnostic tools and documents.
MIT License
1.18k stars 354 forks source link

dotnet-stack should filter out its immediate parent `dotnet` process if any #2977

Open danmoseley opened 2 years ago

danmoseley commented 2 years ago
C:\Users\dan>dotnet stack ps
 2616  dotnet           [Elevated process - cannot determine path]
 2668  dotnet           [Elevated process - cannot determine path]
 4328  dotnet           C:\Program Files (x86)\dotnet\dotnet.exe     stack ps
 2560  MicroBenchmarks  [Elevated process - cannot determine path]
hoyosjs commented 2 years ago

hmm, that's odd - we filter that out

https://github.com/dotnet/diagnostics/blob/d138bcf99369fcde2d80024dc80633e7940544be/src/Tools/Common/Commands/ProcessStatus.cs#L131-L133

What version are you using?

danmoseley commented 2 years ago

Sorry, I should have mentioned this is current 6.0 one. But the lines above seem like they should be in there - hmm

C:\temp>dotnet stack --version
6.0.320101+2aa2e938aad310fd667f926c7217b990568e2783

C:\temp>dotnet stack ps
 2616  dotnet           C:\git\performance\tools\dotnet\x86\dotnet.exe                                         =10, MinIterationCount=15, MinWarmupIterationCount=6, UnrollFactor=1, WarmupCount=-1" --benchmarkId 1306
 2668  dotnet           C:\git\performance\tools\dotnet\x86\dotnet.exe                                         no-restore --no-build -- --filter * --packages C:\git\performance\artifacts\packages --buildTimeout 1200
 4116  dotnet           C:\Program Files (x86)\dotnet\dotnet.exe                                                stack ps
 2560  MicroBenchmarks  "C:\git\performance\artifacts\bin\MicroBenchmarks\Release\net7.0\MicroBenchmarks.exe"   --filter * --packages C:\git\performance\artifacts\packages --buildTimeout 1200

and on another machine

C:\temp>taskkill /im dotnet.exe
ERROR: The process "dotnet.exe" not found.

C:\temp>dotnet stack --version
6.0.257301+27172ce4d05e8a3b0ffdefd65f073d40a1b1fe54

C:\temp>dotnet stack ps
     44696 dotnet     C:\Program Files\dotnet\dotnet.exe
danmoseley commented 2 years ago

Hmm, I verified it is using this one C:\USERS\DANMOSE.DOTNET\TOOLS.STORE\DOTNET-STACK\6.0.257301\DOTNET-STACK\6.0.257301\TOOLS\NETCOREAPP3.1\ANY\DOTNET-STACK.DLL

which per ILSPY contains that code.

danmoseley commented 2 years ago

Ah, I see the bug. It works if I do "dotnet-stack ps". If I do "dotnet stack ps" it filters out "dotnet-stack.exe" but isn't aware of its parent dotnet.exe. It needs to find that and filter it.

It needs a little pinvoking and checking the process start time as there's no managed API currently: https://github.com/dotnet/runtime/issues/24423

hoyosjs commented 2 years ago

Makes sense. When we do this we just need to make sure this is filtering just dotnet stack invocation and not any managed invocation of the native dll.