How can I parse /proc/cpuinfo
virtual file of my Android tablet to get information of the processor's core and clockspeed?
I don’t need all information provided by the above file; just these two bits.
Can someone please help?

- 22,578
- 8
- 40
- 86
2 Answers
It is not clear if you want this information inside your app, or just for your own use.
you can get this information on with adb:
adb shell cat /proc/cpuinfo
If you want to use this information in your app, create a simple function to return a
Map<String,String>
, for example,public static Map<String, String> getCpuInfoMap() { Map<String, String> map = new HashMap<String, String>(); try { Scanner s = new Scanner(new File("/proc/cpuinfo")); while (s.hasNextLine()) { String[] vals = s.nextLine().split(": "); if (vals.length > 1) map.put(vals[0].trim(), vals[1].trim()); } } catch (Exception e) {Log.e("getCpuInfoMap",Log.getStackTraceString(e));} return map; }
Note, this will not get multiple cpus information, overwrites. Most of the values are similar anyways. or Modify to create List of CpuInfoMaps.
try,
Log.d("getCpuInfoMap test", getCpuInfoMap().toString());

- 6,441
- 2
- 26
- 25
-
I want these two information in my own app. But not all of them, sorry! thats why I wrote for only those two values. – Oct 07 '14 at 20:52
-
2just pull those two values from the map...for eg: `getCpuInfoMap().get("cpu MHz")` – ashoke Oct 07 '14 at 20:53
-
thanks but I can't find my desired value there, that are "Processor's Core and ClockSpeed". – Oct 08 '14 at 10:57
-
1@android_bitter post your `adb shell cat /proc/cpuinfo` i can help you get just the values you want inside it. – ashoke Oct 08 '14 at 16:32
-
thanks ! I am getting the map values these "{CPU implementer=0x41, Serial=444155163231473411000138b1880707, CPU architecture=7, Hardware=sun6i, CPU revision=3, CPU variant=0x0, CPU part=0xc07, Revision=000b, BogoMIPS=2013.59, processor=3, Features=swp half thumb fastmult vfp edsp thumbee neon vfpv3 tls vfpv4 idiva idivt, Processor=ARMv7 Processor rev 3 (v7l)}" there are no values what I am looking for. but here are some values /proc/stat – Oct 09 '14 at 06:26
-
1@android_bitter in my case i am able to get the Serial no for some devices but for some device its giving me the value. do have any idea what i am missing in this? – rupesh Aug 19 '15 at 11:34
I hope its not too late for an answer but, this is how i get the current frequency for a specific cpu core:
public class MainActivity extends Activity{
private static final int INSERTION_POINT = 27;
private static String getCurFrequencyFilePath(int whichCpuCore){
StringBuilder filePath = new StringBuilder("/sys/devices/system/cpu/cpu/cpufreq/scaling_cur_freq");
filePath.insert(INSERTION_POINT, whichCpuCore);
return filePath.toString();
}
public static int getCurrentFrequency(int whichCpuCore){
int curFrequency = -1;
String cpuCoreCurFreqFilePath = getCurFrequencyFilePath(whichCpuCore);
if(new File(cpuCoreCurFreqFilePath).exists()){
try {
BufferedReader br = new BufferedReader(new FileReader(new File(cpuCoreCurFreqFilePath)));
String aLine;
while ((aLine = br.readLine()) != null) {
try{
curFrequency = Integer.parseInt(aLine);
}
catch(NumberFormatException e){
Log.e(getPackageName(), e.toString());
}
}
if (br != null) {
br.close();
}
}
catch (IOException e) {
Log.e(getPackageName(), e.toString());
}
}
return curFrequency;
}
}
From here its a piece of cake, you simply call the method :-D
int core1CurrentFreq = getCurrentFrequency(1, this);
Sometimes the cores go offline, in which case the file path will not exist and -1 will be returned
NOTE. the returned value is in KHz
MHz value is core1CurrentFreq / 1e3
GHz value is core1CurrentFreq / 1e6
Some explainations on the getCurFrequencyFilePath() method since it is not all that clear.
Current frequency is usually stored in the file: scaling_cur_freq
The file path is:
"/sys/devices/system/cpu/cpu(XX)/cpufreq/scaling_cur_freq"
where (XX) is substituted for the cpu core number eg:
"/sys/devices/system/cpu/cpu2/cpufreq/scaling_cur_freq"
The INSERTION_POINT variable is nothing more than the index of (XX), the point at which we want to place the number corresponding to the cpu core
I suggest you take a look at some of the other files in the cpufreq folder, you can use them to get other information like maximum and minimum frequency, list of availables frequencies etc.
Click this Link and scroll down to heading 3