convert cpu times to seconds

This commit is contained in:
Doug MacEachern 2005-05-12 00:50:47 +00:00
parent 6139fc7c18
commit 11c7fb330b
1 changed files with 10 additions and 9 deletions

View File

@ -92,21 +92,22 @@ int sigar_swap_get(sigar_t *sigar, sigar_swap_t *swap)
return SIGAR_OK; return SIGAR_OK;
} }
static void get_cpu_metrics(sigar_cpu_t *cpu, int32_t *cpu_time) static void get_cpu_metrics(sigar_t *sigar,
sigar_cpu_t *cpu, int32_t *cpu_time)
{ {
int i; int i;
cpu->user = cpu_time[CP_USER]; cpu->user = SIGAR_TICK2SEC(cpu_time[CP_USER]);
cpu->sys = cpu_time[CP_SYS] + cpu_time[CP_SSYS]; cpu->sys = SIGAR_TICK2SEC(cpu_time[CP_SYS] + cpu_time[CP_SSYS]);
cpu->nice = cpu_time[CP_NICE]; cpu->nice = SIGAR_TICK2SEC(cpu_time[CP_NICE]);
cpu->idle = cpu_time[CP_IDLE]; cpu->idle = SIGAR_TICK2SEC(cpu_time[CP_IDLE]);
cpu->wait = cpu_time[CP_WAIT]; cpu->wait = SIGAR_TICK2SEC(cpu_time[CP_WAIT]);
cpu->total = 0; cpu->total = 0;
/* states above plus CP_BLOCK, CP_SWAIT, etc. (see sys/dk.h) */ /* states above plus CP_BLOCK, CP_SWAIT, etc. (see sys/dk.h) */
for (i=0; i<CPUSTATES; i++) { for (i=0; i<CPUSTATES; i++) {
cpu->total += cpu_time[i]; cpu->total += SIGAR_TICK2SEC(cpu_time[i]);
} }
} }
@ -117,7 +118,7 @@ int sigar_cpu_get(sigar_t *sigar, sigar_cpu_t *cpu)
pstat_getdynamic(&stats, sizeof(stats), 1, 0); pstat_getdynamic(&stats, sizeof(stats), 1, 0);
sigar->ncpu = stats.psd_proc_cnt; sigar->ncpu = stats.psd_proc_cnt;
get_cpu_metrics(cpu, stats.psd_cpu_time); get_cpu_metrics(sigar, cpu, stats.psd_cpu_time);
return SIGAR_OK; return SIGAR_OK;
} }
@ -144,7 +145,7 @@ int sigar_cpu_list_get(sigar_t *sigar, sigar_cpu_list_t *cpulist)
cpu = &cpulist->data[cpulist->number++]; cpu = &cpulist->data[cpulist->number++];
get_cpu_metrics(cpu, proc.psp_cpu_time); get_cpu_metrics(sigar, cpu, proc.psp_cpu_time);
} }
return SIGAR_OK; return SIGAR_OK;