How to read cpu frequency on android device

Is there any Java API for that? How can I read this information.

Answers


To have frequency on Android, just read these special files in /sys directory:

#cat "/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq"
#cat "/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq"
#cat "/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq"

You will have current, min and max Frequency allowed.


not MHz, but at least something. bogoMIPS value can be useful for you.

private String ReadCPUinfo()
 {
  ProcessBuilder cmd;
  String result="";

  try{
   String[] args = {"/system/bin/cat", "/proc/cpuinfo"};
   cmd = new ProcessBuilder(args);

   Process process = cmd.start();
   InputStream in = process.getInputStream();
   byte[] re = new byte[1024];
   while(in.read(re) != -1){
    System.out.println(new String(re));
    result = result + new String(re);
   }
   in.close();
  } catch(IOException ex){
   ex.printStackTrace();
  }
  return result;
 }

If you are interested in how long your system spent in what state, check out the file

/sys/devices/system/cpu/cpu0/cpufreq/stats/time_in_state

I'm not sure, whether root access is necessary for that.


Need Your Help

Help me improve my continuous deployment workflow

php workflow continuous-integration hudson selenium-rc

I've been developing a workflow for practicing a mostly automated continuous deployment cycle for a PHP project. I'd like some feedback on possible process or technical bottlenecks in this workflow,

What is the memory footprint of a Nullable<T>

c# .net memory nullable

An int (Int32) has a memory footprint of 4 bytes. But what is the memory footprint of: