, , :
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;
}
}
, : -D
int core1CurrentFreq = getCurrentFrequency(1, this);
, , -1
.
MHz - core1CurrentFreq/1e3
- core1CurrentFreq/1e6
getCurFrequencyFilePath(), .
: scaling_cur_freq
:
"/sys/devices/system/cpu/cpu(XX)/cpufreq/scaling_cur_freq"
(XX) cpu, :
"/sys/devices/system/cpu/cpu2/cpufreq/scaling_cur_freq"
INSERTION_POINT - , (XX), , , cpu
cpufreq, , , ..
3