From: JeanDagenais2 <sig...@hy...> - 2010-11-17 07:16:55
|
Hello, I modified your code slighlty to get these results: ProcCpu procCPU = sigar.getProcCpu(pid); -> Main Change ProcState procState = sigar.getProcState(pid); ProcTime procTime = sigar.getProcTime(pid); String processName = procState.getName(); String cpuPercentage = CpuPerc.format(procCPU.getPercent()); totalProcessTime = procTime.getTotal(); System.out.println(pid + "\t\t" + processName + "\t\t" + cpuPercentage + "\t\t" + totalProcessTime); This is run with a 1000 ms interval between sampling (which is quite short based on the accuracy of windows, e.g. ~ 15 ms for sampling CPU busy). 6148 javaw 0.0% 351240 6148 javaw 43.3% 351694 6148 javaw 0.0% 351694 6148 javaw 1.5% 351709 6148 javaw 0.0% 351709 6148 javaw 1.6% 351725 6148 javaw 0.0% 351725 6148 javaw 4.7% 351772 6148 javaw 0.0% 351772 6148 javaw 0.0% 351772 6148 javaw 0.0% 351772 This is on Windows XP, and you need to remember that Windows has an accuracy of about 15 milliseconds for this counter, which mean it's not too accurate at low utilization. It is better on Linux and Solaris. I added the procTime.getTotal() which gives you an idea of what is really measured and then interpreted as %. Hope this help! Jean |