pidusage
pidusage copied to clipboard
Add support for threads count
Example:
❯ ps M -p 2100
USER PID TT %CPU STAT PRI STIME UTIME COMMAND
simonepri 2100 ?? 1.9 R 47T 0:01.72 0:18.31 /Applications/Utilities/Terminal.app/Contents/MacOS/Terminal
2100 0.0 S 20T 0:00.00 0:00.00
2100 0.0 S 31T 0:00.00 0:00.00
2100 0.0 S 31T 0:00.54 0:00.33
2100 0.0 S 47T 0:00.92 0:00.56
2100 0.1 S 61T 0:00.00 0:00.03
2100 0.1 S 47T 0:00.00 0:00.02
2100 0.0 S 61T 0:00.00 0:00.01
2100 0.1 S 47T 0:00.00 0:00.01
To count them:
❯ ps M -p 2100 | wc -l
10
@soyuka any idea on how can we support this?
wmic has the ThreadCount
column so it's quite easy to add it on Windows.
ps on AIX has the thcount
column.
https://superuser.com/a/49411/470946
proc files have the Thread
value
http://ask.xmodulo.com/number-of-threads-process-linux.html
Nice research! I agree this could be a nice addition!
Can't find a nice way to do it with ps
, though.
thcount seems available on linux
Cool so the problem is only macOS :(
Yes :| https://stackoverflow.com/questions/28047653/osx-how-can-i-see-the-tid-of-all-threads-from-my-process
I guess we could introduce this and set a default number for os x while we find a way to do this properly on os x.
On macOS we need a custom ps command and a custom parsing function. I'll try to work on it as soon as my exam session ends.
Maybe we need to dig deeper into how the Activity Monitor does the thread count also.
Sure dude, there's no rush in open source software :D. Good luck with your exams!
Just for reference, thats how multi threaded process are reported by ps.
that's cool!
Could you check on os x if you have:
/proc/{pid}/tasks
(number of files, maybe faster then reading status) or /proc/{pid}/status
(search the file for Threads
) ?
On macOS there's no /proc folder sadly. I'll take a look on how cpuUsage() works under the hood in node, for sure there's some particular syscall to call to obtain the same info.
Not sure that they actually use the number of threads :|. We won't be able to make this work without bindings.
Would you consider adding this feature for Linux and Windows only? Related function can return -1 on macOS which would indicate that the platform is not supported.