0
我正在使用SIAGR API来计算CPU使用率,但得到例外时,它是使用LOAD RUNNER进行测试,其他方式也可以。使用SIGAR API来计算CPU使用率
org.hyperic.sigar.SigarFileNotFoundException: No such file or directory
at org.hyperic.sigar.Cpu.gather(Native Method)
at org.hyperic.sigar.Cpu.fetch(Cpu.java:30)
at org.hyperic.sigar.Sigar.getCpu(Sigar.java:320)
at org.hyperic.sigar.Sigar.getCpuPerc(Sigar.java:348)
下面
public static void main(String[] args)
{
try
{
Shell shell = new Shell();
shell.setPageSize(PageControl.SIZE_UNLIMITED);
Sigar sigar = shell.getSigar();
CpuPerc cpu = null;
for (int i = 0; i < 10; i++)
{
try
{
Thread.sleep(500L);
} catch (Exception e)
{
// TODO: handle exception
}
cpu = sigar.getCpuPerc();
double val = cpu.getCombined();
int cpuUsage = (int) (val * 100);
// System.out.println(CpuPerc.format(val));
System.out.println(cpuUsage);
}
}
catch (SigarException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
我的要求,请找到示例代码是收集在特定的时间间隔的CPU使用率50次..并记录平均和最高的。
请帮我解决这个问题
我觉得你误解了我的问题,或者可能是我错误地传达了它。在这里我没有写出上面的代码来加载亚军。我的产品需要定期收集CPU使用情况,而不是Loadrunner.Here我的产品使用负载运行器进行了一些巨大的load.Here后台线程将收集CPU使用情况。当有负载时,我正在超出例外。 –
是的,这确实是澄清。谢谢 –