2

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.

Community
  • 1
  • 1
Michal
  • 2,071
  • 19
  • 30
  • 2
    [`sysconf(_SCK_CLK_TCK)`](http://pubs.opengroup.org/onlinepubs/009695399/functions/sysconf.html) is a C function call (i.e. it must be compiled in a program to be used). The shell command equivalent is [`getconf CLK_TCK`](http://pubs.opengroup.org/onlinepubs/009695399/utilities/getconf.html). Unfortunately, the [`getconf`](http://pubs.opengroup.org/onlinepubs/009695399/utilities/getconf.html) utility appears to be missing from Android. – Vilhelm Gray Jul 07 '15 at 16:04
  • possible duplicate of [What is exactly a "Clock Tick" in the context of Android CPU Usage?](http://stackoverflow.com/questions/28292807/what-is-exactly-a-clock-tick-in-the-context-of-android-cpu-usage) – Vilhelm Gray Jul 07 '15 at 16:14

1 Answers1

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

Willis
  • 5,308
  • 3
  • 32
  • 61
  • 2
    The Linux kernel (which Android runs) abstracts away the true CPU hardware clock ticks. The values listed Linux proc files are scaled to a "pseudo-clock" frequency via the Linux kernel `USER_HZ` constant; this `USER_HZ` is the "hertz" value that must be used. The value in `/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq` is most likely not equal to the `USER_HZ` constant. – Vilhelm Gray Jul 07 '15 at 15:57