Michael Ratanapintha
Michael Ratanapintha

Reputation: 40577

Getting programmatic access to MacOS system performance statistics

When you run top or Activity Monitor on Mac OS X, you see a variety of performance data for the whole system - current and historic CPU usage, physical memory and swap space usage, disk activity, and so on. On Linux and some other Unix-like systems, you can access this data in your own programs by using kernel system calls or by looking in the /proc and/or /sys pseudo-filesystems.

Unfortunately, MacOS lacks both /proc and /sys, and a few web searches don't reveal many syscalls that provide whole-computer performance data. Hence this question:

How might you access MacOS system performance data from your C program?

Upvotes: 2

Views: 1314

Answers (1)

Geoff Reedy
Geoff Reedy

Reputation: 36011

The functions and structures to get this information are described in /usr/include/libproc.h and /usr/include/sys/proc.h. libproc.h has this warning though

/*
 * This header file contains private interfaces to obtain process information.  
 * These interfaces are subject to change in future releases.
 */

The functions are found in libSystem. They look pretty straightforward to use.

Upvotes: 4

Related Questions