Skip to content

Commit

Permalink
fix bus:cpu usage is negative
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewleo committed Mar 25, 2013
1 parent fe27aff commit 232debd
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/com/netease/qa/emmagee/utils/CpuInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,12 @@ public void readCpuStat() {
try {
// monitor total and idle cpu stat of certain process
RandomAccessFile cpuInfo = new RandomAccessFile("/proc/stat", "r");
String[] toks = cpuInfo.readLine().split(" ");
idleCpu = Long.parseLong(toks[5]);
totalCpu = Long.parseLong(toks[2]) + Long.parseLong(toks[3])
+ Long.parseLong(toks[4]) + Long.parseLong(toks[6])
+ Long.parseLong(toks[5]) + Long.parseLong(toks[7])
+ Long.parseLong(toks[8]);
String[] toks = cpuInfo.readLine().split("\\s+");
idleCpu = Long.parseLong(toks[4]);
totalCpu = Long.parseLong(toks[1]) + Long.parseLong(toks[2])
+ Long.parseLong(toks[3]) + Long.parseLong(toks[4])
+ Long.parseLong(toks[6]) + Long.parseLong(toks[5])
+ Long.parseLong(toks[7]);
cpuInfo.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
Expand Down Expand Up @@ -168,7 +168,7 @@ public ArrayList<String> getCpuRatioInfo() {
else
traffic = (lastestTraffic - initialTraffic + 1023) / 1024;
processCpuRatio = fomart
.format(100 * ((double) (processCpu - processCpu2) / (double) (totalCpu - totalCpu2)));
.format(100 * ((double) (processCpu - processCpu2) / ((double) (totalCpu - totalCpu2))));
totalCpuRatio = fomart
.format(100 * ((double) ((totalCpu - idleCpu) - (totalCpu2 - idleCpu2)) / (double) (totalCpu - totalCpu2)));
long pidMemory = mi.getPidMemorySize(pid, context);
Expand Down Expand Up @@ -207,7 +207,7 @@ public ArrayList<String> getCpuRatioInfo() {

}

// TODO coming soon
// // TODO coming soon
// public String cpuinfo() {
// String sys_info = "";
// String s;
Expand Down

0 comments on commit 232debd

Please sign in to comment.