Skip to content

Commit

Permalink
Added notion of phases in AbstractGcEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
yanqilee committed Mar 1, 2019
1 parent ad1ca4b commit 0eb52d4
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 20 deletions.
Expand Up @@ -36,6 +36,7 @@ public abstract class AbstractGCEvent<T extends AbstractGCEvent<T>> implements S
protected List<T> details;
private double pause;
private int number = -1;
private List<T> phases;

public Iterator<T> details() {
if (details == null) return Collections.emptyIterator();
Expand All @@ -59,6 +60,24 @@ public boolean hasDetails() {
&& details.size() > 0;
}

public List<T> getPhases() {
if (this.phases == null) {
return new ArrayList<>();
}
return phases;
}

public void addPhases(T phase) {
if (phase == null) {
throw new IllegalArgumentException("Cannot add null phase to an event");
}
if (this.phases == null) {
this.phases = new ArrayList<>();
}

phases.add(phase);
}

@Override
protected Object clone() throws CloneNotSupportedException {
AbstractGCEvent<T> clonedEvent = (AbstractGCEvent<T>)super.clone();
Expand Down
@@ -1,6 +1,7 @@
package com.tagtraum.perf.gcviewer.model;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertThat;

import com.tagtraum.perf.gcviewer.model.AbstractGCEvent.ExtendedType;
Expand All @@ -11,7 +12,7 @@

/**
* Tests for methods written in {@link AbstractGCEvent}.
*
*
* @author <a href="mailto:gcviewer@gmx.ch">Joerg Wuethrich</a>
* <p>created on: 30.09.2012</p>
*/
Expand All @@ -25,12 +26,12 @@ public void getGenerationParNew() {

GCEvent parNewEvent = new GCEvent();
parNewEvent.setType(Type.PAR_NEW);

event.add(parNewEvent);

assertEquals("generation", Generation.YOUNG, event.getGeneration());
}

@Test
public void getGenerationCmsInitialMark() {
// 6.765: [GC [1 CMS-initial-mark: 0K(25165824K)] 410644K(47815104K), 0.0100670 secs] [Times: user=0.01 sys=0.00, real=0.01 secs]
Expand All @@ -39,12 +40,12 @@ public void getGenerationCmsInitialMark() {

GCEvent CmsInitialMarkEvent = new GCEvent();
CmsInitialMarkEvent.setType(Type.CMS_INITIAL_MARK);

event.add(CmsInitialMarkEvent);

assertEquals("generation", Generation.TENURED, event.getGeneration());
}

@Test
public void getGenerationCmsRemark() {
// 12.203: [GC[YG occupancy: 11281900 K (22649280 K)]12.203: [Rescan (parallel) , 0.3773770 secs]12.580: [weak refs processing, 0.0000310 secs]12.580: [class unloading, 0.0055480 secs]12.586: [scrub symbol & string tables, 0.0041920 secs] [1 CMS-remark: 0K(25165824K)] 11281900K(47815104K), 0.3881550 secs] [Times: user=17.73 sys=0.04, real=0.39 secs]
Expand All @@ -53,12 +54,12 @@ public void getGenerationCmsRemark() {

GCEvent CmsRemarkEvent = new GCEvent();
CmsRemarkEvent.setType(Type.CMS_REMARK);

event.add(CmsRemarkEvent);

assertEquals("generation", Generation.TENURED, event.getGeneration());
}

@Test
public void getGenerationConcurrentMarkStart() {
// 3749.995: [CMS-concurrent-mark-start]
Expand All @@ -67,7 +68,7 @@ public void getGenerationConcurrentMarkStart() {

assertEquals("generation", Generation.TENURED, event.getGeneration());
}

@Test
public void getGenerationFullGc() {
// 2012-04-07T01:14:29.222+0000: 37571.083: [Full GC [PSYoungGen: 21088K->0K(603712K)] [PSOldGen: 1398086K->214954K(1398144K)] 1419174K->214954K(2001856K) [PSPermGen: 33726K->33726K(131072K)], 0.4952250 secs] [Times: user=0.49 sys=0.00, real=0.49 secs]
Expand All @@ -77,42 +78,76 @@ public void getGenerationFullGc() {
GCEvent detailedEvent = new GCEvent();
detailedEvent.setType(Type.PS_YOUNG_GEN);
event.add(detailedEvent);

detailedEvent = new GCEvent();
detailedEvent.setType(Type.PS_OLD_GEN);
event.add(detailedEvent);

detailedEvent = new GCEvent();
detailedEvent.setType(Type.PS_PERM_GEN);
event.add(detailedEvent);

assertEquals("generation", Generation.ALL, event.getGeneration());
}

@Test
public void addExtendedTypePrintGcCause() {
// 2013-05-25T17:02:46.238+0200: 0.194: [GC (Allocation Failure) [PSYoungGen: 16430K->2657K(19136K)] 16430K->15759K(62848K), 0.0109373 secs] [Times: user=0.05 sys=0.02, real=0.02 secs]
GCEvent event = new GCEvent();
event.setExtendedType(ExtendedType.lookup(Type.GC, "GC (Allocation Failure)"));

GCEvent detailedEvent = new GCEvent();
detailedEvent.setType(Type.PS_YOUNG_GEN);

event.add(detailedEvent);

assertEquals("typeAsString", "GC (Allocation Failure); PSYoungGen", event.getTypeAsString());
}

@Test
public void isFullShenandoah() throws Exception {
AbstractGCEvent event = getNewAbstractEvent();

event.setType(Type.UJL_PAUSE_FULL);
assertThat("should be full gc", event.isFull(), Matchers.is(true));
}

@Test
public void testInitialPhaseList() {
AbstractGCEvent event = getNewAbstractEvent();

assertTrue("phases list is empty", event.getPhases().isEmpty());
}

@Test(expected = IllegalArgumentException.class)
public void testZgcAddNullPhase() {
AbstractGCEvent event = getNewAbstractEvent();
event.addPhases(null);

assertTrue("phases list is empty", event.getPhases().isEmpty());
}

@Test
public void testZgcAddValidPhase() {
AbstractGCEvent event = getNewAbstractEvent();

GCEvent phaseEvent = new GCEvent();
phaseEvent.setType(Type.UJL_ZGC_PAUSE_MARK_START);

event.addPhases(phaseEvent);

assertEquals("number of phase events", 1, event.getPhases().size());
assertEquals("get phase event", phaseEvent, event.getPhases().get(0));
}

private AbstractGCEvent getNewAbstractEvent() {
AbstractGCEvent event = new AbstractGCEvent() {
@Override
public void toStringBuffer(StringBuffer sb) {
// do nothing
}
};

event.setType(Type.UJL_PAUSE_FULL);
assertThat("should be full gc", event.isFull(), Matchers.is(true));
return event;
}
}

0 comments on commit 0eb52d4

Please sign in to comment.