Hari Pyla
2013-Apr-01 20:29 UTC
[libvirt-users] nparams in virNodeGetCPUStats and CPU utilization
Hi, I am trying to get the CPU utilization of a node and I am using virNodeGetCPUStats(...) Here is my code snippet. The error checking is omitted for brevity. /* get the number of params */ retval = virNodeGetCPUStats (conn, VIR_NODE_CPU_STATS_ALL_CPUS,\ NULL, &nparams, 0); printf ("nparams: %d\n", nparams); /* allocate space for the params */ params = (virNodeCPUStatsPtr *) malloc (sizeof (virNodeCPUStats) * nparams ); /* get the values */ retval = virNodeGetCPUStats (conn, VIR_NODE_CPU_STATS_ALL_CPUS,\ params, &nparams, 0); for ( i = 0 ; i < nparams ; i++) { printf ("params[%d].field: %s \tparams[%d].value: %llu\n", i, params[i].field, i, params[i].value); } output: nparams: 4 params[0].field: kernel params[0].value: 77930000000 params[1].field: user params[1].value: 568270000000 params[2].field: idle params[2].value: 471429230000000 params[3].field: iowait params[3].value: 67100000000 The documentation at http://libvirt.org/html/libvirt-libvirt.html on the virNodeGetCPUStats(...) API says that nparams is dynamic. Does that mean that not all params are available for a node? I was hoping that nparams would be 5 and that params[4] would contain the utilization (VIR_NODE_CPU_STATS_UTILIZATION). If the answer to the above is 'yes'. Then, I was wondering as to what would be the correct way to calculate the CPU utilization of a node?. Thanks, --Hari