Created
February 5, 2015 13:23
-
-
Save sumioturk/9793d22073a07c2c0e8a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Processes cpu load information from bugreport. Updates mDataset with the | |
* new data. | |
* | |
* @param br Reader providing the content | |
* @throws IOException if error reading file | |
*/ | |
void readCpuDataset(BufferedReader br) throws IOException { | |
Pattern pattern = Pattern | |
.compile("(\\S+): (\\S+)% = (.+)% user . (.+)% kernel"); | |
while (true) { | |
String line = br.readLine(); | |
if (line == null || line.startsWith("DUMP OF SERVICE")) { | |
// Done, or moved on to the next service | |
break; | |
} | |
if (line.startsWith("Load:")) { | |
mLabel.setText(line); | |
continue; | |
} | |
Matcher m = pattern.matcher(line); | |
if (m.find()) { | |
String name = m.group(1); | |
long both = Long.parseLong(m.group(2)); | |
long user = Long.parseLong(m.group(3)); | |
long kernel = Long.parseLong(m.group(4)); | |
if ("TOTAL".equals(name)) { | |
if (both < 100) { | |
mDataset.setValue("Idle", (100 - both)); | |
} | |
} else { | |
// Try to make graphs more useful even with rounding; | |
// log often has 0% user + 0% kernel = 1% total | |
// We arbitrarily give extra to kernel | |
if (user > 0) { | |
mDataset.setValue(name + " (user)", user); | |
} | |
if (kernel > 0) { | |
mDataset.setValue(name + " (kernel)" , both - user); | |
} | |
if (user == 0 && kernel == 0 && both > 0) { | |
mDataset.setValue(name, both); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment