29 #include <mach/mach.h>
30 #include <mach/mach_time.h>
31 #include <mach-o/dyld.h>
32 #include <sys/resource.h>
33 #include <sys/sysctl.h>
62 if (KERN_SUCCESS != mach_timebase_info(&
timebase))
79 char abspath[PATH_MAX * 2 + 1];
80 char exepath[PATH_MAX + 1];
87 exepath_size =
sizeof(exepath);
88 if (_NSGetExecutablePath(exepath, &exepath_size))
91 if (realpath(exepath, abspath) != abspath)
94 abspath_size = strlen(abspath);
95 if (abspath_size == 0)
99 if (*
size > abspath_size)
100 *
size = abspath_size;
110 vm_statistics_data_t
info;
113 if (host_statistics(mach_host_self(), HOST_VM_INFO,
114 (host_info_t)&
info, &
count) != KERN_SUCCESS) {
118 return (
uint64_t)
info.free_count * sysconf(_SC_PAGESIZE);
124 int which[] = {CTL_HW, HW_MEMSIZE};
142 int which[] = {CTL_VM, VM_LOADAVG};
146 avg[0] = (double)
info.ldavg[0] /
info.fscale;
147 avg[1] = (
double)
info.ldavg[1] /
info.fscale;
148 avg[2] = (double)
info.ldavg[2] /
info.fscale;
153 mach_msg_type_number_t
count;
154 task_basic_info_data_t
info;
157 count = TASK_BASIC_INFO_COUNT;
158 err = task_info(mach_task_self(),
167 *rss =
info.resident_size;
177 static int which[] = {CTL_KERN, KERN_BOOTTIME};
183 *uptime = now -
info.tv_sec;
191 kern_return_t (*pIOMasterPort)(mach_port_t, mach_port_t*);
193 kern_return_t (*pIOServiceGetMatchingServices)(mach_port_t,
212 void* core_foundation_handle;
217 mach_port_t mach_port;
224 core_foundation_handle = dlopen(
"/System/Library/Frameworks/"
225 "CoreFoundation.framework/"
226 "Versions/A/CoreFoundation",
227 RTLD_LAZY | RTLD_LOCAL);
228 iokit_handle = dlopen(
"/System/Library/Frameworks/IOKit.framework/"
230 RTLD_LAZY | RTLD_LOCAL);
232 if (core_foundation_handle ==
NULL || iokit_handle ==
NULL)
235 #define V(handle, symbol) \
237 *(void **)(&p ## symbol) = dlsym((handle), #symbol); \
238 if (p ## symbol == NULL) \
242 V(iokit_handle, IOMasterPort);
243 V(iokit_handle, IOServiceMatching);
244 V(iokit_handle, IOServiceGetMatchingServices);
245 V(iokit_handle, IOIteratorNext);
246 V(iokit_handle, IOObjectRelease);
247 V(iokit_handle, IORegistryEntryCreateCFProperty);
248 V(core_foundation_handle, CFStringCreateWithCString);
249 V(core_foundation_handle, CFStringGetSystemEncoding);
250 V(core_foundation_handle, CFDataGetBytePtr);
251 V(core_foundation_handle, CFDataGetLength);
252 V(core_foundation_handle, CFDataGetBytes);
253 V(core_foundation_handle, CFRelease);
256 #define S(s) pCFStringCreateWithCString(NULL, (s), kCFStringEncodingUTF8)
258 kr = pIOMasterPort(MACH_PORT_NULL, &mach_port);
259 assert(kr == KERN_SUCCESS);
261 = pIOServiceMatching(
"IOPlatformDevice");
262 kr = pIOServiceGetMatchingServices(mach_port, classes_to_match, &it);
263 assert(kr == KERN_SUCCESS);
264 service = pIOIteratorNext(it);
269 while (service != 0) {
271 data = pIORegistryEntryCreateCFProperty(service,
276 const UInt8* raw = pCFDataGetBytePtr(data);
277 if (strncmp((
char*)raw,
"cpu", 3) == 0 ||
278 strncmp((
char*)raw,
"processor", 9) == 0) {
280 freq_ref = pIORegistryEntryCreateCFProperty(service,
291 pCFDataGetBytes(freq_ref,
range, (
UInt8*)&freq);
293 pCFRelease(freq_ref);
301 service = pIOIteratorNext(it);
304 pIOObjectRelease(it);
308 if (core_foundation_handle !=
NULL)
309 dlclose(core_foundation_handle);
311 if (iokit_handle !=
NULL)
312 dlclose(iokit_handle);
314 mach_port_deallocate(mach_task_self(), mach_port);
320 unsigned int ticks = (
unsigned int)sysconf(_SC_CLK_TCK),
321 multiplier = ((
uint64_t)1000L / ticks);
326 mach_msg_type_number_t msg_type;
327 processor_cpu_load_info_data_t *
info;
332 size =
sizeof(model);
333 if (sysctlbyname(
"machdep.cpu.brand_string", &model, &
size,
NULL, 0) &&
334 sysctlbyname(
"hw.model", &model, &
size,
NULL, 0)) {
342 if (host_processor_info(mach_host_self(), PROCESSOR_CPU_LOAD_INFO, &numcpus,
343 (processor_info_array_t*)&
info,
344 &msg_type) != KERN_SUCCESS) {
348 *cpu_infos =
uv__malloc(numcpus *
sizeof(**cpu_infos));
350 vm_deallocate(mach_task_self(), (vm_address_t)
info, msg_type);
356 for (
i = 0;
i < numcpus;
i++) {
357 cpu_info = &(*cpu_infos)[
i];
366 cpu_info->
speed = cpuspeed/1000000;
368 vm_deallocate(mach_task_self(), (vm_address_t)
info, msg_type);
RzBinInfo * info(RzBinFile *bf)
const lzma_allocator const uint8_t size_t uint8_t * out
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol which
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void count
unsigned int io_iterator_t
unsigned int io_registry_entry_t
void * CFMutableDictionaryRef
unsigned int io_service_t
unsigned CFStringEncoding
void uv__fsevents_loop_delete(uv_loop_t *loop)
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
static static fork const void static count static fd const char const char static newpath char char char static envp time
assert(limit<=UINT32_MAX/2)
struct uv_cpu_times_s cpu_times
uint64_t uv_get_total_memory(void)
static void uv__hrtime_init_once(void)
void uv_loadavg(double avg[3])
static uint64_t(* time_func)(void)
uint64_t uv_get_free_memory(void)
uint64_t uv__hrtime(uv_clocktype_t type)
int uv__platform_loop_init(uv_loop_t *loop)
int uv_uptime(double *uptime)
#define V(handle, symbol)
int uv_cpu_info(uv_cpu_info_t **cpu_infos, int *count)
uint64_t uv_get_constrained_memory(void)
void uv__platform_loop_delete(uv_loop_t *loop)
static int uv__get_cpu_speed(uint64_t *speed)
static mach_timebase_info_data_t timebase
int uv_exepath(char *buffer, size_t *size)
int uv_resident_set_memory(size_t *rss)
int uv__kqueue_init(uv_loop_t *loop)
char * uv__strdup(const char *s)
void * uv__malloc(size_t size)
UV_EXTERN void uv_once(uv_once_t *guard, void(*callback)(void))