问题
I am currently working on a project in Android. I want to get the total cpu usage of each and every process. So i am using the contents of "/proc/pid/stat". I referred this answer to get the stats. Now i got all the utime, stime etc., The problem is with the value of "Hertz". The answer says that it is the number of clock ticks per second. I don't get the exact meaning of clock tick even after browsing a lot. What is a clock tick and is it the frequency of the processor? And the answer says that we can get the clock ticks using
sysconf(_SC_CLK_TCK)
I don't know how to use this linux command in Android to get the clock ticks. I have googled it and i couldn't find it. Pls help me with this. And it would be more helpful if there is an example for this clock tick.
回答1:
100 is the default value set on Linux. And it appears to be unchanged in Android as shown in the sysconf.c
source file - goo.gl/C5yubg
If you see line 167, this is what sysconf(_SC_CLK_TCK)
will retrun:
case _SC_CLK_TCK: return SYSTEM_CLK_TCK;
The default value for SYSTEM_CLK_TCK
is defined as 100
来源:https://stackoverflow.com/questions/28292807/what-is-exactly-a-clock-tick-in-the-context-of-android-cpu-usage