soyuka / pidusage

Cross-platform process cpu % and memory usage of a PID
MIT License
512 stars 55 forks source link

My OS is ubuntu, the cpu usage still be 0 after a long time. ctime is very small, which is less than 1 ms. #87

Closed zarda closed 4 years ago

zarda commented 5 years ago

My OS is ubuntu, the cpu usage still be 0 after a long time. ctime is very small, which is less than 1 ms.

There is a thousand of scale difference between linux and mac.

Originally posted by @zarda in https://github.com/soyuka/pidusage/issues/76#issuecomment-479397955

zarda commented 5 years ago

Examples on Ubuntu:

Backend testing outcome: 11.475ms with CPU usage = 0.017ms & RAM = 59187200bytes as thread# = 64 5.7977ms with CPU usage = 0.009ms & RAM = 43515904bytes as thread# = 32 7.1625ms with CPU usage = 0.009ms & RAM = 54661120bytes as thread# = 24 5.5756ms with CPU usage = 0.007ms & RAM = 66285568bytes as thread# = 16 9.4999ms with CPU usage = 0.011ms & RAM = 52224000bytes as thread# = 12 4.9621ms with CPU usage = 0.006ms & RAM = 50405376bytes as thread# = 8 5.9829ms with CPU usage = 0.007ms & RAM = 42987520bytes as thread# = 4 5.3366ms with CPU usage = 0.005ms & RAM = 35606528bytes as thread# = 2 5.5319ms with CPU usage = 0.005ms & RAM = 35463168bytes as thread# = 1

zarda commented 5 years ago

Examples on macbook pro:

Backend testing outcome: 7.6749ms with CPU usage = 24.500ms & RAM = 29859840bytes as thread# = 64 6.7235ms with CPU usage = 19.500ms & RAM = 28987392bytes as thread# = 32 6.3843ms with CPU usage = 16.000ms & RAM = 28221440bytes as thread# = 24 6.2482ms with CPU usage = 12.500ms & RAM = 28217344bytes as thread# = 16 5.9951ms with CPU usage = 11.000ms & RAM = 27758592bytes as thread# = 12 5.8547ms with CPU usage = 9.000ms & RAM = 27713536bytes as thread# = 8 5.7934ms with CPU usage = 7.000ms & RAM = 27799552bytes as thread# = 4 5.6177ms with CPU usage = 6.500ms & RAM = 26869760bytes as thread# = 2 5.5751ms with CPU usage = 6.500ms & RAM = 26570752bytes as thread# = 1

soyuka commented 5 years ago

Hi, interesting, and I understand better with those examples, thanks for that! Would you be able to fix the computation in https://github.com/soyuka/pidusage/blob/master/lib/ps.js#L104?

zarda commented 5 years ago

Do you mean the bug is on mac os? I suppose to fix https://github.com/soyuka/pidusage/blob/74ad6b3fed9bc865896cafb12881e05043c1b171/lib/procfile.js#L89 "/ cpuInfo.clockTick".

soyuka commented 5 years ago

Oh you're right the bug fix would be better in the procfile, my bad I meant to link this one!