提交 fad688ba 编写于 作者: A andrewleo

Fixed: get cpu_name of x86 architecture

上级 adb9f2dc
...@@ -59,6 +59,10 @@ public class CpuInfo { ...@@ -59,6 +59,10 @@ public class CpuInfo {
private String totalCpuRatio = ""; private String totalCpuRatio = "";
private int pid; private int pid;
private static final String INTEL_CPU_NAME = "model name";
private static final String CPU_X86 = "x86";
private static final String CPU_INFO_PATH = "/proc/cpuinfo";
public CpuInfo(Context context, int pid, String uid) { public CpuInfo(Context context, int pid, String uid) {
this.pid = pid; this.pid = pid;
this.context = context; this.context = context;
...@@ -87,6 +91,9 @@ public class CpuInfo { ...@@ -87,6 +91,9 @@ public class CpuInfo {
stringBuffer.append(line + "\n"); stringBuffer.append(line + "\n");
} }
String[] tok = stringBuffer.toString().split(" "); String[] tok = stringBuffer.toString().split(" ");
for(int i = 0;i<tok.length;i++){
Log.w(LOG_TAG, "tok["+i+"]=========="+tok[i]);
}
processCpu = Long.parseLong(tok[13]) + Long.parseLong(tok[14]); processCpu = Long.parseLong(tok[13]) + Long.parseLong(tok[14]);
processCpuInfo.close(); processCpuInfo.close();
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
...@@ -100,6 +107,9 @@ public class CpuInfo { ...@@ -100,6 +107,9 @@ public class CpuInfo {
// monitor total and idle cpu stat of certain process // monitor total and idle cpu stat of certain process
RandomAccessFile cpuInfo = new RandomAccessFile("/proc/stat", "r"); RandomAccessFile cpuInfo = new RandomAccessFile("/proc/stat", "r");
String[] toks = cpuInfo.readLine().split("\\s+"); String[] toks = cpuInfo.readLine().split("\\s+");
for(int i = 0;i<toks.length;i++){
Log.w(LOG_TAG, "toks["+i+"]=========="+toks[i]);
}
idleCpu = Long.parseLong(toks[4]); idleCpu = Long.parseLong(toks[4]);
totalCpu = Long.parseLong(toks[1]) + Long.parseLong(toks[2]) + Long.parseLong(toks[3]) + Long.parseLong(toks[4]) totalCpu = Long.parseLong(toks[1]) + Long.parseLong(toks[2]) + Long.parseLong(toks[3]) + Long.parseLong(toks[4])
+ Long.parseLong(toks[6]) + Long.parseLong(toks[5]) + Long.parseLong(toks[7]); + Long.parseLong(toks[6]) + Long.parseLong(toks[5]) + Long.parseLong(toks[7]);
...@@ -118,10 +128,21 @@ public class CpuInfo { ...@@ -118,10 +128,21 @@ public class CpuInfo {
*/ */
public String getCpuName() { public String getCpuName() {
try { try {
RandomAccessFile cpuStat = new RandomAccessFile("/proc/cpuinfo", "r"); RandomAccessFile cpuStat = new RandomAccessFile(CPU_INFO_PATH, "r");
// 需要判断是intel or arm
if (Build.CPU_ABI.equalsIgnoreCase(CPU_X86)) {
String line;
while (null != (line = cpuStat.readLine())) {
String[] values = line.split(":");
if (values[0].contains(INTEL_CPU_NAME)) {
return values[1];
}
}
} else {
String[] cpu = cpuStat.readLine().split(":"); // cpu信息的前一段是含有processor字符串,此处替换为不显示 String[] cpu = cpuStat.readLine().split(":"); // cpu信息的前一段是含有processor字符串,此处替换为不显示
cpuStat.close(); cpuStat.close();
return cpu[1]; return cpu[1];
}
} catch (IOException e) { } catch (IOException e) {
Log.e(LOG_TAG, "IOException: " + e.getMessage()); Log.e(LOG_TAG, "IOException: " + e.getMessage());
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册