Skip to content
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

Add support for threads count #57

Open
simonepri opened this issue Mar 30, 2018 · 16 comments
Open

Add support for threads count #57

simonepri opened this issue Mar 30, 2018 · 16 comments

Comments

@simonepri
Copy link
Collaborator

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
Copy link
Collaborator Author

simonepri commented Mar 30, 2018

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

@simonepri
Copy link
Collaborator Author

simonepri commented Mar 30, 2018

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

@simonepri
Copy link
Collaborator Author

simonepri commented Mar 30, 2018

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

@soyuka
Copy link
Owner

soyuka commented Mar 30, 2018

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

@simonepri
Copy link
Collaborator Author

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

@soyuka
Copy link
Owner

soyuka commented Mar 30, 2018

thcount seems available on linux

@simonepri
Copy link
Collaborator Author

Cool so the problem is only macOS :(

@soyuka
Copy link
Owner

soyuka commented Mar 30, 2018

@soyuka
Copy link
Owner

soyuka commented Jun 4, 2018

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.

@simonepri
Copy link
Collaborator Author

simonepri commented Jun 4, 2018

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.

@soyuka
Copy link
Owner

soyuka commented Jun 4, 2018

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!

@simonepri
Copy link
Collaborator Author

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

@soyuka
Copy link
Owner

soyuka commented Jun 13, 2018

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

@simonepri
Copy link
Collaborator Author

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.

@soyuka
Copy link
Owner

soyuka commented Jun 13, 2018

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

@hiyelbaz
Copy link

hiyelbaz commented Dec 5, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants