pidusage icon indicating copy to clipboard operation
pidusage copied to clipboard

Add support for threads count

Open simonepri opened this issue 6 years ago • 16 comments

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?

simonepri avatar Mar 30 '18 15:03 simonepri

wmic has the ThreadCount column so it's quite easy to add it on Windows.

simonepri avatar Mar 30 '18 15:03 simonepri

ps on AIX has the thcount column. https://superuser.com/a/49411/470946

simonepri avatar Mar 30 '18 15:03 simonepri

proc files have the Thread value http://ask.xmodulo.com/number-of-threads-process-linux.html

simonepri avatar Mar 30 '18 15:03 simonepri

Nice research! I agree this could be a nice addition!

soyuka avatar Mar 30 '18 15:03 soyuka

Can't find a nice way to do it with ps, though.

simonepri avatar Mar 30 '18 15:03 simonepri

thcount seems available on linux

soyuka avatar Mar 30 '18 15:03 soyuka

Cool so the problem is only macOS :(

simonepri avatar Mar 30 '18 15:03 simonepri

Yes :| https://stackoverflow.com/questions/28047653/osx-how-can-i-see-the-tid-of-all-threads-from-my-process

soyuka avatar Mar 30 '18 15:03 soyuka

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.

soyuka avatar Jun 04 '18 08:06 soyuka

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.

simonepri avatar Jun 04 '18 09:06 simonepri

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!

soyuka avatar Jun 04 '18 10:06 soyuka

Just for reference, thats how multi threaded process are reported by ps. http://g.recordit.co/6VB6o4h2xf.gif

simonepri avatar Jun 12 '18 19:06 simonepri

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) ?

soyuka avatar Jun 13 '18 07:06 soyuka

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.

simonepri avatar Jun 13 '18 09:06 simonepri

Not sure that they actually use the number of threads :|. We won't be able to make this work without bindings.

soyuka avatar Jun 13 '18 12:06 soyuka

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.

hiyelbaz avatar Dec 05 '22 13:12 hiyelbaz