61 |
61 |
62 if (lines.length == 0) { |
62 if (lines.length == 0) { |
63 throwTestException("Failed to parse jcmd output"); |
63 throwTestException("Failed to parse jcmd output"); |
64 } |
64 } |
65 |
65 |
66 int totalCommitted = 0, totalReserved = 0; |
66 long totalCommitted = 0, totalReserved = 0; |
67 int totalCommittedSum = 0, totalReservedSum = 0; |
67 long totalCommittedSum = 0, totalReservedSum = 0; |
68 |
68 |
69 // Match '- <mtType> (reserved=<reserved>KB, committed=<committed>KB) |
69 // Match '- <mtType> (reserved=<reserved>KB, committed=<committed>KB) |
70 Pattern mtTypePattern = Pattern.compile("-\\s+(?<typename>[\\w\\s]+)\\(reserved=(?<reserved>\\d+)KB,\\scommitted=(?<committed>\\d+)KB\\)"); |
70 Pattern mtTypePattern = Pattern.compile("-\\s+(?<typename>[\\w\\s]+)\\(reserved=(?<reserved>\\d+)KB,\\scommitted=(?<committed>\\d+)KB\\)"); |
71 // Match 'Total: reserved=<reserved>KB, committed=<committed>KB' |
71 // Match 'Total: reserved=<reserved>KB, committed=<committed>KB' |
72 Pattern totalMemoryPattern = Pattern.compile("Total\\:\\sreserved=(?<reserved>\\d+)KB,\\scommitted=(?<committed>\\d+)KB"); |
72 Pattern totalMemoryPattern = Pattern.compile("Total\\:\\sreserved=(?<reserved>\\d+)KB,\\scommitted=(?<committed>\\d+)KB"); |
74 for (int i = 0; i < lines.length; i++) { |
74 for (int i = 0; i < lines.length; i++) { |
75 if (lines[i].startsWith("Total")) { |
75 if (lines[i].startsWith("Total")) { |
76 Matcher totalMemoryMatcher = totalMemoryPattern.matcher(lines[i]); |
76 Matcher totalMemoryMatcher = totalMemoryPattern.matcher(lines[i]); |
77 |
77 |
78 if (totalMemoryMatcher.matches()) { |
78 if (totalMemoryMatcher.matches()) { |
79 totalCommitted = Integer.parseInt(totalMemoryMatcher.group("committed")); |
79 totalCommitted = Long.parseLong(totalMemoryMatcher.group("committed")); |
80 totalReserved = Integer.parseInt(totalMemoryMatcher.group("reserved")); |
80 totalReserved = Long.parseLong(totalMemoryMatcher.group("reserved")); |
81 } else { |
81 } else { |
82 throwTestException("Failed to match the expected groups in 'Total' memory part"); |
82 throwTestException("Failed to match the expected groups in 'Total' memory part"); |
83 } |
83 } |
84 } else if (lines[i].startsWith("-")) { |
84 } else if (lines[i].startsWith("-")) { |
85 Matcher typeMatcher = mtTypePattern.matcher(lines[i]); |
85 Matcher typeMatcher = mtTypePattern.matcher(lines[i]); |
86 if (typeMatcher.matches()) { |
86 if (typeMatcher.matches()) { |
87 int typeCommitted = Integer.parseInt(typeMatcher.group("committed")); |
87 long typeCommitted = Long.parseLong(typeMatcher.group("committed")); |
88 int typeReserved = Integer.parseInt(typeMatcher.group("reserved")); |
88 long typeReserved = Long.parseLong(typeMatcher.group("reserved")); |
89 |
89 |
90 // Make sure reserved is always less or equals |
90 // Make sure reserved is always less or equals |
91 if (typeCommitted > typeReserved) { |
91 if (typeCommitted > typeReserved) { |
92 throwTestException("Committed (" + typeCommitted + ") was more than Reserved (" |
92 throwTestException("Committed (" + typeCommitted + ") was more than Reserved (" |
93 + typeReserved + ") for mtType: " + typeMatcher.group("typename")); |
93 + typeReserved + ") for mtType: " + typeMatcher.group("typename")); |
101 } |
101 } |
102 } |
102 } |
103 } |
103 } |
104 |
104 |
105 // See if they add up correctly, rounding is a problem so make sure we're within +/- 8KB |
105 // See if they add up correctly, rounding is a problem so make sure we're within +/- 8KB |
106 int committedDiff = totalCommitted - totalCommittedSum; |
106 long committedDiff = totalCommitted - totalCommittedSum; |
107 if (committedDiff > 8 || committedDiff < -8) { |
107 if (committedDiff > 8 || committedDiff < -8) { |
108 throwTestException("Total committed (" + totalCommitted + ") did not match the summarized committed (" + totalCommittedSum + ")" ); |
108 throwTestException("Total committed (" + totalCommitted + ") did not match the summarized committed (" + totalCommittedSum + ")" ); |
109 } |
109 } |
110 |
110 |
111 int reservedDiff = totalReserved - totalReservedSum; |
111 long reservedDiff = totalReserved - totalReservedSum; |
112 if (reservedDiff > 8 || reservedDiff < -8) { |
112 if (reservedDiff > 8 || reservedDiff < -8) { |
113 throwTestException("Total reserved (" + totalReserved + ") did not match the summarized reserved (" + totalReservedSum + ")" ); |
113 throwTestException("Total reserved (" + totalReserved + ") did not match the summarized reserved (" + totalReservedSum + ")" ); |
114 } |
114 } |
115 } |
115 } |
116 |
116 |