VirtualBox

Changeset 11778 in vbox


Ignore:
Timestamp:
Aug 28, 2008 5:53:49 PM (16 years ago)
Author:
vboxsync
Message:

PerfAPI: Darwin VM metrics collection re-done to use libproc

Location:
trunk/src/VBox/Main
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/Makefile.kmk

    r11772 r11778  
    275275endif
    276276
     277VBoxSVC_LDFLAGS.darwin  = -framework IOKit -framework SystemConfiguration
     278ifeq ($(KBUILD_TYPE),debug)
     279VBoxSVC_LDFLAGS.linux  += -rdynamic # for backtrace_symbols()
     280endif
     281
    277282ifdef VBOX_WITH_RESOURCE_USAGE_API
    278283VBoxSVC_SOURCES  += \
     
    284289VBoxSVC_SOURCES.solaris += solaris/PerformanceSolaris.cpp
    285290VBoxSVC_SOURCES.win     +=     win/PerformanceWin.cpp
     291VBoxSVC_LDFLAGS.darwin  += -lproc
    286292VBoxSVC_LDFLAGS.solaris += -lkstat
    287293VBoxSVC_LDFLAGS.win     += wbemuuid.lib powrprof.lib
    288 endif
    289 
    290 VBoxSVC_LDFLAGS.darwin  = -framework IOKit -framework SystemConfiguration
    291 ifeq ($(KBUILD_TYPE),debug)
    292 VBoxSVC_LDFLAGS.linux  += -rdynamic # for backtrace_symbols()
    293294endif
    294295
  • trunk/src/VBox/Main/darwin/PerformanceDarwin.cpp

    r11689 r11778  
    2727#include <mach/mach_init.h>
    2828#include <mach/mach_time.h>
    29 #include <mach/task.h>
    30 #include <mach/task_info.h>
    3129#include <mach/vm_statistics.h>
    3230#include <sys/sysctl.h>
     
    3634#include <iprt/param.h>
    3735#include "Performance.h"
     36
     37/* The following declarations are missing in 10.4.x SDK */
     38/* @todo Replace them with libproc.h and sys/proc_info.h when 10.4 is no longer supported */
     39extern "C" int proc_pidinfo(int pid, int flavor, uint64_t arg,  void *buffer, int buffersize);
     40struct proc_taskinfo {
     41        uint64_t                pti_virtual_size;   /* virtual memory size (bytes) */
     42        uint64_t                pti_resident_size;  /* resident memory size (bytes) */
     43        uint64_t                pti_total_user;         /* total time */
     44        uint64_t                pti_total_system;
     45        uint64_t                pti_threads_user;       /* existing threads only */
     46        uint64_t                pti_threads_system;
     47        int32_t                 pti_policy;             /* default policy for new threads */
     48        int32_t                 pti_faults;             /* number of page faults */
     49        int32_t                 pti_pageins;    /* number of actual pageins */
     50        int32_t                 pti_cow_faults; /* number of copy-on-write faults */
     51        int32_t                 pti_messages_sent;      /* number of messages sent */
     52        int32_t                 pti_messages_received; /* number of messages received */
     53        int32_t                 pti_syscalls_mach;  /* number of mach system calls */
     54        int32_t                 pti_syscalls_unix;  /* number of unix system calls */
     55        int32_t                 pti_csw;            /* number of context switches */
     56        int32_t                 pti_threadnum;          /* number of threads in the task */
     57        int32_t                 pti_numrunning;         /* number of running threads */
     58        int32_t                 pti_priority;           /* task priority*/
     59};
     60#define PROC_PIDTASKINFO 4
    3861
    3962namespace pm {
     
    110133}
    111134
     135static int getProcessInfo(RTPROCESS process, struct proc_taskinfo *tinfo)
     136{
     137    int nb = proc_pidinfo(process, PROC_PIDTASKINFO, 0,  tinfo, sizeof(*tinfo));
     138    if (nb <= 0)
     139    {
     140        int rc = errno;
     141        Log(("proc_pidinfo() -> %s", strerror(rc)));
     142        return RTErrConvertFromDarwin(rc);
     143    }
     144    else if (nb < sizeof(*tinfo))
     145    {
     146        Log(("proc_pidinfo() -> too few bytes %d", nb));
     147        return VERR_INTERNAL_ERROR;
     148    }
     149    return VINF_SUCCESS;
     150}
     151
    112152int CollectorDarwin::getRawProcessCpuLoad(RTPROCESS process, uint64_t *user, uint64_t *kernel, uint64_t *total)
    113153{
    114     kern_return_t krc;
    115     task_absolutetime_info_data_t tinfo;
    116     mach_port_name_t vmTask;
    117     mach_msg_type_number_t count;
     154    struct proc_taskinfo tinfo;
    118155
    119     krc = task_for_pid(task_self_trap(), process, &vmTask);
    120     if (krc != KERN_SUCCESS)
     156    int rc = getProcessInfo(process, &tinfo);
     157    if (RT_SUCCESS(rc))
    121158    {
    122         Log(("task_for_pid() -> %s", mach_error_string(krc)));
    123         return RTErrConvertFromDarwinKern(krc);
     159        *user = tinfo.pti_total_user;
     160        *kernel = tinfo.pti_total_system;
     161        *total = mach_absolute_time();
    124162    }
    125 
    126     count = TASK_ABSOLUTETIME_INFO_COUNT;
    127     krc = task_info(vmTask, TASK_ABSOLUTETIME_INFO, (task_info_t)&tinfo, &count);
    128     if (krc != KERN_SUCCESS) {
    129         Log(("task_info() -> %s", mach_error_string(krc)));
    130         return RTErrConvertFromDarwinKern(krc);
    131     }
    132 
    133     *user = tinfo.total_user;
    134     *kernel = tinfo.total_system;
    135     *total = mach_absolute_time();
    136     return VINF_SUCCESS;
     163    return rc;
    137164}
    138165
    139166int CollectorDarwin::getProcessMemoryUsage(RTPROCESS process, ULONG *used)
    140167{
    141     kern_return_t krc;
    142     task_basic_info_64_data_t tinfo;
    143     mach_port_name_t vmTask;
    144     mach_msg_type_number_t count;
     168    struct proc_taskinfo tinfo;
    145169
    146     krc = task_for_pid(task_self_trap(), process, &vmTask);
    147     if (krc != KERN_SUCCESS)
     170    int rc = getProcessInfo(process, &tinfo);
     171    if (RT_SUCCESS(rc))
    148172    {
    149         Log(("task_for_pid() -> %s", mach_error_string(krc)));
    150         return RTErrConvertFromDarwinKern(krc);
     173        *used = tinfo.pti_resident_size / 1024;
    151174    }
    152     count = TASK_BASIC_INFO_64_COUNT;
    153     krc = task_info(task_self_trap(), TASK_BASIC_INFO_64, (task_info_t)&tinfo, &count);
    154     if (krc != KERN_SUCCESS) {
    155         Log(("host_statistics() -> %s", mach_error_string(krc)));
    156         return RTErrConvertFromDarwinKern(krc);
    157     }
    158 
    159     *used = tinfo.resident_size / 1024;
    160     return VINF_SUCCESS;
     175    return rc;
    161176}
    162177
  • trunk/src/VBox/Main/testcase/Makefile.kmk

    r11760 r11778  
    118118        ../Performance.cpp
    119119tstCollector_INCS     = ../include
     120tstCollector_LDFLAGS.darwin  += -lproc
    120121tstCollector_LDFLAGS.solaris += -lkstat
    121 tstCollector_LDFLAGS.win += wbemuuid.lib powrprof.lib
     122tstCollector_LDFLAGS.win     += wbemuuid.lib powrprof.lib
    122123
    123124
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette