开发者

Measure memory usage of a process in Cocoa/Objective-C?

I want to make a program that is able to show the amount of RAM that Google Chrome uses. Chrome uses a process for each tab and each plug-in/extension (basically), so you can't know with a glance on the a开发者_运维问答ctivity monitor the amount of RAM it's taking.

My idea was to give the program the name of the process (Chrome), and it will search every child process. I will add then the amount of memory taken by all the parented process to have my answer.

The problem is: I can't find a class that can give me the amount of memory taken by a process.

I've find a way to get the PID from the name of the app (and vice versa) with the sample code PIDFromBSDProcessName written in C. But I can't find the memory, neither in NSRunningApplication, NSTask of NSWorkSpace classes.


One problem is that there will likely be some shared memory between the various processes that an application will find very hard to detect. Also if it maps a file like the bookmarks/history DBs into memory as well that will appear as if it were normal memory, making a tool like this very inaccurate.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜