Skip to content
Snippets Groups Projects
Commit da7b04ca authored by Michael Rosenfeld's avatar Michael Rosenfeld Committed by Android (Google) Code Review
Browse files

Merge "Add new parsed fields to the compact meminfo parser."

parents 7e8dea6d 56ced067
No related branches found
No related tags found
No related merge requests found
......@@ -37,6 +37,10 @@ public class CompactMemInfoItem implements IItem {
public static final String ACTIVITIES_JSON_KEY = "activities";
public static final String PROCESSES_JSON_KEY = "processes";
public static final String LOST_RAM_JSON_KEY = "lostRam";
public static final String TOTAL_ZRAM_JSON_KEY = "totalZram";
public static final String FREE_SWAP_ZRAM_JSON_KEY = "freeSwapZram";
public static final String FREE_RAM_JSON_KEY = "freeRam";
public static final String TUNING_LEVEL_JSON_KEY = "tuningLevel";
/** Constants for attributes HashMap */
private static final String NAME_ATTR_KEY = "name";
private static final String PSS_ATTR_KEY = "pss";
......@@ -45,7 +49,11 @@ public class CompactMemInfoItem implements IItem {
private static final String ACTIVITIES_ATTR_KEY = "activities";
private Map<Integer, Map<String, Object>> mPids = new HashMap<Integer, Map<String, Object>>();
private long mFreeRam;
private long mFreeSwapZram;
private long mLostRam;
private long mTotalZram;
private long mTuningLevel;
@Override
public IItem merge(IItem other) throws ConflictingItemException {
......@@ -78,8 +86,12 @@ public class CompactMemInfoItem implements IItem {
}
try {
object.put(PROCESSES_JSON_KEY, processes);
// Add the lost RAM field
// Add the additional non-process field
object.put(LOST_RAM_JSON_KEY, getLostRam());
object.put(TOTAL_ZRAM_JSON_KEY, getTotalZram());
object.put(FREE_SWAP_ZRAM_JSON_KEY, getFreeSwapZram());
object.put(FREE_RAM_JSON_KEY, getFreeRam());
object.put(TUNING_LEVEL_JSON_KEY, getTuningLevel());
} catch (JSONException e) {
// ignore
}
......@@ -161,4 +173,44 @@ public class CompactMemInfoItem implements IItem {
public long getLostRam() {
return mLostRam;
}
/** Sets the free RAM field */
public void setFreeRam(long freeRam) {
mFreeRam = freeRam;
}
/** Returns the free RAM field */
public long getFreeRam() {
return mFreeRam;
}
/** Sets the total ZRAM field */
public void setTotalZram(long totalZram) {
mTotalZram = totalZram;
}
/** Returns the total ZRAM field */
public long getTotalZram() {
return mTotalZram;
}
/** Sets the free swap ZRAM field */
public void setFreeSwapZram(long freeSwapZram) {
mFreeSwapZram = freeSwapZram;
}
/** Returns the free swap ZRAM field */
public long getFreeSwapZram() {
return mFreeSwapZram;
}
/** Sets the tuning level field */
public void setTuningLevel(long tuningLevel) {
mTuningLevel = tuningLevel;
}
/** Returns the tuning level field */
public long getTuningLevel() {
return mTuningLevel;
}
}
......@@ -37,10 +37,12 @@ import java.util.regex.Pattern;
*
*/
public class CompactMemInfoParser implements IParser {
private static final Pattern PROC_PREFIX = Pattern.compile(
"proc,(\\w+),([a-zA-Z_0-9\\.]+),(\\d+),(\\d+),((\\S+),)?(.*)");
private static final Pattern LOST_RAM_PREFIX = Pattern.compile(
"lostram,(.+)");
private static final Pattern PROC_PATTERN =
Pattern.compile("proc,(\\w+),([a-zA-Z_0-9\\.]+),(\\d+),(\\d+),((\\S+),)?(.*)");
private static final Pattern LOST_RAM_PATTERN = Pattern.compile("lostram,(\\d+)");
private static final Pattern RAM_PATTERN = Pattern.compile("ram,(\\d+),(\\d+),(\\d+)");
private static final Pattern ZRAM_PATTERN = Pattern.compile("zram,(\\d+),(\\d+),(\\d+)");
private static final Pattern TUNING_PATTERN = Pattern.compile("tuning,(\\d+),(\\d+),(\\d+).*");
/**
* Parse compact meminfo log. Output a CompactMemInfoItem which contains
......@@ -50,7 +52,7 @@ public class CompactMemInfoParser implements IParser {
public CompactMemInfoItem parse(List<String> lines) {
CompactMemInfoItem item = new CompactMemInfoItem();
for (String line : lines) {
Matcher m = PROC_PREFIX.matcher(line);
Matcher m = PROC_PATTERN.matcher(line);
if (m.matches()) {
String type = m.group(1);
String name = m.group(2);
......@@ -69,9 +71,8 @@ public class CompactMemInfoParser implements IParser {
}
}
m = LOST_RAM_PREFIX.matcher(line);
m = LOST_RAM_PATTERN.matcher(line);
if (m.matches()) {
String name = "Lost RAM";
try {
long lostRam = Long.parseLong(m.group(1));
item.setLostRam(lostRam);
......@@ -80,6 +81,37 @@ public class CompactMemInfoParser implements IParser {
// ignore exception
}
}
m = RAM_PATTERN.matcher(line);
if (m.matches()) {
try {
item.setFreeRam(Long.parseLong(m.group(2)));
continue;
} catch (NumberFormatException nfe) {
// ignore exception
}
}
m = ZRAM_PATTERN.matcher(line);
if (m.matches()) {
try {
item.setTotalZram(Long.parseLong(m.group(1)));
item.setFreeSwapZram(Long.parseLong(m.group(3)));
continue;
} catch (NumberFormatException nfe) {
// ignore exception
}
}
m = TUNING_PATTERN.matcher(line);
if (m.matches()) {
try {
item.setTuningLevel(Long.parseLong(m.group(3)));
continue;
} catch (NumberFormatException nfe) {
// ignore exception
}
}
}
return item;
}
......
......@@ -74,14 +74,49 @@ public class CompactMemInfoParserTest extends TestCase {
assertEquals(1005, item.getLostRam());
}
public void testSingleRamLine() {
List<String> input = Arrays.asList("ram,2866484,1221694,1112777");
CompactMemInfoItem item = new CompactMemInfoParser().parse(input);
assertEquals(1221694, item.getFreeRam());
}
public void testSingleZramLine() {
List<String> input = Arrays.asList("zram,5800,520908,491632");
CompactMemInfoItem item = new CompactMemInfoParser().parse(input);
assertEquals(5800, item.getTotalZram());
assertEquals(491632, item.getFreeSwapZram());
}
public void testSingleTuningLine() {
// With specific configuration
List<String> input1 = Arrays.asList("tuning,192,512,322560,high-end-gfx");
CompactMemInfoItem item1 = new CompactMemInfoParser().parse(input1);
assertEquals(322560, item1.getTuningLevel());
// Without specific configuration
List<String> input2 = Arrays.asList("tuning,193,513,322561");
CompactMemInfoItem item2 = new CompactMemInfoParser().parse(input2);
assertEquals(322561, item2.getTuningLevel());
}
public void testSomeMalformedLines() {
List<String> input = Arrays.asList(
List<String> input =
Arrays.asList(
"proc,cached,com.google.android.youtube,a,b,e",
"proc,cached,com.google.android.youtube,2964,c,e",
"proc,cached,com.google.android.youtube,2964,e",
"proc,cached,com.google.android.youtube,2964,19345,a,e",
"lostram,a,1000",
"lostram,1000,a");
"lostram,1000,a",
"ram,123,345",
"ram,123,345,abc",
"ram,123,345,456,678",
"ram,123,345,456,abc",
"zram,123,345",
"zram,123,345,abc",
"zram,123,345,456,678",
"zram,123,345,456,abc",
"tuning,123,345",
"tuning,123,345,abc");
CompactMemInfoItem item = new CompactMemInfoParser().parse(input);
......@@ -89,13 +124,17 @@ public class CompactMemInfoParserTest extends TestCase {
}
public void testMultipleLines() {
List<String> input = Arrays.asList(
List<String> input =
Arrays.asList(
"proc,cached,com.google.android.youtube,2964,19345,123,e",
"proc,cached,com.google.android.apps.plus,2877,9604,N/A,e",
"proc,cached,com.google.android.apps.magazines,2009,20111,N/A,e",
"proc,cached,com.google.android.apps.walletnfcrel,10790,11164,100,e",
"proc,cached,com.google.android.incallui,3410,9491,N/A,e",
"lostram,1005");
"lostram,1005",
"ram,2866484,1221694,1112777",
"zram,5800,520908,491632",
"tuning,193,513,322561");
CompactMemInfoItem item = new CompactMemInfoParser().parse(input);
......@@ -107,6 +146,10 @@ public class CompactMemInfoParserTest extends TestCase {
assertEquals(false, item.hasActivities(2964));
assertEquals(1005, item.getLostRam());
assertEquals(1221694, item.getFreeRam());
assertEquals(5800, item.getTotalZram());
assertEquals(491632, item.getFreeSwapZram());
assertEquals(322561, item.getTuningLevel());
}
public void testSkipNonProcLines() {
......@@ -132,7 +175,8 @@ public class CompactMemInfoParserTest extends TestCase {
}
public void testJson() throws JSONException {
List<String> input = Arrays.asList(
List<String> input =
Arrays.asList(
"oom,cached,141357",
"proc,cached,com.google.android.youtube,2964,19345,N/A,e",
"proc,cached,com.google.android.apps.plus,2877,9604,50,e",
......@@ -140,6 +184,9 @@ public class CompactMemInfoParserTest extends TestCase {
"proc,cached,com.google.android.apps.walletnfcrel,10790,11164,0,e",
"proc,cached,com.google.android.incallui,3410,9491,500,e",
"lostram,1005",
"ram,2866484,1221694,1112777",
"zram,5800,520908,491632",
"tuning,193,513,322561",
"cat,Native,63169");
CompactMemInfoItem item = new CompactMemInfoParser().parse(input);
......@@ -150,5 +197,9 @@ public class CompactMemInfoParserTest extends TestCase {
assertEquals(5, processes.length());
assertEquals(1005, (long)json.get("lostRam"));
assertEquals(1221694, (long) json.get("freeRam"));
assertEquals(5800, (long) json.get("totalZram"));
assertEquals(491632, (long) json.get("freeSwapZram"));
assertEquals(322561, (long) json.get("tuningLevel"));
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment