New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add and use Environment.ProcessId #38908
Conversation
Note regarding the This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, to please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change. |
I couldn't figure out the best area label to add to this PR. If you have write-permissions please help me learn by adding exactly one area label. |
src/libraries/Common/src/System/Diagnostics/TraceListenerHelpers.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Diagnostics.TraceSource/src/System.Diagnostics.TraceSource.csproj
Outdated
Show resolved
Hide resolved
src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessManager.Win32.cs
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@@ -10,24 +10,6 @@ | |||
<Compile Include="System\Diagnostics\DelimitedListTraceListener.cs" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does not need to have OS specific build anymore.
<TargetFrameworks>$(NetCoreAppCurrent)<TargetFrameworks>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I tried that, but I got errors that I wasn't sure what to do with, and so decided to leave that for a follow-up, e.g.
C:\Users\stoub\.nuget\packages\microsoft.dotnet.build.tasks.targetframework.sdk\5.0.0-beta.20316.1\build\Microsoft.DotNet.Build.Tasks.TargetFramework.Sdk.targets(74,5): error : Not able to find a compatible supported target framework for net5.0 in Project System.Diagnostics.Process.csproj. The Supported Configurations are net5.0-Windows_NT, net5.0-FreeBSD, net5.0-Linux, net5.0-OSX, net5.0-iOS, net5.0-tvOS [D:\repos\runtime\src\libraries\System.Diagnostics.TraceSource\src\System.Diagnostics.TraceSource.csproj]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you remove the reference to System.Diagnostics.Process? Is its still used anywhere? IIRC there was a case for Process.GetCurrentProcess().ProcessName which was unused in some cases. Perhaps we can use a different pattern to obtain the name of the process, like AppDomain.CurrentDomain.FriendlyName 🤮 or add Environment.ProcessName.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ericstj, I can remove the Process reference, but then the error just becomes:
C:\Users\stoub\.nuget\packages\microsoft.dotnet.build.tasks.targetframework.sdk\5.0.0-beta.20316.1\build\Microsoft.DotNet.Build.Tasks.TargetFramework.Sdk.targets(74,5): error : Not able to find a compatible supported target framework for net5.0 in Project System.IO.FileSystem.csproj. The Supported Configurations are net5.0-Windows_NT, net5.0-Unix [D:\repos\runtime\src\libraries\System.Diagnostics.TraceSource\src\System.Diagnostics.TraceSource.csproj]
for FileSystem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks to me like you're talking about a different project? This comment is on TextWriterTraceListener and the error mentions System.Diagnostics.TraceSource.csproj
and I don't see any project references in TextWriterTraceListener.
In the case of TraceSource you might be able to get away with changing from a ProjectReference
to a simple Reference
. ProjectReferences are only needed when you need to use a type that lives in System.Private.CoreLib at runtime (to avoid the duplicate type error from compiler).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks to me like you're talking about a different project? This comment is on TextWriterTraceListener and the error mentions System.Diagnostics.TraceSource.csproj and I don't see any project references in TextWriterTraceListener.
I was talking about TraceSource (the below "Same here" comment was applying to TraceSource as well, so I've just been using that as a guinea pig). For TextWriterTraceListener, it does still use Process, to get the current process name.
In the case of TraceSource you might be able to get away with changing from a ProjectReference to a simple Reference.
The purpose of this PR is to add Environment.ProcessId. I'm not going to hold it up right now fiddling with the csproj. Please open an issue about consolidating the target frameworks if there isn't already one tracking that. Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, that's fine by me. /cc @Anipik
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can follow up with this and see where we can leverage this api and remove cross targeting
src/libraries/System.Diagnostics.TraceSource/src/System.Diagnostics.TraceSource.csproj
Show resolved
Hide resolved
66e5bcb
to
4f4ddc4
Compare
src/libraries/System.Runtime.Extensions/tests/System/EnvironmentTests.cs
Show resolved
Hide resolved
src/libraries/System.Runtime.Extensions/tests/System/EnvironmentTests.cs
Show resolved
Hide resolved
343573f
to
fe0a403
Compare
fe0a403
to
7d147e7
Compare
Could |
It could. I'm not sure it's worth it. @jkotas, do you have an opinion? |
I do not have an opinion. This optimization is not free - it adds static footprint. Is it a good tradeoff in this case? Unclear. |
Right, thanks. That's why I went with the simple solution of just doing lazy initialization. If we get enough evidence to suggest this is so critical path that it's worth it, we can change it in the future. As of now, though, we're making something that was super slow way faster already. |
Fixes #38388
dotnet/roslyn-analyzers#3838 provides a Process.GetCurrentProcess().Id => Environment.ProcessId analyzer and fixer
cc: @jkotas, @ericstj, @jeffhandley