Skip to content

Commit

Permalink
Fixed: NetEase#32 negative network traffic
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewleo committed Feb 10, 2015
1 parent 4c2dc6d commit fd1ebf2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
16 changes: 8 additions & 8 deletions src/com/netease/qa/emmagee/service/EmmageeService.java
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ private void getStartTimeFromLogcat() {

while ((line = bufferedReader.readLine()) != null) {
strBuilder.append(line);
strBuilder.append("\r\n");
strBuilder.append(Constants.LINE_END);
String regex = ".*Displayed.*" + startActivity + ".*\\+(.*)ms.*";
if (line.matches(regex)) {
Log.w("my logs", line);
Expand Down Expand Up @@ -434,10 +434,10 @@ private void dataRefresh() {
// 异常数据过滤
try {
if (Math.abs(Double.parseDouble(currentBatt)) >= 500) {
currentBatt = "N/A";
currentBatt = Constants.NA;
}
} catch (Exception e) {
currentBatt = "N/A";
currentBatt = Constants.NA;
}
ArrayList<String> processInfo = cpuInfo.getCpuRatioInfo(totalBatt, currentBatt, temperature, voltage);
if (isFloating) {
Expand All @@ -464,7 +464,7 @@ private void dataRefresh() {
txtTotalMem.setText(getString(R.string.process_overall_cpu) + processCpuRatio + "%/" + totalCpuRatio + "%");
String batt = getString(R.string.current) + currentBatt;
if ("-1".equals(trafficSize)) {
txtTraffic.setText(batt + "," + getString(R.string.traffic) + "N/A");
txtTraffic.setText(batt + "," + getString(R.string.traffic) + Constants.NA);
} else if (isMb)
txtTraffic.setText(batt + "," + getString(R.string.traffic) + fomart.format(trafficMb) + "MB");
else
Expand Down Expand Up @@ -498,8 +498,8 @@ private void updateViewPosition() {
public void closeOpenedStream() {
try {
if (bw != null) {
bw.write(getString(R.string.comment1) + "\r\n" + getString(R.string.comment2) + "\r\n" + getString(R.string.comment3) + "\r\n"
+ getString(R.string.comment4) + "\r\n");
bw.write(getString(R.string.comment1) + Constants.LINE_END + getString(R.string.comment2) + Constants.LINE_END + getString(R.string.comment3) + Constants.LINE_END
+ getString(R.string.comment4) + Constants.LINE_END);
bw.close();
}
if (osw != null)
Expand All @@ -523,7 +523,7 @@ public void onDestroy() {
// replace the start time in file
if (isGrantedReadLogsPermission()) {
if (!BLANK_STRING.equals(startTime)) {
replaceFileString(resultFilePath, START_TIME, getString(R.string.start_time) + startTime + "\r\n");
replaceFileString(resultFilePath, START_TIME, getString(R.string.start_time) + startTime + Constants.LINE_END);
} else {
replaceFileString(resultFilePath, START_TIME, BLANK_STRING);
}
Expand Down Expand Up @@ -561,7 +561,7 @@ private void replaceFileString(String filePath, String replaceType, String repla
String line = BLANK_STRING;
String oldtext = BLANK_STRING;
while ((line = reader.readLine()) != null) {
oldtext += line + "\r\n";
oldtext += line + Constants.LINE_END;
}
reader.close();
// replace a word in a file
Expand Down
13 changes: 8 additions & 5 deletions src/com/netease/qa/emmagee/utils/CpuInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class CpuInfo {
private SimpleDateFormat formatterFile;
private MemoryInfo mi;
private long totalMemorySize;
private long initialTraffic;
private long preTraffic;
private long lastestTraffic;
private long traffic;
private TrafficInfo trafficInfo;
Expand Down Expand Up @@ -252,17 +252,20 @@ public ArrayList<String> getCpuRatioInfo(String totalBatt, String currentBatt, S
} else
mDateTime2 = formatterFile.format(cal.getTime().getTime());
if (isInitialStatics) {
initialTraffic = trafficInfo.getTrafficInfo();
preTraffic = trafficInfo.getTrafficInfo();
isInitialStatics = false;
} else {
lastestTraffic = trafficInfo.getTrafficInfo();
if (initialTraffic == -1)
if (preTraffic == -1)
traffic = -1;
else {
traffic = (lastestTraffic - initialTraffic + 1023) / 1024;
if (lastestTraffic > preTraffic) {
traffic += (lastestTraffic - preTraffic + 1023) / 1024;
}
}
preTraffic = lastestTraffic;
Log.d(LOG_TAG, "lastestTraffic===" + lastestTraffic);
Log.d(LOG_TAG, "initialTraffic===" + initialTraffic);
Log.d(LOG_TAG, "preTraffic===" + preTraffic);
StringBuffer totalCpuBuffer = new StringBuffer();
if (null != totalCpu2 && totalCpu2.size() > 0) {
processCpuRatio = fomart.format(100 * ((double) (processCpu - processCpu2) / ((double) (totalCpu.get(0) - totalCpu2.get(0)))));
Expand Down

0 comments on commit fd1ebf2

Please sign in to comment.