PerformanceDarwin.cpp revision 88e68b19b8e610f11783a271c548281b976e706a
7b57f6ec6175ce1ee53e1ea49c24ff06f3723379vboxsync * VBox Darwin-specific Performance Classes implementation.
7b57f6ec6175ce1ee53e1ea49c24ff06f3723379vboxsync * Copyright (C) 2008 Sun Microsystems, Inc.
7b57f6ec6175ce1ee53e1ea49c24ff06f3723379vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
7b57f6ec6175ce1ee53e1ea49c24ff06f3723379vboxsync * available from http://www.virtualbox.org. This file is free software;
7b57f6ec6175ce1ee53e1ea49c24ff06f3723379vboxsync * you can redistribute it and/or modify it under the terms of the GNU
7b57f6ec6175ce1ee53e1ea49c24ff06f3723379vboxsync * General Public License (GPL) as published by the Free Software
7b57f6ec6175ce1ee53e1ea49c24ff06f3723379vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
7b57f6ec6175ce1ee53e1ea49c24ff06f3723379vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
7b57f6ec6175ce1ee53e1ea49c24ff06f3723379vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
7b57f6ec6175ce1ee53e1ea49c24ff06f3723379vboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
7b57f6ec6175ce1ee53e1ea49c24ff06f3723379vboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
7b57f6ec6175ce1ee53e1ea49c24ff06f3723379vboxsync * additional information or have any questions.
7b57f6ec6175ce1ee53e1ea49c24ff06f3723379vboxsync/* The following declarations are missing in 10.4.x SDK */
7b57f6ec6175ce1ee53e1ea49c24ff06f3723379vboxsync/* @todo Replace them with libproc.h and sys/proc_info.h when 10.4 is no longer supported */
7b57f6ec6175ce1ee53e1ea49c24ff06f3723379vboxsyncextern "C" int proc_pidinfo(int pid, int flavor, uint64_t arg, void *buffer, int buffersize);
7b57f6ec6175ce1ee53e1ea49c24ff06f3723379vboxsync uint64_t pti_virtual_size; /* virtual memory size (bytes) */
7b57f6ec6175ce1ee53e1ea49c24ff06f3723379vboxsync uint64_t pti_resident_size; /* resident memory size (bytes) */
7b57f6ec6175ce1ee53e1ea49c24ff06f3723379vboxsync uint64_t pti_threads_user; /* existing threads only */
7b57f6ec6175ce1ee53e1ea49c24ff06f3723379vboxsync int32_t pti_policy; /* default policy for new threads */
7b57f6ec6175ce1ee53e1ea49c24ff06f3723379vboxsync int32_t pti_pageins; /* number of actual pageins */
7b57f6ec6175ce1ee53e1ea49c24ff06f3723379vboxsync int32_t pti_cow_faults; /* number of copy-on-write faults */
7b57f6ec6175ce1ee53e1ea49c24ff06f3723379vboxsync int32_t pti_messages_sent; /* number of messages sent */
7b57f6ec6175ce1ee53e1ea49c24ff06f3723379vboxsync int32_t pti_messages_received; /* number of messages received */
7b57f6ec6175ce1ee53e1ea49c24ff06f3723379vboxsync int32_t pti_syscalls_mach; /* number of mach system calls */
7b57f6ec6175ce1ee53e1ea49c24ff06f3723379vboxsync int32_t pti_syscalls_unix; /* number of unix system calls */
7b57f6ec6175ce1ee53e1ea49c24ff06f3723379vboxsync int32_t pti_threadnum; /* number of threads in the task */
7b57f6ec6175ce1ee53e1ea49c24ff06f3723379vboxsync int32_t pti_numrunning; /* number of running threads */
db328d9a0c557c268222858740db4860d4f22a95vboxsync virtual int getRawHostCpuLoad(uint64_t *user, uint64_t *kernel, uint64_t *idle);
db328d9a0c557c268222858740db4860d4f22a95vboxsync virtual int getHostMemoryUsage(ULONG *total, ULONG *used, ULONG *available);
db328d9a0c557c268222858740db4860d4f22a95vboxsync virtual int getRawProcessCpuLoad(RTPROCESS process, uint64_t *user, uint64_t *kernel, uint64_t *total);
db328d9a0c557c268222858740db4860d4f22a95vboxsync virtual int getProcessMemoryUsage(RTPROCESS process, ULONG *used);
db328d9a0c557c268222858740db4860d4f22a95vboxsyncint CollectorDarwin::getRawHostCpuLoad(uint64_t *user, uint64_t *kernel, uint64_t *idle)
7b57f6ec6175ce1ee53e1ea49c24ff06f3723379vboxsync krc = host_statistics(mach_host_self(), HOST_CPU_LOAD_INFO, (host_info_t)&info, &count);
7b57f6ec6175ce1ee53e1ea49c24ff06f3723379vboxsync Log(("host_statistics() -> %s", mach_error_string(krc)));
7b57f6ec6175ce1ee53e1ea49c24ff06f3723379vboxsync *kernel = (uint64_t)info.cpu_ticks[CPU_STATE_SYSTEM];
7b57f6ec6175ce1ee53e1ea49c24ff06f3723379vboxsyncint CollectorDarwin::getHostMemoryUsage(ULONG *total, ULONG *used, ULONG *available)
7b57f6ec6175ce1ee53e1ea49c24ff06f3723379vboxsync krc = host_statistics(mach_host_self(), HOST_VM_INFO, (host_info_t)&info, &count);
7b57f6ec6175ce1ee53e1ea49c24ff06f3723379vboxsync Log(("host_statistics() -> %s", mach_error_string(krc)));
7b57f6ec6175ce1ee53e1ea49c24ff06f3723379vboxsync if (sysctl(mib, 2, &hostMemory, &size, NULL, 0) == -1) {
7b57f6ec6175ce1ee53e1ea49c24ff06f3723379vboxsyncstatic int getProcessInfo(RTPROCESS process, struct proc_taskinfo *tinfo)
7b57f6ec6175ce1ee53e1ea49c24ff06f3723379vboxsync int nb = proc_pidinfo(process, PROC_PIDTASKINFO, 0, tinfo, sizeof(*tinfo));
7b57f6ec6175ce1ee53e1ea49c24ff06f3723379vboxsyncint CollectorDarwin::getRawProcessCpuLoad(RTPROCESS process, uint64_t *user, uint64_t *kernel, uint64_t *total)