-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Conversation
I think I will have to modify the tests. Currently, since values are not being returned, they have been set to return 0. |
This PR fixes an issue which exists in 2.1,2.2 and as well as 3.0. Is there something specific I need to do to make sure this fix makes its way for all supported versions ? |
@krwq as area owner could you please help get this reviewed and merged? |
Re : versions, this will not be back ported to shipped versions without clear customer need: we minimize churn in shipped releases . It might be a candidate for 3.1 if completed soon though. |
I see. Currently, I find this required by most monitoring tools which, at the moment, on non-windows platforms are reporting memory usage as 0. |
@shubhamranjan which monitoring tools? Is there a way to estimate their usage? How did these tools work before? |
Newrelic is one of them. I am not sure about how many dotnet core customers use them. I have tested since 2.x versions of dotnet core and it never worked on non-windows platforms. |
Ah, that Newrelic documentation is a good source. Thank you. 2.1 is LTS so we are trying to minimise churn in it. 2.2 is going out of support soon because 3.0 shipped. 3.1 will ship soon: perhaps we can get this into there in the first instance, and see whether there is more interest in making the case for churn in 2.1. |
@danmosemsft This is an issue for Azure Monitor/Application Insights as well. The memory is shown as 0 in Linux in Application Insights Live Metrics feature. It'd be good to get this fixed and ideally ported to 2.1/2.2 as well. https://github.com/microsoft/ApplicationInsights-dotnet-server/issues/1299 |
@krwq could you please review so we can get this in master? we should keep it open to consider backport to 3.1. |
@janvorli any concerns about consuming these values, and the mappings being made here? I know we've had various issues using the "correct" memory values on Linux in some cases. |
return Interop.procfs.TryReadStatFile(pid, out stat, reusableReader) ? | ||
CreateProcessInfo(ref stat, reusableReader) : | ||
null; | ||
return readStatFile || readStatusFile ? CreateProcessInfo(ref stat, ref status, reusableReader) : null; |
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.
readStatFile || readStatusFile
I don't understand this. How do we create the process info if we don't have a valid stat
? We can do so without a valid status
, but stat
appears necessary, no? (e.g. for the pid, for the process name, etc.)
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.
Pid
is an input parameter, we already have that, so that's how we access /proc/[pid]/stat
. Now what if reading /stat
fails and /status
doesn't ? You want to fail it as well ?
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.
That's not how it's populated:
corefx/src/System.Diagnostics.Process/src/System/Diagnostics/ProcessManager.Linux.cs
Line 129 in d391103
int pid = procFsStat.pid; |
Note that
pid
currently isn't passed into CreateProcessInfo.
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.
Now what if reading /stat fails and /status doesn't ? You want to fail it as well ?
Yup
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.
That's not how it's populated:
corefx/src/System.Diagnostics.Process/src/System/Diagnostics/ProcessManager.Linux.cs
Line 129 in d391103
int pid = procFsStat.pid; Note that
pid
currently isn't passed into CreateProcessInfo.
Ah. Ok when you pass it forward, you read from the object itself.
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.
Done.
@stephentoub Please re-review. I will be online for a while to do any changes if necessary on urgent basis if you guys plan to take this in your next release (since the cutoff is today I believe) . |
@shubhamranjan thanks for working on this. At this point, we'll have to defer it from 3.1 I think. It may be possible to service it in later, if appropriate, we'll see. Meantime, let's carry on and get this into master. |
@danmosemsft |
2.2 and 3.0 will be out of support in not too long, obsoleted by 3.0 and 3.1 respectively. 2.1 is unlikely. That release has a very high bar for changes now. |
#endif | ||
} | ||
|
||
ReadOnlySpan<char> value = default; |
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.
Nit: this local is unnecessary... instead of e.g.
value = statusFileContents.Slice(0, nonUnitSliceLength);
valueParsed = int.TryParse(value, out results.Pid);
it can be:
valueParsed = int.TryParse(statusFileContents.Slice(0, nonUnitSliceLength), out results.Pid);
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.
Thanks!
@danmosemsft, up to you what you want to do about porting to 3.x. |
* Fix #23449 - Read values from /proc/[pid]/status * Fix tests for new returned data from /prod/[pid]/status * Update tests of process info on OSX * Rename property ParsedStatus.pid --> ParsedStatus.Pid * 1. Avoid reallocation of delimiter array 2. Use tryParse instead of Parse to avoid exceptions * Rename static field and mark it as readonly * Change pid from /status to be read only from debug mode * Change status file read implementation using spans * Remove unecessary debug statement * Revert "Remove unecessary debug statement" This reverts commit f60b4f3. * Refactor logic using if statements with reduction in code redundancy * Improve condition arrangement to avoid reading subsequent files if process name doesn't match * Avoid failure of process info creation in case of fail read from one of many files. * Refactor Interop.ProcFsStat for better understanding * Change process creation logic to fail on read /stat * Change logic for unit and non unit values in file
* Fix #23449 - Read values from /proc/[pid]/status * Fix tests for new returned data from /prod/[pid]/status * Update tests of process info on OSX * Rename property ParsedStatus.pid --> ParsedStatus.Pid * 1. Avoid reallocation of delimiter array 2. Use tryParse instead of Parse to avoid exceptions * Rename static field and mark it as readonly * Change pid from /status to be read only from debug mode * Change status file read implementation using spans * Remove unecessary debug statement * Revert "Remove unecessary debug statement" This reverts commit f60b4f3. * Refactor logic using if statements with reduction in code redundancy * Improve condition arrangement to avoid reading subsequent files if process name doesn't match * Avoid failure of process info creation in case of fail read from one of many files. * Refactor Interop.ProcFsStat for better understanding * Change process creation logic to fail on read /stat * Change logic for unit and non unit values in file
return true; | ||
} | ||
} | ||
catch (IOException) |
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.
when reading /proc/<pid>/maps
we also catch UnauthorizedAccessException
. should we do that here?
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.
In case you want a specific behaviour for UnauthorizedAccessException
, we can add one.
* Fix #23449 - Read values from /proc/[pid]/status * Fix tests for new returned data from /prod/[pid]/status * Update tests of process info on OSX * Rename property ParsedStatus.pid --> ParsedStatus.Pid * 1. Avoid reallocation of delimiter array 2. Use tryParse instead of Parse to avoid exceptions * Rename static field and mark it as readonly * Change pid from /status to be read only from debug mode * Change status file read implementation using spans * Remove unecessary debug statement * Revert "Remove unecessary debug statement" This reverts commit f60b4f3. * Refactor logic using if statements with reduction in code redundancy * Improve condition arrangement to avoid reading subsequent files if process name doesn't match * Avoid failure of process info creation in case of fail read from one of many files. * Refactor Interop.ProcFsStat for better understanding * Change process creation logic to fail on read /stat * Change logic for unit and non unit values in file
@danmosemsft What version of .NET Core will this be part of ? 3.1 and higher only? Any scope of porting to 2.1/2.2 ? |
@cijothomas it will be in 3.1 only. That is expected to be released next month. We don't plan to back port. 3.1 should be a suitable upgrade for most people, as it is expected to become a long term support release. |
@cijothomas as you probably noticed, 3.1 is now released. Please let us know (in a new issue) if this does not work correctly for you. |
@danmosemsft Yes! I validated this works and unblocks a key customer scenario for application insights customers. |
Yay! Thanks @cijothomas for circling back. That makes it worth the rush to get this in. @shubhamranjan you pointed to New Relic. Do you have a contact there who can update their documentation? |
It seems to be working differently than on Windows. The point of this assertion in my program is that I really need Linux and Windows machines are identical and both have 32 GB RAM. |
@usr-sse2 this PR is merged, so if you have an issue I suggest to open one in dotnet/runtime and link here if relevant. |
* Fix dotnet/corefx#23449 - Read values from /proc/[pid]/status * Fix tests for new returned data from /prod/[pid]/status * Update tests of process info on OSX * Rename property ParsedStatus.pid --> ParsedStatus.Pid * 1. Avoid reallocation of delimiter array 2. Use tryParse instead of Parse to avoid exceptions * Rename static field and mark it as readonly * Change pid from /status to be read only from debug mode * Change status file read implementation using spans * Remove unecessary debug statement * Revert "Remove unecessary debug statement" This reverts commit dotnet/corefx@f60b4f3. * Refactor logic using if statements with reduction in code redundancy * Improve condition arrangement to avoid reading subsequent files if process name doesn't match * Avoid failure of process info creation in case of fail read from one of many files. * Refactor Interop.ProcFsStat for better understanding * Change process creation logic to fail on read /stat * Change logic for unit and non unit values in file Commit migrated from dotnet/corefx@8086f36
Add support for:
Improve:
Fixes #23449
Fixes #36086
UPDATE: Fixes/Additions/ Supports have only been added on Linux. OSX is still unsupported.