Skip to content

Instantly share code, notes, and snippets.

@billmote
Last active August 29, 2015 14:05
Show Gist options
  • Save billmote/1cc86b49189f89a14ca0 to your computer and use it in GitHub Desktop.
Save billmote/1cc86b49189f89a14ca0 to your computer and use it in GitHub Desktop.
How much horsepower does my phone have?
public static Long CPU_MAX_FREQUENCY;
@Override
public void onCreate(){
// ...
CPU_MAX_FREQUENCY = getCpuMaxFrequency();
// ...
}
private Long getCpuMaxFrequency() {
String cpuMaxFreq = "";
int numCores = 0;
RandomAccessFile reader = null;
try {
reader = new RandomAccessFile("/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq", "r");
numCores++;
reader = new RandomAccessFile("/sys/devices/system/cpu/cpu1/cpufreq/cpuinfo_max_freq", "r");
numCores++;
reader = new RandomAccessFile("/sys/devices/system/cpu/cpu2/cpufreq/cpuinfo_max_freq", "r");
numCores++;
reader = new RandomAccessFile("/sys/devices/system/cpu/cpu3/cpufreq/cpuinfo_max_freq", "r");
numCores++;
reader = new RandomAccessFile("/sys/devices/system/cpu/cpu4/cpufreq/cpuinfo_max_freq", "r");
numCores++;
reader = new RandomAccessFile("/sys/devices/system/cpu/cpu5/cpufreq/cpuinfo_max_freq", "r");
numCores++;
reader = new RandomAccessFile("/sys/devices/system/cpu/cpu6/cpufreq/cpuinfo_max_freq", "r");
numCores++;
reader = new RandomAccessFile("/sys/devices/system/cpu/cpu7/cpufreq/cpuinfo_max_freq", "r");
numCores++;
} catch (FileNotFoundException fnfe) {
fnfe.printStackTrace();
}
try {
cpuMaxFreq = reader.readLine();
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
//Toast.makeText(this, String.format("MAX CPU FREQ: %,d", (numCores * Long.parseLong(cpuMaxFreq))), Toast.LENGTH_LONG).show();
return numCores * Long.parseLong(cpuMaxFreq);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment