Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

ArtOfWarfare

macrumors G3
Original poster
Nov 26, 2007
9,545
6,042
Does anyone know from whence Activity Monitor fetches all the data it shows?

Namely, I'd like to find the breakdown of CPU and RAM usage of each process running on the computer in my app.

An ideal solution would be MAS-permitted but I'd be happy with any solutions anyone has.

I'm in a similar boat to this person:

http://stackoverflow.com/questions/6762932/measure-memory-usage-of-a-process-in-cocoa-objectice-c

Looking at other sources, I found someone saying that the kernel keeps track of memory and CPU usage of each application.

To be clear, the data I want is exactly what activity monitor shows... I've read other places that there are five different types of memory, and I don't care that much about such details... Whatever is good enough for Activity Monitor is good enough for me.
 

chown33

Moderator
Staff member
Aug 9, 2009
10,706
8,346
A sea of green
Start by looking at the man page for the 'top' command. See if it has the ability to print every specific datum you want.

If it does, then go get the source for 'top' from Apple's Darwin website, and see how 'top' gets each specific datum. I suspect 'top' uses the sysctl() function (man section 3) for a lot of things, and the various KERN_PROC mibs or names. But the best approach is to look at top's source.

If you need some datum that top doesn't display, and you can't figure out a sysctl() name to use, ask again.

Notice when running Activity Monitor that pmTool, which Activity Monitor uses to gather data, runs as root, which means you may be restricted in deploying to the Mac App Store.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.