[close #39] Supporting different PIDs on Mac #41
Merged
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.
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.