28 #include <mach/mach.h>
29 #include <mach/mach_time.h>
30 #include <mach-o/dyld.h>
31 #include <sys/resource.h>
32 #include <sys/sysctl.h>
37 loop->cf_state = NULL;
52 static mach_timebase_info_data_t info;
56 mach_timebase_info(&info) != KERN_SUCCESS)
59 return mach_absolute_time() * info.numer / info.denom;
65 char abspath[PATH_MAX * 2 + 1];
77 if (realpath(
exepath, abspath) != abspath)
80 abspath_size = strlen(abspath);
81 if (abspath_size == 0)
85 if (*
size > abspath_size)
96 vm_statistics_data_t info;
99 if (host_statistics(mach_host_self(), HOST_VM_INFO,
100 (host_info_t)&info, &
count) != KERN_SUCCESS) {
104 return (
uint64_t) info.free_count * sysconf(_SC_PAGESIZE);
110 int which[] = {CTL_HW, HW_MEMSIZE};
111 size_t size =
sizeof(info);
127 size_t size =
sizeof(info);
128 int which[] = {CTL_VM, VM_LOADAVG};
132 avg[0] = (double) info.ldavg[0] / info.fscale;
133 avg[1] = (
double) info.ldavg[1] / info.fscale;
134 avg[2] = (double) info.ldavg[2] / info.fscale;
139 mach_msg_type_number_t
count;
140 task_basic_info_data_t info;
143 count = TASK_BASIC_INFO_COUNT;
144 err = task_info(mach_task_self(),
152 assert(
err == KERN_SUCCESS);
153 *rss = info.resident_size;
162 size_t size =
sizeof(info);
163 static int which[] = {CTL_KERN, KERN_BOOTTIME};
175 unsigned int ticks = (
unsigned int)sysconf(_SC_CLK_TCK),
182 mach_msg_type_number_t msg_type;
183 processor_cpu_load_info_data_t *info;
186 size =
sizeof(model);
187 if (sysctlbyname(
"machdep.cpu.brand_string", &model, &
size, NULL, 0) &&
188 sysctlbyname(
"hw.model", &model, &
size, NULL, 0)) {
192 size =
sizeof(cpuspeed);
193 if (sysctlbyname(
"hw.cpufrequency", &cpuspeed, &
size, NULL, 0))
196 if (host_processor_info(mach_host_self(), PROCESSOR_CPU_LOAD_INFO, &numcpus,
197 (processor_info_array_t*)&info,
198 &msg_type) != KERN_SUCCESS) {
202 *cpu_infos =
uv__malloc(numcpus *
sizeof(**cpu_infos));
204 vm_deallocate(mach_task_self(), (vm_address_t)info, msg_type);
210 for (
i = 0;
i < numcpus;
i++) {
211 cpu_info = &(*cpu_infos)[
i];
220 cpu_info->
speed = cpuspeed/1000000;
222 vm_deallocate(mach_task_self(), (vm_address_t)info, msg_type);