-
-
Notifications
You must be signed in to change notification settings - Fork 879
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
[OSHI] Add bytesRead and bytesWritten to OSProcess #262
Conversation
Current coverage is 84.46% (diff: 100%)@@ master #262 diff @@
==========================================
Files 23 23
Lines 1047 1056 +9
Methods 0 0
Messages 0 0
Branches 189 191 +2
==========================================
+ Hits 884 892 +8
Misses 72 72
- Partials 91 92 +1
|
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.
Looks good, with the comments indicated. Are you able to do the other OS's or just Mac?
@@ -107,12 +108,18 @@ public OSProcess getProcess(int pid) { | |||
} | |||
} | |||
} | |||
long bytesRead = 0, bytesWritten = 0; | |||
RUsageInfoV2 rUsageInfoV2 = new RUsageInfoV2(); | |||
if (0 == SystemB.INSTANCE.proc_pid_rusage(pid, SystemB.RUSAGE_INFO_V2, rUsageInfoV2)) { |
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.
Should we check for OS version >= 10.9 here? What happens if this is run on an earlier version? I suspect an exception (if the method doesn't exist) or possibly it populates a smaller structure and would give memory access errors/segfault on the next two lines.
We could use a utility method to find OS X version (need to check for 12+ for #260) so might as well dual-purpose that.
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.
I added a version check.
* holds results | ||
* @returns 0 on success; or -1 on failure, with errno set to indicate the specific error. | ||
*/ | ||
int proc_pid_rusage(int pid, int flavor, Structure buffer); |
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.
Should use type RUsageInfoV2
here. Or, if preferred, RUsageInfoT
(define to extend Structure
) which the V2 class can subsequently extend.
@@ -127,6 +130,37 @@ | |||
} | |||
} | |||
|
|||
class RUsageInfoV2 extends Structure { | |||
public byte ri_uuid[] = new byte[16]; |
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.
Should be public byte[] ri_uuid =
...
Forgot to note in the code review ... you'll also need to modify the oshi-json code (and config file) to output the additional fields. |
Summary: This change adds bytesRead and bytesWritten fields to OSProcess. An implementation is provided for MacProcess which uses `proc_pid_rusage(pid, RUSAGE_INFO_V2, ...)`. Note that RUSAGE_INFO_V2 is only available on MacOSX 10.9+. Test Plan: Successfully obtained process io stats on MacOSX 10.10 and 10.11. Verified that `mvn test` succeeds.
Yeah, I'll try to make a pull request for Linux and possibly windows. |
I amended the commit and you can see the new changes, but for some reason GitHub didn't comment here that the pull request got updated and it still shows |
Test Plan: Test app that consumes io/cpu/mem resources: mem size: 401 bytes read: 42991616 bytes written: 42991616 ^C real 0m41.241s user 0m2.007s sys 0m10.478s OSHI: pid: 1619028, MEM Resident: 411 MB, MEM Size: 829 MB, CPU Real: 41.299 s, CPU User: 2.0 s, CPU Sys: 10.43 s, CPU Total: 12.43 s, IO Read: 42 MB, IO Write: 41 MB, IO Total: 83 MB,
Okay I added proc io stats for Linux too and verified it works: My test app that consumes io/cpu/mem resources:
OSHI with these two commits:
I also found out a bug in reporting RSS on Linux as the number OSHI reported were suspicious. Turns out http://man7.org/linux/man-pages/man5/proc.5.html
|
Summary: oshi/oshi#262 was merged so now we can have process disk i/o stats as well. Test Plan: checked buck-0.log: [2016-10-13 17:01:23.702][vrbos][command:839d219a-8cf7-4a6e-ad49-a0fd3e4baf89][tid:25][com.facebook.buck.util.perf.ProcessTracker] Process resource consumption: [/opt/homebrew/bin/python2, ...] ProcessResourceConsumption{memResident=29298688, memSize=2584113152, cpuReal=9270, cpuUser=3255, cpuSys=1461, cpuTotal=4716, ioBytesRead=46559232, ioBytesWritten=110592, ioTotal=46669824} Reviewed By: Coneko fbshipit-source-id: 6b9f7dc
Summary:
This change adds bytesRead and bytesWritten fields to OSProcess.
An implementation is provided for MacProcess which uses
proc_pid_rusage(pid, RUSAGE_INFO_V2, ...)
.Note that RUSAGE_INFO_V2 is only available on MacOSX 10.9+.
Test Plan:
Successfully obtained process io stats on MacOSX 10.10 and 10.11.
Verified that
mvn test
succeeds.