提交 244509aa 编写于 作者: A andrewleo

Fixed: #15 usage rate of CPU is negative

上级 e384d9a8
......@@ -464,25 +464,26 @@ public class EmmageeService extends Service {
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;
}
}
}
......
......@@ -177,13 +177,11 @@ public class CpuInfo {
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");
......@@ -198,24 +196,24 @@ public class CpuInfo {
}
} 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;
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册