34 public static final String event_heap_metaspace_summary = "vm/gc/heap/metaspace_summary";
35 public static final String event_reference_statistics = "vm/gc/reference/statistics";
36 public static final String event_phases_pause = "vm/gc/phases/pause";
37 public static final String event_phases_level_1 = "vm/gc/phases/pause_level_1";
38 public static final String event_phases_level_2 = "vm/gc/phases/pause_level_2";
39 public static final String event_phases_level_3 = "vm/gc/phases/pause_level_3";
40 public static final String event_phases_group = "vm/gc/phases/";
41
42 public static final String gcG1New = "G1New";
43 public static final String gcParNew = "ParNew";
44 public static final String gcDefNew = "DefNew";
45 public static final String gcParallelScavenge = "ParallelScavenge";
46 public static final String gcG1Old = "G1Old";
47 public static final String gcConcurrentMarkSweep = "ConcurrentMarkSweep";
48 public static final String gcSerialOld = "SerialOld";
49 public static final String gcPSMarkSweep = "PSMarkSweep";
50 public static final String gcParallelOld = "ParallelOld";
51
52 private static PrintStream defaultErrorLog = null;
53
54 public static long getGcId(FLREvent event) {
55 return ((Long) event.getValue("gcId")).longValue();
56 }
57
58 /**
59 * Check if this is a GC event. We count it as a GC event if it has the value "gcId".
60 */
61 public static boolean isGcEvent(FLREvent event) {
62 try {
63 event.getValue("gcId");
64 } catch (NoSuchElementException e) {
65 return false;
66 }
67 return true;
68 }
69
70
71 public static String getEventDesc(FLREvent event) {
72 if (!isGcEvent(event)) {
73 return event.getPath();
74 }
75 if (event_garbage_collection.equals(event.getPath())) {
117 collectorOverrides.add("G1Old.SerialOld");
118 collectorOverrides.add("ConcurrentMarkSweep.SerialOld");
119 collectorOverrides.add("SerialOld.PSMarkSweep");
120
121 requiredEvents.put(gcG1New, new String[] {event_heap_summary, event_young_garbage_collection});
122 requiredEvents.put(gcParNew, new String[] {event_heap_summary, event_phases_pause, event_phases_level_1, event_young_garbage_collection});
123 requiredEvents.put(gcDefNew, new String[] {event_heap_summary, event_phases_pause, event_phases_level_1, event_young_garbage_collection});
124 requiredEvents.put(gcParallelScavenge, new String[] {event_heap_summary, event_heap_ps_summary, event_reference_statistics, event_phases_pause, event_phases_level_1, event_young_garbage_collection});
125 requiredEvents.put(gcG1Old, new String[] {event_heap_summary, event_old_garbage_collection});
126 requiredEvents.put(gcConcurrentMarkSweep, new String[] {event_phases_pause, event_phases_level_1, event_old_garbage_collection});
127 requiredEvents.put(gcSerialOld, new String[] {event_heap_summary, event_phases_pause, event_phases_level_1, event_old_garbage_collection});
128 requiredEvents.put(gcParallelOld, new String[] {event_heap_summary, event_heap_ps_summary, event_reference_statistics, event_phases_pause, event_phases_level_1, event_old_garbage_collection, event_parold_garbage_collection});
129 }
130
131 /**
132 * Contains all GC events belonging to the same GC (same gcId).
133 */
134 public static class GcBatch {
135 private List<FLREvent> events = new ArrayList<FLREvent>();
136
137 public long getGcId() {
138 if (events.isEmpty()) {
139 return -1;
140 }
141 return GCHelper.getGcId(events.get(0));
142 }
143
144 public String getName() {
145 FLREvent endEvent = getEndEvent();
146 String name = "null";
147 if (endEvent != null) {
148 Object obj = endEvent.getResolvedValue("name");
149 if (obj != null) {
150 name = obj.toString();
151 }
152 }
153 return name;
154 }
155
156 public FLREvent getEndEvent() {
157 return getEvent(event_garbage_collection);
217 }
218 }
219 return String.format("GcEvent: gcId=%d, method=%s, cause=%s, startTime=%d",
220 getGcId(), name, cause, startTime);
221 }
222
223 public String getLog() {
224 StringBuilder sb = new StringBuilder();
225 sb.append(this.toString() + System.getProperty("line.separator"));
226 for (FLREvent event : events) {
227 sb.append(String.format("event: %s", getEventDesc(event)));
228 sb.append(System.getProperty("line.separator"));
229 }
230 return sb.toString();
231 }
232
233 /**
234 * Parse all events and group them into batches
235 */
236 public static List<GcBatch> createFromEvents(List<FLREvent> events) throws Exception {
237 Stack<Long> openGcIds = new Stack<Long>();
238 List<GcBatch> batches = new ArrayList<GcBatch>();
239 GcBatch currBatch = null;
240
241 for (FLREvent event : events) {
242 if (!isGcEvent(event)) {
243 continue;
244 }
245 long gcId = GCHelper.getGcId(event);
246 if (currBatch == null || currBatch.getGcId() != gcId) {
247 currBatch = null;
248 // Search for existing batch
249 for (GcBatch loopBatch : batches) {
250 if (gcId == loopBatch.getGcId()) {
251 currBatch = loopBatch;
252 break;
253 }
254 }
255 if (currBatch == null) {
256 // No existing batch. Create new.
257 currBatch = new GcBatch();
258 batches.add(currBatch);
259 openGcIds.push(new Long(gcId));
260 }
261 }
262 boolean isEndEvent = currBatch.addEvent(event);
263 if (isEndEvent) {
264 openGcIds.pop();
265 }
266 }
267 // Verify that all start_garbage_collection events have received a corresponding "garbage_collection" event.
268 for (GcBatch batch : batches) {
269 Asserts.assertNotNull(batch.getEndEvent(), "Not all gc batches closed.");
270 }
271 return batches;
272 }
273 }
274
275 /**
276 * Contains number of collections and sum pause time for young and old collections.
277 */
278 public static class CollectionSummary {
279 public long collectionCountOld;
|
34 public static final String event_heap_metaspace_summary = "vm/gc/heap/metaspace_summary";
35 public static final String event_reference_statistics = "vm/gc/reference/statistics";
36 public static final String event_phases_pause = "vm/gc/phases/pause";
37 public static final String event_phases_level_1 = "vm/gc/phases/pause_level_1";
38 public static final String event_phases_level_2 = "vm/gc/phases/pause_level_2";
39 public static final String event_phases_level_3 = "vm/gc/phases/pause_level_3";
40 public static final String event_phases_group = "vm/gc/phases/";
41
42 public static final String gcG1New = "G1New";
43 public static final String gcParNew = "ParNew";
44 public static final String gcDefNew = "DefNew";
45 public static final String gcParallelScavenge = "ParallelScavenge";
46 public static final String gcG1Old = "G1Old";
47 public static final String gcConcurrentMarkSweep = "ConcurrentMarkSweep";
48 public static final String gcSerialOld = "SerialOld";
49 public static final String gcPSMarkSweep = "PSMarkSweep";
50 public static final String gcParallelOld = "ParallelOld";
51
52 private static PrintStream defaultErrorLog = null;
53
54 public static int getGcId(FLREvent event) {
55 return ((Integer) event.getValue("gcId")).intValue();
56 }
57
58 /**
59 * Check if this is a GC event. We count it as a GC event if it has the value "gcId".
60 */
61 public static boolean isGcEvent(FLREvent event) {
62 try {
63 event.getValue("gcId");
64 } catch (NoSuchElementException e) {
65 return false;
66 }
67 return true;
68 }
69
70
71 public static String getEventDesc(FLREvent event) {
72 if (!isGcEvent(event)) {
73 return event.getPath();
74 }
75 if (event_garbage_collection.equals(event.getPath())) {
117 collectorOverrides.add("G1Old.SerialOld");
118 collectorOverrides.add("ConcurrentMarkSweep.SerialOld");
119 collectorOverrides.add("SerialOld.PSMarkSweep");
120
121 requiredEvents.put(gcG1New, new String[] {event_heap_summary, event_young_garbage_collection});
122 requiredEvents.put(gcParNew, new String[] {event_heap_summary, event_phases_pause, event_phases_level_1, event_young_garbage_collection});
123 requiredEvents.put(gcDefNew, new String[] {event_heap_summary, event_phases_pause, event_phases_level_1, event_young_garbage_collection});
124 requiredEvents.put(gcParallelScavenge, new String[] {event_heap_summary, event_heap_ps_summary, event_reference_statistics, event_phases_pause, event_phases_level_1, event_young_garbage_collection});
125 requiredEvents.put(gcG1Old, new String[] {event_heap_summary, event_old_garbage_collection});
126 requiredEvents.put(gcConcurrentMarkSweep, new String[] {event_phases_pause, event_phases_level_1, event_old_garbage_collection});
127 requiredEvents.put(gcSerialOld, new String[] {event_heap_summary, event_phases_pause, event_phases_level_1, event_old_garbage_collection});
128 requiredEvents.put(gcParallelOld, new String[] {event_heap_summary, event_heap_ps_summary, event_reference_statistics, event_phases_pause, event_phases_level_1, event_old_garbage_collection, event_parold_garbage_collection});
129 }
130
131 /**
132 * Contains all GC events belonging to the same GC (same gcId).
133 */
134 public static class GcBatch {
135 private List<FLREvent> events = new ArrayList<FLREvent>();
136
137 public int getGcId() {
138 if (events.isEmpty()) {
139 return -1;
140 }
141 return GCHelper.getGcId(events.get(0));
142 }
143
144 public String getName() {
145 FLREvent endEvent = getEndEvent();
146 String name = "null";
147 if (endEvent != null) {
148 Object obj = endEvent.getResolvedValue("name");
149 if (obj != null) {
150 name = obj.toString();
151 }
152 }
153 return name;
154 }
155
156 public FLREvent getEndEvent() {
157 return getEvent(event_garbage_collection);
217 }
218 }
219 return String.format("GcEvent: gcId=%d, method=%s, cause=%s, startTime=%d",
220 getGcId(), name, cause, startTime);
221 }
222
223 public String getLog() {
224 StringBuilder sb = new StringBuilder();
225 sb.append(this.toString() + System.getProperty("line.separator"));
226 for (FLREvent event : events) {
227 sb.append(String.format("event: %s", getEventDesc(event)));
228 sb.append(System.getProperty("line.separator"));
229 }
230 return sb.toString();
231 }
232
233 /**
234 * Parse all events and group them into batches
235 */
236 public static List<GcBatch> createFromEvents(List<FLREvent> events) throws Exception {
237 Stack<Integer> openGcIds = new Stack<Integer>();
238 List<GcBatch> batches = new ArrayList<GcBatch>();
239 GcBatch currBatch = null;
240
241 for (FLREvent event : events) {
242 if (!isGcEvent(event)) {
243 continue;
244 }
245 int gcId = GCHelper.getGcId(event);
246 if (currBatch == null || currBatch.getGcId() != gcId) {
247 currBatch = null;
248 // Search for existing batch
249 for (GcBatch loopBatch : batches) {
250 if (gcId == loopBatch.getGcId()) {
251 currBatch = loopBatch;
252 break;
253 }
254 }
255 if (currBatch == null) {
256 // No existing batch. Create new.
257 currBatch = new GcBatch();
258 batches.add(currBatch);
259 openGcIds.push(new Integer(gcId));
260 }
261 }
262 boolean isEndEvent = currBatch.addEvent(event);
263 if (isEndEvent) {
264 openGcIds.pop();
265 }
266 }
267 // Verify that all start_garbage_collection events have received a corresponding "garbage_collection" event.
268 for (GcBatch batch : batches) {
269 Asserts.assertNotNull(batch.getEndEvent(), "Not all gc batches closed.");
270 }
271 return batches;
272 }
273 }
274
275 /**
276 * Contains number of collections and sum pause time for young and old collections.
277 */
278 public static class CollectionSummary {
279 public long collectionCountOld;
|