Skip to content

Commit

Permalink
Fixed: get cpu_name of x86 architecture
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewleo committed Sep 15, 2014
1 parent adb9f2d commit fad688b
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions src/com/netease/qa/emmagee/utils/CpuInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ public class CpuInfo {
private String totalCpuRatio = "";
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) {
this.pid = pid;
this.context = context;
Expand Down Expand Up @@ -87,6 +91,9 @@ public void readCpuStat() {
stringBuffer.append(line + "\n");
}
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]);
processCpuInfo.close();
} catch (FileNotFoundException e) {
Expand All @@ -100,6 +107,9 @@ public void readCpuStat() {
// monitor total and idle cpu stat of certain process
RandomAccessFile cpuInfo = new RandomAccessFile("/proc/stat", "r");
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]);
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]);
Expand All @@ -118,10 +128,21 @@ public void readCpuStat() {
*/
public String getCpuName() {
try {
RandomAccessFile cpuStat = new RandomAccessFile("/proc/cpuinfo", "r");
String[] cpu = cpuStat.readLine().split(":"); // cpu信息的前一段是含有processor字符串,此处替换为不显示
cpuStat.close();
return cpu[1];
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字符串,此处替换为不显示
cpuStat.close();
return cpu[1];
}
} catch (IOException e) {
Log.e(LOG_TAG, "IOException: " + e.getMessage());
}
Expand Down

0 comments on commit fad688b

Please sign in to comment.