Skip to content
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

[close #39] Supporting different PIDs on Mac #41

Merged
merged 1 commit into from
Aug 25, 2020

Conversation

schneems
Copy link
Member

Currently, when you call GetProcessMem.new with a different pid value than the current process it calls `GetProcessMem::Darwin.resident_size this uses FFI to get data from the mach kernel about the current process.

This PR adds a test to ensure that memory results from different processes is correctly reported.

This PR addresses the different PID problem by checking if a different pid other than Process.pid is being passed in. If that's the case then we will fall back to determining memory based off of shelling out to ps.

There was a performance concern over using Process.pid but it appears to be relatively fast. It is approximately the speed of allocating 3 string object.

I would like to extend the FFI code to be able to quickly provide data about other processes, but I couldn't easilly figure out how to do it. I've asked on SO. If anyone knows the mach API and has hints on how to do this please let me know.

Currently when you call `GetProcessMem.new` with a different pid value than the current process it calls `GetProcessMem::Darwin.resident_size this uses FFI to get data from the mach kernel about the current process.

- #32
- https://stackoverflow.com/questions/18389581/memory-used-by-a-process-under-mac-os-x/23379216#23379216

This PR adds a test to ensure that memory results from different processes is correctly reported.

This PR addresses the different PID problem by checking if a different pid other than Process.pid is being passed in. If that's the case then we will fall back to determining memory based off of shelling out to `ps`.

There was a performance concern over using `Process.pid` but it appears to be relatively fast. It is approximately the speed of allocating 3 string object.
@schneems schneems force-pushed the schneems/fix-mac-pid-bug branch from b47816a to 95a1e89 Compare August 25, 2020 17:57
@schneems
Copy link
Member Author

It's taking a LOOOONG time to boot the mac tests.

They work for me locally.

@schneems schneems merged commit a29c2f2 into master Aug 25, 2020
@schneems
Copy link
Member Author

This is released in 0.2.6

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.

1 participant