Skip to content

Commit

Permalink
- Corrected README
Browse files Browse the repository at this point in the history
- Renamed JfrAnalysis -> JmcAutomaticAnalysis
- Moved JmcAutomaticAnalysis to internal package
- Separated tests for Automated Analysis
- Add to JmcAutomaticAnalysisAssert api to assert based on IReport
  severity
- Generate new JFR dump for each analysis
- Removed JfrAnalysisResults, replaced with List<IResult>
  • Loading branch information
johnaohara committed Oct 20, 2021
1 parent 2b4a3f9 commit 03a9c07
Show file tree
Hide file tree
Showing 8 changed files with 330 additions and 247 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,10 @@ Java Mission Control provides an Automatic Analysis tool that performs pattern a
It is possible to write assertions against the Automatic Analysis results to verify that unit tests against common performance issues:

```java
import dev.morling.jfrunit.*;
import org.moditect.jfrunit.*;

import static dev.morling.jfrunit.JfrEventsAssert.*;
import static dev.morling.jfrunit.ExpectedEvent.*;
import static org.moditect.jfrunit.JfrEventsAssert.*;
import static org.moditect.jfrunit.ExpectedEvent.*;

@Test
@EnableConfiguration("profile")
Expand Down
124 changes: 0 additions & 124 deletions src/main/java/org/moditect/jfrunit/JfrAnalysisAssert.java

This file was deleted.

38 changes: 0 additions & 38 deletions src/main/java/org/moditect/jfrunit/JfrAnalysisResults.java

This file was deleted.

47 changes: 31 additions & 16 deletions src/main/java/org/moditect/jfrunit/JfrEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,16 @@
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import java.util.function.Predicate;
import java.util.regex.Pattern;
import java.util.stream.Stream;

import org.moditect.jfrunit.EnableEvent.StacktracePolicy;
import org.moditect.jfrunit.internal.JmcAutomaticAnalysis;
import org.moditect.jfrunit.internal.SyncEvent;
import org.openjdk.jmc.flightrecorder.rules.IResult;
import org.openjdk.jmc.flightrecorder.rules.Severity;

import jdk.jfr.Configuration;
Expand All @@ -64,7 +67,7 @@ public class JfrEvents {
private Recording recording;
private boolean capturing;

private JfrAnalysisResults analysis = null;
private AtomicInteger analysisCounter = new AtomicInteger(0);

public JfrEvents() {
}
Expand Down Expand Up @@ -138,6 +141,10 @@ void stopRecordingEvents() {
}

private Path getRecordingFilePath() throws URISyntaxException, IOException {
return getRecordingFilePath(null);
}

private Path getRecordingFilePath(String suffix) throws URISyntaxException, IOException {
URI testSourceUri = testMethod.getDeclaringClass().getProtectionDomain().getCodeSource().getLocation().toURI();
Path dumpDir;
try {
Expand All @@ -148,7 +155,7 @@ private Path getRecordingFilePath() throws URISyntaxException, IOException {
dumpDir = Files.createTempDirectory(null);
LOGGER.log(Level.WARNING, "'" + testSourceUri.getScheme() + "' is not a valid file system, dumping recording to a temporary location.");
}
String fileName = getDumpFileName();
String fileName = getDumpFileName(suffix);
return dumpDir.resolve(fileName);
}

Expand Down Expand Up @@ -314,31 +321,39 @@ private List<EventConfiguration> matchEventTypes(List<EventConfiguration> enable
return allEvents;
}

private String getDumpFileName() {
private String getDumpFileName(String suffix) {
if (dumpFileName == null) {
return getDefaultDumpFileName();
return getDefaultDumpFileName(suffix);
}
else {
return dumpFileName.endsWith(".jfr") ? dumpFileName : dumpFileName + ".jfr";
}
}

private String getDefaultDumpFileName() {
return testMethod.getDeclaringClass().getName() + "-" + testMethod.getName() + ".jfr";
return getDefaultDumpFileName(null);
}

public JfrAnalysisResults automaticAnalysis() {
if (analysis == null) {
try {
Path recordingPath = getRecordingFilePath();
dumpRecording(recordingPath);
private String getDefaultDumpFileName(String suffix) {
return testMethod.getDeclaringClass().getName() + "-" + testMethod.getName() + (suffix != null ? "-" + suffix : "") + ".jfr";
}

analysis = new JfrAnalysisResults(JfrAnalysis.analysisRecording(recordingPath.toAbsolutePath().toString(), Severity.INFO));
}
catch (IOException | URISyntaxException e) {
LOGGER.log(Level.WARNING, "Unable to analyse jfr recording: " + e.getLocalizedMessage());
}
// TODO: Do we move out of JfrEvents?
public List<IResult> automaticAnalysis() {
try {
awaitEvents();

int counter = analysisCounter.getAndIncrement();
Path recordingPath = getRecordingFilePath("analysis" + (counter != 0 ? "-" + counter : ""));

LOGGER.log(Level.INFO, "Analysis recording: " + recordingPath.toAbsolutePath());
dumpRecording(recordingPath);

return JmcAutomaticAnalysis.analysisRecording(recordingPath.toAbsolutePath().toString(), Severity.INFO);

}
catch (IOException | URISyntaxException e) {
throw new RuntimeException("Unable to analyse jfr recording", e);
}
return analysis;
}
}
Loading

0 comments on commit 03a9c07

Please sign in to comment.