Skip to content

Commit 244509a

Browse files
author
andrewleo
committed
Fixed: #15 usage rate of CPU is negative
1 parent e384d9a commit 244509a

File tree

2 files changed

+27
-28
lines changed

2 files changed

+27
-28
lines changed

src/com/netease/qa/emmagee/service/EmmageeService.java

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -464,25 +464,26 @@ private void dataRefresh() {
464464
trafficMb = (double) tempTraffic / 1024;
465465
}
466466
}
467+
// 如果cpu使用率存在且都不小于0,则输出
468+
if (processCpuRatio != null && totalCpuRatio != null) {
469+
txtUnusedMem.setText("应用/剩余内存:" + processMemory + "/" + freeMemoryKb + "MB");
470+
txtTotalMem.setText("应用/总体CPU:" + processCpuRatio + "%/" + totalCpuRatio + "%");
471+
String batt = "电流:" + currentBatt;
472+
if ("-1".equals(trafficSize)) {
473+
txtTraffic.setText(batt + ",流量:N/A");
474+
} else if (isMb)
475+
txtTraffic.setText(batt + ",流量:" + fomart.format(trafficMb) + "MB");
476+
else
477+
txtTraffic.setText(batt + ",流量:" + trafficSize + "KB");
478+
}
479+
// 当内存为0切cpu使用率为0时则是被测应用退出
480+
if ("0".equals(processMemory) && "0.00".equals(processCpuRatio)) {
481+
closeOpenedStream();
482+
isServiceStop = true;
483+
return;
484+
}
467485
}
468-
// 如果cpu使用率存在且都不小于0,则输出
469-
if (processCpuRatio != null && totalCpuRatio != null) {
470-
txtUnusedMem.setText("应用/剩余内存:" + processMemory + "/" + freeMemoryKb + "MB");
471-
txtTotalMem.setText("应用/总体CPU:" + processCpuRatio + "%/" + totalCpuRatio + "%");
472-
String batt = "电流:" + currentBatt;
473-
if ("-1".equals(trafficSize)) {
474-
txtTraffic.setText(batt + ",流量:N/A");
475-
} else if (isMb)
476-
txtTraffic.setText(batt + ",流量:" + fomart.format(trafficMb) + "MB");
477-
else
478-
txtTraffic.setText(batt + ",流量:" + trafficSize + "KB");
479-
}
480-
// 当内存为0切cpu使用率为0时则是被测应用退出
481-
if ("0".equals(processMemory) && "0.00".equals(processCpuRatio)) {
482-
closeOpenedStream();
483-
isServiceStop = true;
484-
return;
485-
}
486+
486487
}
487488
}
488489

src/com/netease/qa/emmagee/utils/CpuInfo.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -177,13 +177,11 @@ public ArrayList<String> getCpuRatioInfo(String totalBatt, String currentBatt, S
177177
percent = fomart.format(((double) pidMemory / (double) totalMemorySize) * 100);
178178
}
179179

180-
// 当应用的cpu使用率大于0时才写入文件中,过滤掉异常数据
181-
if (isDouble(processCpuRatio) && isDouble(totalCpuRatio)) {
180+
if (isPositive(processCpuRatio) && isPositive(totalCpuRatio)) {
182181
// whether certain device supports traffic statics or not
183-
if (traffic == -1) {
182+
if (traffic == -1) {
184183
EmmageeService.bw.write(mDateTime2 + "," + pMemory + "," + percent + "," + fMemory + "," + processCpuRatio + ","
185-
+ totalCpuRatio + "," + "N/A" + "," + totalBatt + "," + currentBatt + "," + temperature + "," + voltage
186-
+ "\r\n");
184+
+ totalCpuRatio + "," + "N/A" + "," + totalBatt + "," + currentBatt + "," + temperature + "," + voltage + "\r\n");
187185
} else {
188186
EmmageeService.bw.write(mDateTime2 + "," + pMemory + "," + percent + "," + fMemory + "," + processCpuRatio + ","
189187
+ totalCpuRatio + "," + traffic + "," + totalBatt + "," + currentBatt + "," + temperature + "," + voltage + "\r\n");
@@ -198,24 +196,24 @@ public ArrayList<String> getCpuRatioInfo(String totalBatt, String currentBatt, S
198196
}
199197
} catch (IOException e) {
200198
e.printStackTrace();
201-
// PttService.closeOpenedStream()
202199
}
203200
return cpuUsedRatio;
204201
}
205202

206203
/**
207-
* 判断text是否是一个double类型数据
204+
* is text a positive number
208205
*
209206
* @param text
210207
* @return
211208
*/
212-
private boolean isDouble(String text) {
209+
private boolean isPositive(String text) {
210+
Double num;
213211
try {
214-
Double.parseDouble(text);
212+
num = Double.parseDouble(text);
215213
} catch (NumberFormatException e) {
216214
return false;
217215
}
218-
return true;
216+
return num >= 0;
219217
}
220218

221219
}

0 commit comments

Comments
 (0)