-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Breaking change: use state code rather than "description" #173
Conversation
For process.Status(), linux is the only platform where it's possible to get state descriptions. This is specific to the linux /proc/<pid>/status file. I think it would be better to get the more platform-neutral state codes, which are also present on FreeBSD, OpenBSD, darwin, etc. The state codes are also better documented on "man proc" and "man ps"
Hmm. State codes are not common between platforms, I think. For example, Darwin also has I had gave up to standardize it, but if you know some pointers to the differences between platform. I will implement it. |
as far as I can tell, D == D on freebsd and linux, I think you can consider those both "blocked" or "uninterruptible sleep". Darwin having U is a little odd, but it's also the only platform that uses U for any state, so it's easy to deal with |
you can see how collectd classifies them in Linux here: https://github.com/collectd/collectd/blob/master/src/processes.c#L1871 keep scrolling down to see how it maps other states to "blocked" |
I check 3 platform
So, one approach is standardize as follows,
FreeBSD and Darwin should have a convert code. How do you think? |
I don't think that it needs to be normalized, why combine Idle for darwin and BSD? I think the gopsutil user can switch on the operating system to parse the state codes themselves. The purpose behind the PR is to give the user access to the state codes, which are easier to parse than the somewhat arbitrary (and subject to change) descriptions available in /proc/pid/status |
for example, in telegraf, I'd prefer to do this: case 'W':
switch runtime.GOOS{
...
}
case 'U', 'D':
// Also known as uninterruptible sleep or disk sleep
blocked++
case 'Z':
zombie++
case 'T':
trace++
case 'R':
running++
case 'S':
sleeping++
case 'I':
idle++ |
lesseee, If you prefer platform-dependent , why not like this?
|
But there is a problem when there are additional parts to the states, for example, sometimes there are extra characters on the state: R+ So this is actually the switch statement (we need to grab the 1st character): switch status[0] {
case 'W':
switch runtime.GOOS{
...
}
case 'U', 'D':
// Also known as uninterruptible sleep or disk sleep
blocked++
case 'Z':
zombie++
case 'T':
trace++
case 'R':
running++
case 'S':
sleeping++
case 'I':
idle++
} So we would need to grab the first character in some cases (when we have a state code), and in some cases not grab the first character (when we have a state description) |
OK, I agree to change the Linux status code. But as you write, it is a breaking change and it can not detect by compiling. I opened #174, plan to introduce v2. I want to merge this PR at that time. How do you think? |
that sounds good to me, thanks @shirou 😄 |
This PR is included on v2. See #174. Thank you for your contirbution! |
For process.Status(), linux is the only platform where it's possible to
get state descriptions. This is specific to the linux /proc/pid/status
file.
I think it would be better to get the more platform-neutral state codes,
which are also present on FreeBSD, OpenBSD, darwin, etc.
The state codes are also better documented on "man proc" and "man ps"