Вопрос

I'm writing an Android app that delivers statistics on the device it is installed on, and want to know if it is possible to determine the following metric.

Time the CPU has spent servicing a specific process. The device I am testing on has a 4 core processor, and I would like to get time spent regardless of weather the process in question is in the foreground or background. Using top gives you the % of the CPU a process occupies, is there a way to determine time (in seconds or clock cycles)?

Thank you

Это было полезно?

Решение

Take a look at ps command. It has format specifiers, i.e. fields/columns that provide CPU and wall time.

For example cputime for Android:

ps -x

will yield something that looks like this
u0_a16    18214 17002 743644 18104 ffffffff 00000000 S com.android.location.fused (u:10, s:13)

where u:10 and s:13 stand for time the CPU has spent on the processes (source : http://codeseekah.com/2012/10/21/android-shell-tricks-ps/)

I've made a Linux script for collecting system stats which you can check here: https://gist.github.com/izmailoff/8923008.

Другие советы

This is something for which gprof could actually be a good tool, if you can use it.

It only samples CPU time, and its samples are typically every 10 milliseconds.

So, see how many samples it gets, regardless of what functions they fall in, multiply by 10, and that's how many milliseconds your program used.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top