Does anyone know if it is possible to get the cpu usage for a specific thread, process, or some code in the application?
If you look at AUGraph it has a function which returns average cpu usage. How do they do that?
Does anyone know if it is possible to get the cpu usage for a
Share
I am not sure that this also applies to iOS, but for OS X, you can get the info you need by accessing the Mach/BSD subsystem. Basically you get the list of threads for a given process, then sum all threads’ usage to get the process cpu usage. If you need only a thread cpu usage, you don’t need to sum up.
It is not as easy and straightforward as one might desire, but here it is (this code is based on Amit Singh “Mac OS X internals”):
I don’t know if there is a better way to do that, possibly so, but this one has worked for me.