[SIGAR-106] Add cpu irq, soft_irq and steal

This commit is contained in:
Doug MacEachern 2008-05-24 15:12:06 +00:00
parent e3510e0805
commit 9a1f45cd7b
12 changed files with 118 additions and 9 deletions

View File

@ -442,6 +442,21 @@ use vars qw(%classes %cmds);
desc => 'Total system cpu io wait time', desc => 'Total system cpu io wait time',
plat => 'ALHS' plat => 'ALHS'
}, },
{
name => 'irq', type => 'Long',
desc => 'Total system cpu time servicing interrupts',
plat => 'FLH'
},
{
name => 'soft_irq', type => 'Long',
desc => 'Total system cpu time servicing softirqs',
plat => 'L'
},
{
name => 'steal', type => 'Long',
desc => 'Total system cpu involuntary wait time',
plat => 'L'
},
{ {
name => 'total', type => 'Long', name => 'total', type => 'Long',
desc => 'Total system cpu time', desc => 'Total system cpu time',
@ -474,6 +489,21 @@ use vars qw(%classes %cmds);
desc => 'Percent system cpu io wait time', desc => 'Percent system cpu io wait time',
plat => 'ALHS' plat => 'ALHS'
}, },
{
name => 'irq', type => 'Double',
desc => 'Percent system cpu time servicing interrupts',
plat => 'FLH'
},
{
name => 'soft_irq', type => 'Double',
desc => 'Percent system cpu time servicing softirqs',
plat => 'L'
},
{
name => 'steal', type => 'Double',
desc => 'Percent system cpu involuntary wait time',
plat => 'L'
},
{ {
name => 'combined', type => 'Double', name => 'combined', type => 'Double',
desc => 'Sum of User + Sys + Nice + Wait', desc => 'Sum of User + Sys + Nice + Wait',

View File

@ -23,13 +23,16 @@ package org.hyperic.sigar;
*/ */
public class CpuPerc implements java.io.Serializable { public class CpuPerc implements java.io.Serializable {
private static final long serialVersionUID = 02242007L; private static final long serialVersionUID = 05242007L;
private double user; private double user;
private double sys; private double sys;
private double nice; private double nice;
private double idle; private double idle;
private double wait; private double wait;
private double irq;
private double softIrq;
private double steal;
private double combined; private double combined;
CpuPerc() {} CpuPerc() {}
@ -74,6 +77,18 @@ public class CpuPerc implements java.io.Serializable {
return this.wait; return this.wait;
} }
public double getIrq() {
return this.irq;
}
public double getSoftIrq() {
return this.softIrq;
}
public double getSteal() {
return this.steal;
}
/** /**
* @return Sum of User + Sys + Nice + Wait * @return Sum of User + Sys + Nice + Wait
*/ */

View File

@ -20,6 +20,7 @@ package org.hyperic.sigar.cmd;
import org.hyperic.sigar.CpuPerc; import org.hyperic.sigar.CpuPerc;
import org.hyperic.sigar.Sigar; import org.hyperic.sigar.Sigar;
import org.hyperic.sigar.SigarLoader;
import org.hyperic.sigar.SigarException; import org.hyperic.sigar.SigarException;
/** /**
@ -48,6 +49,11 @@ public class CpuInfo extends SigarCommandBase {
println("Wait Time....." + CpuPerc.format(cpu.getWait())); println("Wait Time....." + CpuPerc.format(cpu.getWait()));
println("Nice Time....." + CpuPerc.format(cpu.getNice())); println("Nice Time....." + CpuPerc.format(cpu.getNice()));
println("Combined......" + CpuPerc.format(cpu.getCombined())); println("Combined......" + CpuPerc.format(cpu.getCombined()));
if (SigarLoader.IS_LINUX) {
println("Irq Time......" + CpuPerc.format(cpu.getIrq()));
println("SoftIrq Time.." + CpuPerc.format(cpu.getSoftIrq()));
println("Steal Time...." + CpuPerc.format(cpu.getSteal()));
}
println(""); println("");
} }

View File

@ -43,6 +43,15 @@ public class TestCpu extends SigarTestCase {
traceln("Wait..." + cpu.getWait()); traceln("Wait..." + cpu.getWait());
assertTrue(cpu.getWait() >= 0); assertTrue(cpu.getWait() >= 0);
traceln("Irq..." + cpu.getIrq());
assertTrue(cpu.getIrq() >= 0);
traceln("SIrq.." + cpu.getSoftIrq());
assertTrue(cpu.getSoftIrq() >= 0);
traceln("Stl..." + cpu.getSteal());
assertTrue(cpu.getSteal() >= 0);
traceln("Total.." + cpu.getTotal()); traceln("Total.." + cpu.getTotal());
assertTrue(cpu.getTotal() > 0); assertTrue(cpu.getTotal() > 0);

View File

@ -165,6 +165,9 @@ typedef struct {
nice, nice,
idle, idle,
wait, wait,
irq,
soft_irq,
steal,
total; total;
} sigar_cpu_t; } sigar_cpu_t;

View File

@ -25,6 +25,9 @@ typedef struct {
double nice; double nice;
double idle; double idle;
double wait; double wait;
double irq;
double soft_irq;
double steal;
double combined; double combined;
} sigar_cpu_perc_t; } sigar_cpu_perc_t;

View File

@ -717,6 +717,9 @@ int sigar_cpu_get(sigar_t *sigar, sigar_cpu_t *cpu)
cpu->sys = SIGAR_TICK2MSEC(cpu_data.sys); cpu->sys = SIGAR_TICK2MSEC(cpu_data.sys);
cpu->idle = SIGAR_TICK2MSEC(cpu_data.idle); cpu->idle = SIGAR_TICK2MSEC(cpu_data.idle);
cpu->wait = SIGAR_TICK2MSEC(cpu_data.wait); cpu->wait = SIGAR_TICK2MSEC(cpu_data.wait);
cpu->irq = 0; /*N/A*/
cpu->soft_irq = 0; /*N/A*/
cpu->steal = 0; /*N/A*/
cpu->total = cpu->user + cpu->sys + cpu->idle + cpu->wait; cpu->total = cpu->user + cpu->sys + cpu->idle + cpu->wait;
return SIGAR_OK; return SIGAR_OK;
} }
@ -736,6 +739,9 @@ int sigar_cpu_get(sigar_t *sigar, sigar_cpu_t *cpu)
cpu->sys = SIGAR_TICK2MSEC(data.cpu[CPU_KERNEL]); cpu->sys = SIGAR_TICK2MSEC(data.cpu[CPU_KERNEL]);
cpu->idle = SIGAR_TICK2MSEC(data.cpu[CPU_IDLE]); cpu->idle = SIGAR_TICK2MSEC(data.cpu[CPU_IDLE]);
cpu->wait = SIGAR_TICK2MSEC(data.cpu[CPU_WAIT]); cpu->wait = SIGAR_TICK2MSEC(data.cpu[CPU_WAIT]);
cpu->irq = 0; /*N/A*/
cpu->soft_irq = 0; /*N/A*/
cpu->steal = 0; /*N/A*/
cpu->total = cpu->user + cpu->sys + cpu->idle + cpu->wait; cpu->total = cpu->user + cpu->sys + cpu->idle + cpu->wait;
return SIGAR_OK; return SIGAR_OK;

View File

@ -634,6 +634,9 @@ int sigar_cpu_get(sigar_t *sigar, sigar_cpu_t *cpu)
cpu->idle = SIGAR_TICK2MSEC(cpuload.cpu_ticks[CPU_STATE_IDLE]); cpu->idle = SIGAR_TICK2MSEC(cpuload.cpu_ticks[CPU_STATE_IDLE]);
cpu->nice = SIGAR_TICK2MSEC(cpuload.cpu_ticks[CPU_STATE_NICE]); cpu->nice = SIGAR_TICK2MSEC(cpuload.cpu_ticks[CPU_STATE_NICE]);
cpu->wait = 0; /*N/A*/ cpu->wait = 0; /*N/A*/
cpu->irq = 0; /*N/A*/
cpu->soft_irq = 0; /*N/A*/
cpu->steal = 0; /*N/A*/
cpu->total = cpu->user + cpu->nice + cpu->sys + cpu->idle; cpu->total = cpu->user + cpu->nice + cpu->sys + cpu->idle;
#elif defined(__FreeBSD__) || (__OpenBSD__) || defined(__NetBSD__) #elif defined(__FreeBSD__) || (__OpenBSD__) || defined(__NetBSD__)
@ -663,10 +666,13 @@ int sigar_cpu_get(sigar_t *sigar, sigar_cpu_t *cpu)
cpu->user = SIGAR_TICK2MSEC(cp_time[CP_USER]); cpu->user = SIGAR_TICK2MSEC(cp_time[CP_USER]);
cpu->nice = SIGAR_TICK2MSEC(cp_time[CP_NICE]); cpu->nice = SIGAR_TICK2MSEC(cp_time[CP_NICE]);
cpu->sys = SIGAR_TICK2MSEC(cp_time[CP_SYS] + cp_time[CP_INTR]); cpu->sys = SIGAR_TICK2MSEC(cp_time[CP_SYS]);
cpu->idle = SIGAR_TICK2MSEC(cp_time[CP_IDLE]); cpu->idle = SIGAR_TICK2MSEC(cp_time[CP_IDLE]);
cpu->wait = 0; /*N/A*/ cpu->wait = 0; /*N/A*/
cpu->total = cpu->user + cpu->nice + cpu->sys + cpu->idle; cpu->irq = SIGAR_TICK2MSEC(cp_time[CP_INTR]);
cpu->soft_irq = 0; /*N/A*/
cpu->steal = 0; /*N/A*/
cpu->total = cpu->user + cpu->nice + cpu->sys + cpu->idle + cpu->irq;
#endif #endif
return SIGAR_OK; return SIGAR_OK;
@ -704,6 +710,9 @@ int sigar_cpu_list_get(sigar_t *sigar, sigar_cpu_list_t *cpulist)
cpu->idle = SIGAR_TICK2MSEC(cpuload[i].cpu_ticks[CPU_STATE_IDLE]); cpu->idle = SIGAR_TICK2MSEC(cpuload[i].cpu_ticks[CPU_STATE_IDLE]);
cpu->nice = SIGAR_TICK2MSEC(cpuload[i].cpu_ticks[CPU_STATE_NICE]); cpu->nice = SIGAR_TICK2MSEC(cpuload[i].cpu_ticks[CPU_STATE_NICE]);
cpu->wait = 0; /*N/A*/ cpu->wait = 0; /*N/A*/
cpu->irq = 0; /*N/A*/
cpu->soft_irq = 0; /*N/A*/
cpu->steal = 0; /*N/A*/
cpu->total = cpu->user + cpu->nice + cpu->sys + cpu->idle; cpu->total = cpu->user + cpu->nice + cpu->sys + cpu->idle;
} }

View File

@ -128,8 +128,7 @@ static void get_cpu_metrics(sigar_t *sigar,
cpu->user = SIGAR_TICK2MSEC(cpu_time[CP_USER]); cpu->user = SIGAR_TICK2MSEC(cpu_time[CP_USER]);
cpu->sys = SIGAR_TICK2MSEC(cpu_time[CP_SYS] + cpu->sys = SIGAR_TICK2MSEC(cpu_time[CP_SYS] +
cpu_time[CP_SSYS] + cpu_time[CP_SSYS]);
cpu_time[CP_INTR]);
cpu->nice = SIGAR_TICK2MSEC(cpu_time[CP_NICE]); cpu->nice = SIGAR_TICK2MSEC(cpu_time[CP_NICE]);
@ -139,8 +138,12 @@ static void get_cpu_metrics(sigar_t *sigar,
cpu_time[CP_SWAIT] + cpu_time[CP_SWAIT] +
cpu_time[CP_BLOCK]); cpu_time[CP_BLOCK]);
cpu->irq = SIGAR_TICK2MSEC(cpu_time[CP_INTR]);
cpu->soft_irq = 0; /*N/A*/
cpu->steal = 0; /*N/A*/
cpu->total = cpu->total =
cpu->user + cpu->sys + cpu->nice + cpu->idle + cpu->wait; cpu->user + cpu->sys + cpu->nice + cpu->idle + cpu->wait + cpu->irq;
} }
int sigar_cpu_get(sigar_t *sigar, sigar_cpu_t *cpu) int sigar_cpu_get(sigar_t *sigar, sigar_cpu_t *cpu)

View File

@ -411,8 +411,16 @@ static void get_cpu_metrics(sigar_t *sigar, sigar_cpu_t *cpu, char *line)
if (*ptr == ' ') { if (*ptr == ' ') {
/* 2.6+ kernels only */ /* 2.6+ kernels only */
cpu->wait += SIGAR_TICK2MSEC(sigar_strtoull(ptr)); cpu->wait += SIGAR_TICK2MSEC(sigar_strtoull(ptr));
cpu->irq += SIGAR_TICK2MSEC(sigar_strtoull(ptr));
cpu->soft_irq += SIGAR_TICK2MSEC(sigar_strtoull(ptr));
} }
cpu->total = cpu->user + cpu->nice + cpu->sys + cpu->idle + cpu->wait; if (*ptr == ' ') {
/* 2.6.11+ kernels only */
cpu->steal += SIGAR_TICK2MSEC(sigar_strtoull(ptr));
}
cpu->total =
cpu->user + cpu->nice + cpu->sys + cpu->idle +
cpu->wait + cpu->irq + cpu->soft_irq + cpu->steal;
} }
int sigar_cpu_get(sigar_t *sigar, sigar_cpu_t *cpu) int sigar_cpu_get(sigar_t *sigar, sigar_cpu_t *cpu)

View File

@ -104,6 +104,9 @@ int sigar_cpu_get(sigar_t *sigar, sigar_cpu_t *cpu)
cpu->sys = sysinfo.si_sys; cpu->sys = sysinfo.si_sys;
cpu->idle = sysinfo.si_idle; cpu->idle = sysinfo.si_idle;
cpu->wait = 0; /*N/A?*/ cpu->wait = 0; /*N/A?*/
cpu->irq = 0; /*N/A*/
cpu->soft_irq = 0; /*N/A*/
cpu->steal = 0; /*N/A*/
cpu->total = cpu->user + cpu->nice + cpu->sys + cpu->idle + cpu->wait; cpu->total = cpu->user + cpu->nice + cpu->sys + cpu->idle + cpu->wait;
return SIGAR_OK; return SIGAR_OK;

View File

@ -610,28 +610,42 @@ SIGAR_DECLARE(int) sigar_cpu_perc_calculate(sigar_cpu_t *prev,
sigar_cpu_t *curr, sigar_cpu_t *curr,
sigar_cpu_perc_t *perc) sigar_cpu_perc_t *perc)
{ {
double diff_user, diff_sys, diff_nice, diff_idle, diff_wait, diff_total; double diff_user, diff_sys, diff_nice, diff_idle;
double diff_wait, diff_irq, diff_soft_irq, diff_steal;
double diff_total;
diff_user = (sigar_int64_t)(curr->user - prev->user); diff_user = (sigar_int64_t)(curr->user - prev->user);
diff_sys = (sigar_int64_t)(curr->sys - prev->sys); diff_sys = (sigar_int64_t)(curr->sys - prev->sys);
diff_nice = (sigar_int64_t)(curr->nice - prev->nice); diff_nice = (sigar_int64_t)(curr->nice - prev->nice);
diff_idle = (sigar_int64_t)(curr->idle - prev->idle); diff_idle = (sigar_int64_t)(curr->idle - prev->idle);
diff_wait = (sigar_int64_t)(curr->wait - prev->wait); diff_wait = (sigar_int64_t)(curr->wait - prev->wait);
diff_irq = (sigar_int64_t)(curr->irq - prev->irq);
diff_soft_irq = (sigar_int64_t)(curr->soft_irq - prev->soft_irq);
diff_steal = (sigar_int64_t)(curr->steal - prev->steal);
diff_user = diff_user < 0 ? 0 : diff_user; diff_user = diff_user < 0 ? 0 : diff_user;
diff_sys = diff_sys < 0 ? 0 : diff_sys; diff_sys = diff_sys < 0 ? 0 : diff_sys;
diff_nice = diff_nice < 0 ? 0 : diff_nice; diff_nice = diff_nice < 0 ? 0 : diff_nice;
diff_idle = diff_idle < 0 ? 0 : diff_idle; diff_idle = diff_idle < 0 ? 0 : diff_idle;
diff_wait = diff_wait < 0 ? 0 : diff_wait; diff_wait = diff_wait < 0 ? 0 : diff_wait;
diff_irq = diff_irq < 0 ? 0 : diff_irq;
diff_soft_irq = diff_soft_irq < 0 ? 0 : diff_soft_irq;
diff_steal = diff_steal < 0 ? 0 : diff_steal;
diff_total = diff_total =
diff_user + diff_sys + diff_nice + diff_idle + diff_wait; diff_user + diff_sys + diff_nice + diff_idle +
diff_wait + diff_irq + diff_soft_irq +
diff_steal;
perc->user = diff_user / diff_total; perc->user = diff_user / diff_total;
perc->sys = diff_sys / diff_total; perc->sys = diff_sys / diff_total;
perc->nice = diff_nice / diff_total; perc->nice = diff_nice / diff_total;
perc->idle = diff_idle / diff_total; perc->idle = diff_idle / diff_total;
perc->wait = diff_wait / diff_total; perc->wait = diff_wait / diff_total;
perc->irq = diff_irq / diff_total;
perc->soft_irq = diff_soft_irq / diff_total;
perc->steal = diff_steal / diff_total;
perc->combined = perc->combined =
perc->user + perc->sys + perc->nice + perc->wait; perc->user + perc->sys + perc->nice + perc->wait;