[OS X Emacs] Re: M-x proced

Leo sdl.web at gmail.com
Mon Mar 15 12:52:30 EDT 2010


On 2010-03-09 23:26 +0000, David Reitter wrote:
> On Mar 9, 2010, at 4:55 PM, Leo wrote:
>
>>  
>> <proced-osx.png>
>> However, do you know how to get the cpu and mem percentage?
>> 
>> struct extern_proc.p_pctcpu always gives me '0'.
>
>
> sysctl is a lower-level library than Carbon, but I can see why we don't want to include Carbon.h.
>
> One clean way seems to be to go through getrusage(), but that is guaranteed for yourself and the child processes only.  
>
> What about processSize from the ProcessInfoRec structure?
> You can easily convert that into a percentage after querying all processes.
>
> And to get a snapshot of the CPU usage, I would query GetProcessInformation() twice, noting processActiveTime so that you can see what the process has used in the last 0.1 second or whatever.... However, the Apple doc says "In Mac OS X, the processActiveTime field of the returned structure is always 0", so this is not an option.
>
> So, the answer is, I don't know.  I would probably take a look at the darwin "top" source code:
>
> http://www.opensource.apple.com/source/top/top-67/
>
> From cpu.c it seems that it just keeps sampling  and attributes time lapsed to the active process, but I might be wrong.

Would you be willing to test my patch? If so, i will send a copy to you
through email.

Thanks

Leo




More information about the MacOSX-Emacs mailing list