如何从Android设备的具体信息"的/ proc内/ cpuinfo" flie? [英] How to get specific information of an Android device from "/proc/cpuinfo" flie?

查看:171
本文介绍了如何从Android设备的具体信息"的/ proc内/ cpuinfo" flie?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何分析我的Andr​​oid平板电脑的/ proc内/ cpuinfo文件,以获得处理器的核心时钟频率和信息?
我不需要上述文件,但他们中的两个信息提供的所有信息。
如果有人请帮助?

How can I parse "/proc/cpuinfo" 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 but two information of them. If someone please help?

推荐答案

我希望这不是为时已晚,一个答案,但,这是我如何获得当前的频率为特定的CPU核心:

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;
 }

}

从这里的一块蛋糕,你只需调用方法:-D

From here its a piece of cake, you simply call the method :-D

int core1CurrentFreq = getCurrentFrequency(1, this); 

有时芯脱机,在这种情况下,该文件的路径将不存在和将返回-1

Sometimes the cores go offline, in which case the file path will not exist and -1 will be returned

注:。返回的值是千赫

MHz的值是core1CurrentFreq / 1E3

GHz的值是core1CurrentFreq / 1e6个电子

NOTE. the returned value is in KHz
MHz value is core1CurrentFreq / 1e3
GHz value is core1CurrentFreq / 1e6

在getCurFrequencyFilePath()方法的一些解释相关,因为它是不是所有的清晰。

Some explainations on the getCurFrequencyFilePath() method since it is not all that clear.

电流频率通常存储在文件:scaling_cur_freq

Current frequency is usually stored in the file: scaling_cur_freq

该文件路径是:

"/sys/devices/system/cpu/cpu(XX)/cpufreq/scaling_cur_freq"

在哪里(XX)替换为CPU内核数例如:

where (XX) is substituted for the cpu core number eg:

"/sys/devices/system/cpu/cpu2/cpufreq/scaling_cur_freq"

该INSERTION_POINT变量无非是在我们希望将对应的CPU核心数(XX),该点的指数更加

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

我建议你看看一些在CPU频率文件夹,可以使用它们的其他文件,以获得像最大和最小频率,可获取的频率等。

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.

点击此
链接
向下滚动到标题3

Click this Link and scroll down to heading 3

这篇关于如何从Android设备的具体信息"的/ proc内/ cpuinfo" flie?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆