process.GetInfoForPid collects the total thread count#100
Merged
AndersonQ merged 1 commit intoelastic:mainfrom Oct 2, 2023
Merged
Conversation
2730298 to
5a45e5e
Compare
2 tasks
rdner
reviewed
Oct 2, 2023
| // isWhitelistedEnvVar returns true if the given variable name is a match for | ||
| // the whitelist. If the whitelist is empty it returns false. | ||
| func (procStats Stats) isWhitelistedEnvVar(varName string) bool { | ||
| func (procStats *Stats) isWhitelistedEnvVar(varName string) bool { |
Member
There was a problem hiding this comment.
The reason for this change is not obvious to me, this function don't seem to change anything in procStats.
Member
Author
There was a problem hiding this comment.
I just made it consistent with the other receivers
Member
There was a problem hiding this comment.
up to you, for me it's not about consistency, it's about semantics, if I have a pointer receiver in a function that means this function changes the state. Otherwise, you indicate that the function is read-only.
5a45e5e to
3068747
Compare
* On linux: - it extends the information parsed from /proc/[PID]/stat to get the total thread count - unit tests added, they mock /proc/[PID]/stat * On darwin: - it uses the syscall proc_pidinfo - unit test only validates GetInfoForPid does not return an error and the total thread count ins't zero * On windows: - it uses the Process Snapshotting APIs: https://learn.microsoft.com/en-us/previous-versions/windows/desktop/proc_snap/overview-of-process-snapshotting - unit test only validates GetInfoForPid does not return an error and the total thread count ins't * Add a unit test using a C++ program which runs exactly 42 threads so we can assert the data read by process.GetInfoForPid On windows the and newer the process start with more threads than the program requests to parallel load needed tabels/dll or some windows specific things. Therefore the test on windows accepts 42 or 45 for the number of threads allocated to the process. See the following for details https://stackoverflow.com/questions/42789199/why-there-are-three-unexpected-worker-threads-when-a-win32-console-application-s/42789684#42789684
3068747 to
2c80c04
Compare
rdner
approved these changes
Oct 2, 2023
Member
rdner
left a comment
There was a problem hiding this comment.
LGTM, I'll leave decision on the pointer receiver to you, @AndersonQ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Collect the total thread count, num_threads, as part of the information collected by
process.GetInfoForPidWhy is it important?
To enable metricbeat to collect the total thread count per process as requested by elastic/beats#34461.
Checklist
CHANGELOG.mdRelated issues