From b06ecedfd3442b76e1cfec0ebf89c30ffee25568 Mon Sep 17 00:00:00 2001 From: Kirk Pepperdine Date: Wed, 15 Feb 2023 12:39:23 -0800 Subject: [PATCH 1/3] debug: push a funny 3x pub problem --- .../integration/MissingAnnotationTest.java | 92 +++++++++++++++++++ .../jvm/AbstractJavaVirtualMachine.java | 17 ++-- 2 files changed, 103 insertions(+), 6 deletions(-) create mode 100644 IT/src/test/java/com/microsoft/gctoolkit/integration/MissingAnnotationTest.java diff --git a/IT/src/test/java/com/microsoft/gctoolkit/integration/MissingAnnotationTest.java b/IT/src/test/java/com/microsoft/gctoolkit/integration/MissingAnnotationTest.java new file mode 100644 index 00000000..025fa0d2 --- /dev/null +++ b/IT/src/test/java/com/microsoft/gctoolkit/integration/MissingAnnotationTest.java @@ -0,0 +1,92 @@ +package com.microsoft.gctoolkit.integration; + +import com.microsoft.gctoolkit.GCToolKit; +import com.microsoft.gctoolkit.aggregator.Aggregates; +import com.microsoft.gctoolkit.aggregator.Aggregation; +import com.microsoft.gctoolkit.aggregator.Aggregator; +import com.microsoft.gctoolkit.aggregator.Collates; +import com.microsoft.gctoolkit.aggregator.EventSource; +import com.microsoft.gctoolkit.integration.aggregation.CollectionCycleCountsSummary; +import com.microsoft.gctoolkit.integration.aggregation.HeapOccupancyAfterCollectionSummary; +import com.microsoft.gctoolkit.integration.io.TestLogFile; +import com.microsoft.gctoolkit.io.GCLogFile; +import com.microsoft.gctoolkit.io.SingleGCLogFile; +import com.microsoft.gctoolkit.jvm.JavaVirtualMachine; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; + +import java.io.IOException; +import java.nio.file.Path; + +import static org.junit.jupiter.api.Assertions.fail; + +@Tag("modulePath") +public class MissingAnnotationTest { + + private void workFlow( Aggregation aggregation, Class clazz) { + GCToolKit gcToolKit = new GCToolKit(); + // Load our test aggregation instead of calling GCToolKit::loadAggregationsFromServiceLoader + gcToolKit.loadAggregation(aggregation); + JavaVirtualMachine machine = null; + try { + machine = gcToolKit.analyze(new SingleGCLogFile(new TestLogFile("cms/defnew/details/defnew.log").getFile().toPath())); + } catch (IOException e) { + fail(e.getMessage()); + } + Assertions.assertTrue(machine.getAggregation(clazz).isEmpty()); + } + + @Tag("modulePath") + @Test + public void testNoAggregationRegistered() { + workFlow(new MissingAnnotationAggregation(), MissingAnnotationTest.MissingAnnotationAggregation.class); + } + + @Tag("modulePath") + @Test + public void testSuppliedAggregation() { + workFlow(new MissingEventSource(), MissingAnnotationTest.MissingEventSource.class); + } + + /************* Aggregator/Aggregation with missing Collates annotation */ + public static class MissingAnnotationAggregation extends Aggregation { + + @Override + public boolean hasWarning() { + return false; + } + + @Override + public boolean isEmpty() { + return false; + } + } + + @Aggregates(EventSource.G1GC) + public static class TestAggregator extends Aggregator { + protected TestAggregator(MissingAnnotationAggregation aggregation) { + super(aggregation); + } + } + + /************* Aggregator/Aggregation with missing Aggregates annotation */ + @Collates(MissingAnnotationAggregator.class) + public static class MissingEventSource extends Aggregation { + @Override + public boolean hasWarning() { + return false; + } + + @Override + public boolean isEmpty() { + return false; + } + } + + public static class MissingAnnotationAggregator extends Aggregator { + protected MissingAnnotationAggregator(MissingEventSource aggregation) { + super(aggregation); + } + } +} diff --git a/api/src/main/java/com/microsoft/gctoolkit/jvm/AbstractJavaVirtualMachine.java b/api/src/main/java/com/microsoft/gctoolkit/jvm/AbstractJavaVirtualMachine.java index 4d457b43..04fdda4f 100644 --- a/api/src/main/java/com/microsoft/gctoolkit/jvm/AbstractJavaVirtualMachine.java +++ b/api/src/main/java/com/microsoft/gctoolkit/jvm/AbstractJavaVirtualMachine.java @@ -153,11 +153,13 @@ public Optional getAggregation(Class aggregationCl @SuppressWarnings("unchecked") private Constructor> constructor(Aggregation aggregation) { Class> targetClazz = aggregation.collates(); - Constructor[] constructors = targetClazz.getConstructors(); - for ( Constructor constructor : constructors) { - Parameter[] parameters = constructor.getParameters(); - if ( parameters.length == 1 && Aggregation.class.isAssignableFrom(parameters[0].getType())) - return (Constructor>)constructor; + if ( targetClazz != null) { + Constructor[] constructors = targetClazz.getConstructors(); + for (Constructor constructor : constructors) { + Parameter[] parameters = constructor.getParameters(); + if (parameters.length == 1 && Aggregation.class.isAssignableFrom(parameters[0].getType())) + return (Constructor>) constructor; + } } return null; } @@ -181,7 +183,10 @@ public void analyze(List registeredAggregations, JVMEventChannel ev Set generatedEvents = diary.generatesEvents(); for (Aggregation aggregation : registeredAggregations) { Constructor> constructor = constructor(aggregation); - if ( constructor == null) continue; + if ( constructor == null) { + LOGGER.log(Level.WARNING, "Cannot find one of: default constructor or @Collates annotation for " + aggregation.getClass().getName()); + continue; + } Aggregator aggregator = constructor.newInstance(aggregation); aggregatedData.put(aggregation.getClass(), aggregation); Optional source = generatedEvents.stream().filter(aggregator::aggregates).findFirst(); From 009f2779eba38d71d0cf09e51f14be7a96f7b3a4 Mon Sep 17 00:00:00 2001 From: Kirk Pepperdine Date: Tue, 21 Feb 2023 12:36:15 -0800 Subject: [PATCH 2/3] debug: fix for corrupted JVMTermination event starting DateTimeStamp --- .../com/microsoft/gctoolkit/event/jvm/JVMTermination.java | 1 - .../com/microsoft/gctoolkit/parser/UnifiedG1GCParser.java | 3 +-- .../gctoolkit/parser/unittests/UnifiedG1GCParserTest.java | 3 +++ .../main/java/com/microsoft/gctoolkit/vertx/VertxChannel.java | 4 ++-- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/api/src/main/java/com/microsoft/gctoolkit/event/jvm/JVMTermination.java b/api/src/main/java/com/microsoft/gctoolkit/event/jvm/JVMTermination.java index df1e1ca5..39a964b2 100644 --- a/api/src/main/java/com/microsoft/gctoolkit/event/jvm/JVMTermination.java +++ b/api/src/main/java/com/microsoft/gctoolkit/event/jvm/JVMTermination.java @@ -2,7 +2,6 @@ // Licensed under the MIT License. package com.microsoft.gctoolkit.event.jvm; - import com.microsoft.gctoolkit.time.DateTimeStamp; public class JVMTermination extends JVMEvent { diff --git a/parser/src/main/java/com/microsoft/gctoolkit/parser/UnifiedG1GCParser.java b/parser/src/main/java/com/microsoft/gctoolkit/parser/UnifiedG1GCParser.java index 5112c3d0..b5b4e4af 100644 --- a/parser/src/main/java/com/microsoft/gctoolkit/parser/UnifiedG1GCParser.java +++ b/parser/src/main/java/com/microsoft/gctoolkit/parser/UnifiedG1GCParser.java @@ -57,7 +57,6 @@ public class UnifiedG1GCParser extends UnifiedGCLogParser implements UnifiedG1GC private DateTimeStamp jvmTerminationEventTime = new DateTimeStamp(-1.0d); private G1GCForwardReference forwardReference; - private boolean concurrentCycleActive = false; private boolean concurrentPhaseActive = false; private final RuleSet> parseRules; @@ -222,7 +221,7 @@ private void cpuBreakout(GCLogTrace trace, String line) { // todo: need to drain the queues before terminating... // Just in case there isn't a JVM termination event in the log. public void endOfFile(GCLogTrace trace, String line) { - publish(new JVMTermination((jvmTerminationEventTime.getTimeStamp() < 0.0d) ? getClock() : jvmTerminationEventTime,diary.getTimeOfFirstEvent())); + publish(new JVMTermination((jvmTerminationEventTime.hasTimeStamp()) ? jvmTerminationEventTime : getClock(),diary.getTimeOfFirstEvent())); } diff --git a/parser/src/test/java/com/microsoft/gctoolkit/parser/unittests/UnifiedG1GCParserTest.java b/parser/src/test/java/com/microsoft/gctoolkit/parser/unittests/UnifiedG1GCParserTest.java index 90d72fb1..44069419 100644 --- a/parser/src/test/java/com/microsoft/gctoolkit/parser/unittests/UnifiedG1GCParserTest.java +++ b/parser/src/test/java/com/microsoft/gctoolkit/parser/unittests/UnifiedG1GCParserTest.java @@ -27,16 +27,19 @@ public void testForDetailsLogs() { } private static final String[] details = { + "jvm-gc-10Nov2022.log", "details_reference.log", "jdk11_details.log.zip" }; private static final int[] detailsNumberOfDifferentCollectors = { + 9, 12, 11 }; private static final int[][] detailsCounts = { // 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 + { 4, 0, 2, 0, 0, 2, 0, 2, 2, 2, 0, 0, 2, 2, 0, 0, 0, 0, 2, 0}, {1130, 141, 146, 0, 0, 146, 0, 146, 0, 146, 1, 0, 146, 146, 0, 0, 16, 146, 146, 0}, {9969, 40, 194, 0, 42, 198, 0, 156, 152, 152, 0, 0, 194, 194, 0, 0, 0, 0, 152, 0} }; diff --git a/vertx/src/main/java/com/microsoft/gctoolkit/vertx/VertxChannel.java b/vertx/src/main/java/com/microsoft/gctoolkit/vertx/VertxChannel.java index 1ca1f726..659e0969 100644 --- a/vertx/src/main/java/com/microsoft/gctoolkit/vertx/VertxChannel.java +++ b/vertx/src/main/java/com/microsoft/gctoolkit/vertx/VertxChannel.java @@ -6,9 +6,9 @@ public class VertxChannel { - private static Vertx vertx; + private Vertx vertx; - static { + { //Disable unused Vert.x functionality System.setProperty("vertx.disableFileCPResolving", "true"); System.setProperty("vertx.disableFileCaching", "true"); From dc05852455a19709ab55410832e0ee964df72c60 Mon Sep 17 00:00:00 2001 From: Kirk Pepperdine Date: Wed, 22 Feb 2023 13:55:47 -0800 Subject: [PATCH 3/3] refactor: bump gctoolkit-testdata release version --- gclogs/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gclogs/pom.xml b/gclogs/pom.xml index 5634a233..af0ec08b 100644 --- a/gclogs/pom.xml +++ b/gclogs/pom.xml @@ -17,7 +17,7 @@ pom - 1.0.5 + 1.0.6