Skip to content

process.GetInfoForPid collects the total thread count#100

Merged
AndersonQ merged 1 commit intoelastic:mainfrom
AndersonQ:34461-beats-collect-total-thread-count
Oct 2, 2023
Merged

process.GetInfoForPid collects the total thread count#100
AndersonQ merged 1 commit intoelastic:mainfrom
AndersonQ:34461-beats-collect-total-thread-count

Conversation

@AndersonQ
Copy link
Copy Markdown
Member

What does this PR do?

Collect the total thread count, num_threads, as part of the information collected by process.GetInfoForPid

Why is it important?

To enable metricbeat to collect the total thread count per process as requested by elastic/beats#34461.

Checklist

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • I have added tests that prove my fix is effective or that my feature works
  • I have added an entry in CHANGELOG.md

Related issues

@AndersonQ AndersonQ requested a review from a team as a code owner September 29, 2023 16:30
@AndersonQ AndersonQ self-assigned this Sep 29, 2023
@AndersonQ AndersonQ requested review from belimawr, cmacknz, leehinman and rdner and removed request for a team, leehinman and rdner September 29, 2023 16:30
@AndersonQ AndersonQ force-pushed the 34461-beats-collect-total-thread-count branch from 2730298 to 5a45e5e Compare September 29, 2023 18:51
// 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 {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason for this change is not obvious to me, this function don't seem to change anything in procStats.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just made it consistent with the other receivers

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@AndersonQ AndersonQ force-pushed the 34461-beats-collect-total-thread-count branch from 5a45e5e to 3068747 Compare October 2, 2023 15:26
* 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
@AndersonQ AndersonQ force-pushed the 34461-beats-collect-total-thread-count branch from 3068747 to 2c80c04 Compare October 2, 2023 15:35
Copy link
Copy Markdown
Member

@rdner rdner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, I'll leave decision on the pointer receiver to you, @AndersonQ

@AndersonQ AndersonQ merged commit 8630a5d into elastic:main Oct 2, 2023
@AndersonQ AndersonQ deleted the 34461-beats-collect-total-thread-count branch October 2, 2023 16:05
Copy link
Copy Markdown
Contributor

@fearful-symmetry fearful-symmetry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants