Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Npe #273

Merged
3 commits merged into from
Feb 22, 2023
Merged

Npe #273

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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<MissingAnnotationAggregation> {
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<MissingEventSource> {
protected MissingAnnotationAggregator(MissingEventSource aggregation) {
super(aggregation);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,13 @@ public <T extends Aggregation> Optional<T> getAggregation(Class<T> aggregationCl
@SuppressWarnings("unchecked")
private Constructor<? extends Aggregator<?>> constructor(Aggregation aggregation) {
Class<? extends Aggregator<?>> 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<? extends Aggregator<?>>)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<? extends Aggregator<?>>) constructor;
}
}
return null;
}
Expand All @@ -181,7 +183,10 @@ public void analyze(List<Aggregation> registeredAggregations, JVMEventChannel ev
Set<EventSource> generatedEvents = diary.generatesEvents();
for (Aggregation aggregation : registeredAggregations) {
Constructor<? extends Aggregator<?>> 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<? extends Aggregation> aggregator = constructor.newInstance(aggregation);
aggregatedData.put(aggregation.getClass(), aggregation);
Optional<EventSource> source = generatedEvents.stream().filter(aggregator::aggregates).findFirst();
Expand Down
2 changes: 1 addition & 1 deletion gclogs/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<packaging>pom</packaging>

<properties>
<gctoolkit-testdata-version>1.0.5</gctoolkit-testdata-version>
<gctoolkit-testdata-version>1.0.6</gctoolkit-testdata-version>
</properties>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<GCParseRule, BiConsumer<GCLogTrace, String>> parseRules;
Expand Down Expand Up @@ -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()));
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down