94 return result;
95 }
96
97 private static String gcName(FLREvent e) throws Exception {
98 FLRStruct s = (FLRStruct) e.getResolvedValue("name");
99 return (String) s.getValue("name");
100 }
101
102 private static List<FLREvent> filterEventsOnCollector(List<FLREvent> events, String name)
103 throws Exception {
104 List<FLREvent> result = new ArrayList<FLREvent>();
105 List<FLREvent> allGCEvents = filterEventsOnPath(events, gcEventPath);
106 for (FLREvent e : allGCEvents) {
107 if (gcName(e).equals(name)) {
108 result.add(e);
109 }
110 }
111 return result;
112 }
113
114 private static Long getGCIdFromEvent(FLREvent e) throws Exception {
115 return (Long) e.getValue("gcId");
116 }
117
118 private static List<FLREvent> filterRefProcEventsByGcId(List<FLREvent> events, Long id)
119 throws Exception {
120 List<FLREvent> result = new ArrayList<FLREvent>();
121 for (FLREvent e : events) {
122 if (getGCIdFromEvent(e).equals(id)) {
123 result.add(e);
124 }
125 }
126 return result;
127 }
128
129 private static List<Long> mapGCEventsToIds(List<FLREvent> events) throws Exception {
130 List<Long> gcIds = new ArrayList<Long>();
131 for (FLREvent e : events) {
132 gcIds.add(getGCIdFromEvent(e));
133 }
134 return gcIds;
135 }
136
137 private static List<List<FLREvent>> groupRefStatEventsByGCId(List<FLREvent> allEvents, List<FLREvent> gcEvents)
138 throws Exception {
139 List<Long> gcIds = mapGCEventsToIds(gcEvents);
140 List<FLREvent> refProcEvents = filterEventsOnPath(allEvents, refStatsEventPath);
141 List<List<FLREvent>> result = new ArrayList<List<FLREvent>>();
142 for (Long l : gcIds) {
143 List<FLREvent> events = filterRefProcEventsByGcId(refProcEvents, l);
144 if (events.size() > 0) {
145 result.add(events);
146 }
147 }
148 return result;
149 }
150
151 private static String referenceType(FLREvent e) throws Exception {
152 FLRStruct s = (FLRStruct) e.getResolvedValue("type");
153 return (String) s.getValue("type");
154 }
155
156 private static void assertReferenceType(HashSet<String> types, String type, Long gcId)
157 throws Exception {
158 assertTrue(types.contains(type + " reference"),
159 "Expected " + refStatsEventPath + " event with type " + type +
160 " reference for gc with id " + gcId);
161 assertNE(gcId, -1, "Expected " + refStatsEventPath + " to have a gcId");
162 }
163
164 private static void verifyRefStatEvents(List<FLREvent> events) throws Exception {
165 HashSet<String> types = new HashSet<String>();
166 long gcId = -1;
167 for (FLREvent e : events) {
168 types.add(referenceType(e));
169 gcId = getGCIdFromEvent(e); // all the event should have the same gcId
170 }
171 assertReferenceType(types, "Soft", gcId);
172 assertReferenceType(types, "Weak", gcId);
173 assertReferenceType(types, "Final", gcId);
174 assertReferenceType(types, "Phantom", gcId);
175 }
176
177 private static List<FLREvent> filterOutBadCMSEvents(List<FLREvent> events, String gcName) throws Exception {
178 List<FLREvent> cmsEvents = filterEventsOnCollector(events, gcName);
179 assertTrue(cmsEvents.size() == 1 || cmsEvents.size() == 2,
180 "Expected exactly one or two " + gcEventPath + " event(s) from concurrent CMS collector");
181
182 if (cmsEvents.size() == 2) {
183 // No need to filter any events since we got GC events for both
184 // System.gc() calls.
185 return events;
186 }
187
188 List<FLREvent> gcEvents = filterEventsOnPath(events, gcEventPath);
189
190 List<Long> gcIds = mapGCEventsToIds(gcEvents);
191 Long largestGCId = 0L;
192 for (Long gcId : gcIds) {
193 if (gcId > largestGCId) {
194 largestGCId = gcId;
195 }
196 }
197
198 List<FLREvent> result = new ArrayList<FLREvent>();
199 for (FLREvent e : events) {
200 String path = e.getPath();
201 if (path.startsWith("vm/gc/") && !path.startsWith("vm/gc/configuration")) {
202 if (getGCIdFromEvent(e) == largestGCId + 1) {
203 // this event comes from "dangling" CMS collection
204 } else {
205 result.add(e);
206 }
207 }
208 }
209 return result;
210 }
211
212 public static void main(String[] args) throws Exception {
|
94 return result;
95 }
96
97 private static String gcName(FLREvent e) throws Exception {
98 FLRStruct s = (FLRStruct) e.getResolvedValue("name");
99 return (String) s.getValue("name");
100 }
101
102 private static List<FLREvent> filterEventsOnCollector(List<FLREvent> events, String name)
103 throws Exception {
104 List<FLREvent> result = new ArrayList<FLREvent>();
105 List<FLREvent> allGCEvents = filterEventsOnPath(events, gcEventPath);
106 for (FLREvent e : allGCEvents) {
107 if (gcName(e).equals(name)) {
108 result.add(e);
109 }
110 }
111 return result;
112 }
113
114 private static Integer getGCIdFromEvent(FLREvent e) throws Exception {
115 return (Integer) e.getValue("gcId");
116 }
117
118 private static List<FLREvent> filterRefProcEventsByGcId(List<FLREvent> events, Integer id)
119 throws Exception {
120 List<FLREvent> result = new ArrayList<FLREvent>();
121 for (FLREvent e : events) {
122 if (getGCIdFromEvent(e).equals(id)) {
123 result.add(e);
124 }
125 }
126 return result;
127 }
128
129 private static List<Integer> mapGCEventsToIds(List<FLREvent> events) throws Exception {
130 List<Integer> gcIds = new ArrayList<Integer>();
131 for (FLREvent e : events) {
132 gcIds.add(getGCIdFromEvent(e));
133 }
134 return gcIds;
135 }
136
137 private static List<List<FLREvent>> groupRefStatEventsByGCId(List<FLREvent> allEvents, List<FLREvent> gcEvents)
138 throws Exception {
139 List<Integer> gcIds = mapGCEventsToIds(gcEvents);
140 List<FLREvent> refProcEvents = filterEventsOnPath(allEvents, refStatsEventPath);
141 List<List<FLREvent>> result = new ArrayList<List<FLREvent>>();
142 for (Integer id : gcIds) {
143 List<FLREvent> events = filterRefProcEventsByGcId(refProcEvents, id);
144 if (events.size() > 0) {
145 result.add(events);
146 }
147 }
148 return result;
149 }
150
151 private static String referenceType(FLREvent e) throws Exception {
152 FLRStruct s = (FLRStruct) e.getResolvedValue("type");
153 return (String) s.getValue("type");
154 }
155
156 private static void assertReferenceType(HashSet<String> types, String type, Integer gcId)
157 throws Exception {
158 assertTrue(types.contains(type + " reference"),
159 "Expected " + refStatsEventPath + " event with type " + type +
160 " reference for gc with id " + gcId);
161 assertNE(gcId, -1, "Expected " + refStatsEventPath + " to have a gcId");
162 }
163
164 private static void verifyRefStatEvents(List<FLREvent> events) throws Exception {
165 HashSet<String> types = new HashSet<String>();
166 int gcId = -1;
167 for (FLREvent e : events) {
168 types.add(referenceType(e));
169 gcId = getGCIdFromEvent(e); // all the event should have the same gcId
170 }
171 assertReferenceType(types, "Soft", gcId);
172 assertReferenceType(types, "Weak", gcId);
173 assertReferenceType(types, "Final", gcId);
174 assertReferenceType(types, "Phantom", gcId);
175 }
176
177 private static List<FLREvent> filterOutBadCMSEvents(List<FLREvent> events, String gcName) throws Exception {
178 List<FLREvent> cmsEvents = filterEventsOnCollector(events, gcName);
179 assertTrue(cmsEvents.size() == 1 || cmsEvents.size() == 2,
180 "Expected exactly one or two " + gcEventPath + " event(s) from concurrent CMS collector");
181
182 if (cmsEvents.size() == 2) {
183 // No need to filter any events since we got GC events for both
184 // System.gc() calls.
185 return events;
186 }
187
188 List<FLREvent> gcEvents = filterEventsOnPath(events, gcEventPath);
189
190 List<Integer> gcIds = mapGCEventsToIds(gcEvents);
191 Integer largestGCId = 0;
192 for (Integer gcId : gcIds) {
193 if (gcId > largestGCId) {
194 largestGCId = gcId;
195 }
196 }
197
198 List<FLREvent> result = new ArrayList<FLREvent>();
199 for (FLREvent e : events) {
200 String path = e.getPath();
201 if (path.startsWith("vm/gc/") && !path.startsWith("vm/gc/configuration")) {
202 if (getGCIdFromEvent(e) == largestGCId + 1) {
203 // this event comes from "dangling" CMS collection
204 } else {
205 result.add(e);
206 }
207 }
208 }
209 return result;
210 }
211
212 public static void main(String[] args) throws Exception {
|