diff --git a/src/com/netease/qa/emmagee/service/EmmageeService.java b/src/com/netease/qa/emmagee/service/EmmageeService.java index b985f51fd908f448a46287ef57e728a0c91204b2..d6f45c38534c60295ef8a2c8e741da932a5a3019 100644 --- a/src/com/netease/qa/emmagee/service/EmmageeService.java +++ b/src/com/netease/qa/emmagee/service/EmmageeService.java @@ -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; - } + } } diff --git a/src/com/netease/qa/emmagee/utils/CpuInfo.java b/src/com/netease/qa/emmagee/utils/CpuInfo.java index 41eeab95d40407b470f4b49aac7f8c532a6b70de..4537d44ac6e745733135d491b39957c959713147 100644 --- a/src/com/netease/qa/emmagee/utils/CpuInfo.java +++ b/src/com/netease/qa/emmagee/utils/CpuInfo.java @@ -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; } }