我已经下载了 Java Sigar API ( http://support.hyperic.com/display/SIGAR/Home ),并希望使用它来获取有关正在运行的不同进程的内存使用信息。
我编写了以下测试用例来报告 eclipse.exe 的内存使用情况:
import org.hyperic.sigar.Sigar;
import org.hyperic.sigar.SigarException;
import org.hyperic.sigar.ptql.ProcessFinder;
public class SigarTest {
public static void main(String[] args) throws SigarException {
Sigar sigar = new Sigar();
ProcessFinder find = new ProcessFinder(sigar);
long pid = find.findSingleProcess("Exe.Name.ct=eclipse.exe");
System.out.println(sigar.getProcMem(pid));
}
}
执行此代码输出:
{PageFaults=3017940, Size=4125868032, Resident=608493568}
但是,查看 Windows 资源监视器,它显示了 eclipse.exe 的以下统计信息:
Commit (KB): 689,356
Working Set (KB): 594,028
Shareable (KB): 47,332
Private (KB): 546,696
请参阅以下屏幕截图:
Sigar 报告的 4.1GB 内存使用量甚至与 Resource Monitor 报告的任何内存统计数据都不接近。
为什么这些离得那么远?