Skip to content

Commit

Permalink
bug: preunified start time was not being set properly
Browse files Browse the repository at this point in the history
  • Loading branch information
kcpeppe committed Apr 22, 2022
1 parent 6cea993 commit 58fee5a
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ public abstract class PauseTimeAggregation extends RuntimeAggregation {
* @param duration The duration (in decimal seconds) of a GC pause.
*/
public abstract void recordPauseDuration(double duration);

public abstract void recordRuntime(double runtime);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.microsoft.gctoolkit.aggregator.EventSource;
import com.microsoft.gctoolkit.event.g1gc.G1RealPause;
import com.microsoft.gctoolkit.event.generational.GenerationalGCPauseEvent;
import com.microsoft.gctoolkit.event.jvm.JVMTermination;

/**
* An Aggregator that extracts pause time.
Expand All @@ -15,6 +16,7 @@ public PauseTimeAggregator(PauseTimeAggregation aggregation) {
super(aggregation);
register(G1RealPause.class, this::process);
register(GenerationalGCPauseEvent.class, this::record);
register(JVMTermination.class, this::record);
}

private void record(GenerationalGCPauseEvent event) {
Expand All @@ -24,4 +26,8 @@ private void record(GenerationalGCPauseEvent event) {
private void process(G1RealPause event) {
aggregation().recordPauseDuration(event.getDuration());
}

private void record(JVMTermination event) {
aggregation().recordRuntime(event.getEstimatedRuntimeDuration());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
public class PauseTimeSummary extends PauseTimeAggregation {

private double totalPauseTime;
private double runtime;

@Override
public boolean hasWarning() {
Expand All @@ -25,6 +26,11 @@ public void recordPauseDuration(double duration) {
totalPauseTime += duration;
}

@Override
public void recordRuntime(double runtime) {
this.runtime = runtime;
}

/**
* Get the total amount of time the application was paused for garbage collection.
* @return The total pause time.
Expand All @@ -38,6 +44,11 @@ public double getTotalPauseTime() {
* @return The percentage of time the application was paused.
*/
public double getPercentPaused() {
return (totalPauseTime / getRuntimeDuration()) * 100.0D;
return (totalPauseTime / runtime) * 100.0D;
}

/**
*
*/
public double getRuntime() { return runtime; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,15 @@ public void analyze(String gcLogFile) {
Assertions.assertEquals( 208922, (int)(pauseTimeSummary.getTotalPauseTime() * 1000.0d));
Assertions.assertEquals( 608797894, (int)(pauseTimeSummary.getRuntimeDuration() * 1000.0d));
Assertions.assertEquals( 34, (int)(pauseTimeSummary.getPercentPaused() * 1000d));
Assertions.assertEquals(608797.886d, pauseTimeSummary.getRuntime());
});

}

private int initialMarkCount = 0;
private int remarkCount = 0;
private int defNewCount = 0;
private double runtime = 0.0d;

public int getInitialMarkCount() {
return initialMarkCount;
Expand All @@ -103,4 +105,8 @@ public int getDefNewCount() {
return defNewCount;
}

public double getRuntime() {
return runtime;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.microsoft.gctoolkit.integration.core;

import com.microsoft.gctoolkit.GCToolKit;
import com.microsoft.gctoolkit.integration.io.TestLogFile;
import com.microsoft.gctoolkit.io.GCLogFile;
import com.microsoft.gctoolkit.io.SingleGCLogFile;
import com.microsoft.gctoolkit.io.SingleGCLogFile;
import com.microsoft.gctoolkit.jvm.JavaVirtualMachine;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.io.IOException;

import static org.junit.jupiter.api.Assertions.fail;

public class PreunifiedJavaVirtualMachineConfigurationTest {

private String logFile = "preunified/g1gc/details/tenuring/180/g1gc.log";
private int[] times = { 0, 1028, 945481, 945481};

@Test
public void testSingle() {
TestLogFile log = new TestLogFile(logFile);
test(new SingleGCLogFile(log.getFile().toPath()), times);
}

private void test(GCLogFile log, int[] endStartTimes ) {
GCToolKit gcToolKit = new GCToolKit();
gcToolKit.loadAggregationsFromServiceLoader();
JavaVirtualMachine machine = null;
try {
machine = gcToolKit.analyze(log);
} catch (IOException e) {
fail(e.getMessage());
}
System.out.println("************************************************************");
Assertions.assertEquals( endStartTimes[0], (int)(machine.getEstimatedJVMStartTime().getTimeStamp() * 1000.0d));
Assertions.assertEquals( endStartTimes[1], (int)(machine.getTimeOfFirstEvent().getTimeStamp() * 1000.0d));
Assertions.assertEquals( endStartTimes[2], (int)(machine.getJVMTerminationTime().getTimeStamp() * 1000.0d));
Assertions.assertEquals( endStartTimes[3], (int)(machine.getRuntimeDuration() * 1000.0d));
System.out.println("************************************************************");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

import static org.junit.jupiter.api.Assertions.fail;

public class JavaVirtualMachineConfigurationTest {
public class UnifiedJavaVirtualMachineConfigurationTest {

private String logFile = "rolling/jdk14/rollinglogs/long_restart.log";
private int[][] times = { { 0, 13, 262172, 262172}, { 259077, 259077, 262172, 3095}};
Expand Down

0 comments on commit 58fee5a

Please sign in to comment.