soyuka / pidusage

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

CPU usage is always 0 #76

Closed zhouhuirun2015 closed 6 years ago

zhouhuirun2015 commented 6 years ago

image

zhouhuirun2015 commented 6 years ago

windows server 2016 x64 standard with GUI E5-2630v4 16GB

soyuka commented 6 years ago

Can you try to execute:

wmic PROCESS where ProcessId=YOUR_PID get CreationDate,KernelModeTime,ParentProcessId,ProcessId,UserModeTime,WorkingSetSize
zhouhuirun2015 commented 6 years ago

The result is: C:\Windows\system32>wmic PROCESS where ProcessId=5896 get CreationDate,KernelModeTime,ParentProcessId,ProcessId,UserModeTime,WorkingSetSize CreationDate KernelModeTime ParentProcessId ProcessId UserModeTime WorkingSetSize 20180714110222.629168+480 5375468750 5060 5896 25893281250 59334656

I use win32 exe which I compiled to get child process cpu usage, but it seems that child_process exec function return wrong pid.If I exec the win32 exe in CMD, it return the right result.

Here is the win32 exe code:

CpuUsage.txt

soyuka commented 6 years ago

The result looks correct to me, maybe try to call the usage a couple of times, the measure should settle with time. I like your C++ code though, maybe it's faster then wmic. If we could make this as a node binding for windows it'd be awesome.

zhouhuirun2015 commented 6 years ago

I call the cpuUsage every 10 secs, it always return 0.but the wmic exec result is right.So maybe the problem is child_process exec func return wrong pid?

soyuka commented 6 years ago

You could debug the where clause here. I don't have access to a windows machine (especially no 2016 server edition), therefore I'm not sure how I could be able to help you...

blamay commented 5 years ago

I'm also experiencing this issue. It used to work, or at least for some of the PIDs, but it suddenly stopped working for all of them. Currently trying get it back to semi-working again to see if I can find a repro case.

EDIT: My solution was to check for cpu == 0 and retry until it showed correctly. It seems to happen every time at the beginning after the processes are first started.

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.