Changeset 11778 in vbox
- Timestamp:
- Aug 28, 2008 5:53:49 PM (16 years ago)
- Location:
- trunk/src/VBox/Main
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/Makefile.kmk
r11772 r11778 275 275 endif 276 276 277 VBoxSVC_LDFLAGS.darwin = -framework IOKit -framework SystemConfiguration 278 ifeq ($(KBUILD_TYPE),debug) 279 VBoxSVC_LDFLAGS.linux += -rdynamic # for backtrace_symbols() 280 endif 281 277 282 ifdef VBOX_WITH_RESOURCE_USAGE_API 278 283 VBoxSVC_SOURCES += \ … … 284 289 VBoxSVC_SOURCES.solaris += solaris/PerformanceSolaris.cpp 285 290 VBoxSVC_SOURCES.win += win/PerformanceWin.cpp 291 VBoxSVC_LDFLAGS.darwin += -lproc 286 292 VBoxSVC_LDFLAGS.solaris += -lkstat 287 293 VBoxSVC_LDFLAGS.win += wbemuuid.lib powrprof.lib 288 endif289 290 VBoxSVC_LDFLAGS.darwin = -framework IOKit -framework SystemConfiguration291 ifeq ($(KBUILD_TYPE),debug)292 VBoxSVC_LDFLAGS.linux += -rdynamic # for backtrace_symbols()293 294 endif 294 295 -
trunk/src/VBox/Main/darwin/PerformanceDarwin.cpp
r11689 r11778 27 27 #include <mach/mach_init.h> 28 28 #include <mach/mach_time.h> 29 #include <mach/task.h>30 #include <mach/task_info.h>31 29 #include <mach/vm_statistics.h> 32 30 #include <sys/sysctl.h> … … 36 34 #include <iprt/param.h> 37 35 #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 */ 39 extern "C" int proc_pidinfo(int pid, int flavor, uint64_t arg, void *buffer, int buffersize); 40 struct 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 38 61 39 62 namespace pm { … … 110 133 } 111 134 135 static 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 112 152 int CollectorDarwin::getRawProcessCpuLoad(RTPROCESS process, uint64_t *user, uint64_t *kernel, uint64_t *total) 113 153 { 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; 118 155 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)) 121 158 { 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(); 124 162 } 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; 137 164 } 138 165 139 166 int CollectorDarwin::getProcessMemoryUsage(RTPROCESS process, ULONG *used) 140 167 { 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; 145 169 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)) 148 172 { 149 Log(("task_for_pid() -> %s", mach_error_string(krc))); 150 return RTErrConvertFromDarwinKern(krc); 173 *used = tinfo.pti_resident_size / 1024; 151 174 } 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; 161 176 } 162 177 -
trunk/src/VBox/Main/testcase/Makefile.kmk
r11760 r11778 118 118 ../Performance.cpp 119 119 tstCollector_INCS = ../include 120 tstCollector_LDFLAGS.darwin += -lproc 120 121 tstCollector_LDFLAGS.solaris += -lkstat 121 tstCollector_LDFLAGS.win += wbemuuid.lib powrprof.lib122 tstCollector_LDFLAGS.win += wbemuuid.lib powrprof.lib 122 123 123 124
Note:
See TracChangeset
for help on using the changeset viewer.