问题
In question about "total cpu usage of an application from /proc/pid/stat" is explanation, how to get cpu usage, but to do it, we must know clock ticks.
But how I can get this value in Android (directly from device)? I just don´t get how to use following function in Android, because it seems to be Linux command.
Hertz (number of clock ticks per second) of your system. In most cases, sysconf(_SC_CLK_TCK) can be used to return the number of clock ticks.
回答1:
Knowing the CPU frequency of your device should allows you to calculate the total CPU usage for an application, as discussed in the post you mentioned in your question. You can get information about your current CPU frequency by accessing the specific system files located in the /sys
directory:
/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq
This will tell you what the current CPU frequency is. You can also determine the maximum and minimum possible CPU frequencies by reading the cpuinfo_max_freq
and cpuinfo_min_freq
files, respectively:
/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq
/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq
来源:https://stackoverflow.com/questions/27671744/android-number-of-clock-ticks-hertz