1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-03-27 06:50:23 +03:00

bhyve: report cpuTime in bhyveDomainGetInfo

Add a helper function virBhyveGetDomainTotalCpuStats() to
obtain process CPU time using kvm (kernel memory interface)
and use it to set cpuTime field of the virDomainInfo struct in
bhyveDomainGetInfo().
This commit is contained in:
Roman Bogorodskiy 2014-04-21 14:59:58 +04:00
parent 6d105946a9
commit 0541727cf7
4 changed files with 57 additions and 0 deletions

@ -2684,6 +2684,13 @@ AC_CHECK_DECLS([cpuset_getaffinity],
#include <sys/cpuset.h>
])
# Check for BSD kvm (kernel memory interface)
if test $with_freebsd = yes; then
AC_CHECK_LIB([kvm], [kvm_getprocs], [],
[AC_MSG_ERROR([BSD kernel memory interface library is required to build on FreeBSD])]
)
fi
# Check if we need to look for ifconfig
if test "$want_ifconfig" = "yes"; then
AC_PATH_PROG([IFCONFIG_PATH], [ifconfig])

@ -269,6 +269,13 @@ bhyveDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info)
if (virDomainGetInfoEnsureACL(domain->conn, vm->def) < 0)
goto cleanup;
if (virDomainObjIsActive(vm)) {
if (virBhyveGetDomainTotalCpuStats(vm, &(info->cpuTime)) < 0)
goto cleanup;
} else {
info->cpuTime = 0;
}
info->state = virDomainObjGetState(vm, NULL);
info->maxMem = vm->def->mem.max_balloon;
info->nrVirtCpu = vm->def->vcpus;

@ -22,7 +22,11 @@
#include <config.h>
#include <fcntl.h>
#include <kvm.h>
#include <sys/param.h>
#include <sys/types.h>
#include <sys/sysctl.h>
#include <sys/user.h>
#include <sys/ioctl.h>
#include <net/if.h>
#include <net/if_tap.h>
@ -248,3 +252,39 @@ virBhyveProcessStop(bhyveConnPtr driver,
virCommandFree(cmd);
return ret;
}
int
virBhyveGetDomainTotalCpuStats(virDomainObjPtr vm,
unsigned long long *cpustats)
{
struct kinfo_proc *kp;
kvm_t *kd;
char errbuf[_POSIX2_LINE_MAX];
int nprocs;
int ret = -1;
if ((kd = kvm_openfiles(NULL, NULL, NULL, O_RDONLY, errbuf)) == NULL) {
virReportError(VIR_ERR_SYSTEM_ERROR,
_("Unable to get kvm descriptor: %s"),
errbuf);
return -1;
}
kp = kvm_getprocs(kd, KERN_PROC_PID, vm->pid, &nprocs);
if (kp == NULL || nprocs != 1) {
virReportError(VIR_ERR_SYSTEM_ERROR,
_("Unable to obtain information about pid: %d"),
(int)vm->pid);
goto cleanup;
}
*cpustats = kp->ki_runtime * 1000ull;
ret = 0;
cleanup:
kvm_close(kd);
return ret;
}

@ -34,6 +34,9 @@ int virBhyveProcessStop(bhyveConnPtr driver,
virDomainObjPtr vm,
virDomainShutoffReason reason);
int virBhyveGetDomainTotalCpuStats(virDomainObjPtr vm,
unsigned long long *cpustats);
typedef enum {
VIR_BHYVE_PROCESS_START_AUTODESTROY = 1 << 0,
} bhyveProcessStartFlags;