Skip to content

Commit

Permalink
Fixed: #15 usage rate of CPU is negative
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewleo committed Jan 6, 2014
1 parent e384d9a commit 244509a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 28 deletions.
37 changes: 19 additions & 18 deletions src/com/netease/qa/emmagee/service/EmmageeService.java
Original file line number Diff line number Diff line change
Expand Up @@ -464,25 +464,26 @@ private void dataRefresh() {
trafficMb = (double) tempTraffic / 1024;
}
}
// 如果cpu使用率存在且都不小于0,则输出
if (processCpuRatio != null && totalCpuRatio != null) {
txtUnusedMem.setText("应用/剩余内存:" + processMemory + "/" + freeMemoryKb + "MB");
txtTotalMem.setText("应用/总体CPU:" + processCpuRatio + "%/" + totalCpuRatio + "%");
String batt = "电流:" + currentBatt;
if ("-1".equals(trafficSize)) {
txtTraffic.setText(batt + ",流量:N/A");
} else if (isMb)
txtTraffic.setText(batt + ",流量:" + fomart.format(trafficMb) + "MB");
else
txtTraffic.setText(batt + ",流量:" + trafficSize + "KB");
}
// 当内存为0切cpu使用率为0时则是被测应用退出
if ("0".equals(processMemory) && "0.00".equals(processCpuRatio)) {
closeOpenedStream();
isServiceStop = true;
return;
}
}
// 如果cpu使用率存在且都不小于0,则输出
if (processCpuRatio != null && totalCpuRatio != null) {
txtUnusedMem.setText("应用/剩余内存:" + processMemory + "/" + freeMemoryKb + "MB");
txtTotalMem.setText("应用/总体CPU:" + processCpuRatio + "%/" + totalCpuRatio + "%");
String batt = "电流:" + currentBatt;
if ("-1".equals(trafficSize)) {
txtTraffic.setText(batt + ",流量:N/A");
} else if (isMb)
txtTraffic.setText(batt + ",流量:" + fomart.format(trafficMb) + "MB");
else
txtTraffic.setText(batt + ",流量:" + trafficSize + "KB");
}
// 当内存为0切cpu使用率为0时则是被测应用退出
if ("0".equals(processMemory) && "0.00".equals(processCpuRatio)) {
closeOpenedStream();
isServiceStop = true;
return;
}

}
}

Expand Down
18 changes: 8 additions & 10 deletions src/com/netease/qa/emmagee/utils/CpuInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,11 @@ public ArrayList<String> getCpuRatioInfo(String totalBatt, String currentBatt, S
percent = fomart.format(((double) pidMemory / (double) totalMemorySize) * 100);
}

// 当应用的cpu使用率大于0时才写入文件中,过滤掉异常数据
if (isDouble(processCpuRatio) && isDouble(totalCpuRatio)) {
if (isPositive(processCpuRatio) && isPositive(totalCpuRatio)) {
// whether certain device supports traffic statics or not
if (traffic == -1) {
if (traffic == -1) {
EmmageeService.bw.write(mDateTime2 + "," + pMemory + "," + percent + "," + fMemory + "," + processCpuRatio + ","
+ totalCpuRatio + "," + "N/A" + "," + totalBatt + "," + currentBatt + "," + temperature + "," + voltage
+ "\r\n");
+ totalCpuRatio + "," + "N/A" + "," + totalBatt + "," + currentBatt + "," + temperature + "," + voltage + "\r\n");
} else {
EmmageeService.bw.write(mDateTime2 + "," + pMemory + "," + percent + "," + fMemory + "," + processCpuRatio + ","
+ totalCpuRatio + "," + traffic + "," + totalBatt + "," + currentBatt + "," + temperature + "," + voltage + "\r\n");
Expand All @@ -198,24 +196,24 @@ public ArrayList<String> getCpuRatioInfo(String totalBatt, String currentBatt, S
}
} catch (IOException e) {
e.printStackTrace();
// PttService.closeOpenedStream()
}
return cpuUsedRatio;
}

/**
* 判断text是否是一个double类型数据
* is text a positive number
*
* @param text
* @return
*/
private boolean isDouble(String text) {
private boolean isPositive(String text) {
Double num;
try {
Double.parseDouble(text);
num = Double.parseDouble(text);
} catch (NumberFormatException e) {
return false;
}
return true;
return num >= 0;
}

}

0 comments on commit 244509a

Please sign in to comment.