use of com.microsoft.jfr.Recording in project ApplicationInsights-Java by microsoft.
the class ProfilerServiceTest method getJfrDaemon.
private JfrProfiler getJfrDaemon(AtomicBoolean profileInvoked) throws MalformedURLException {
return new JfrProfiler(new ServiceProfilerServiceConfig(1, 2, 3, new URL("http://localhost"), null, null, LocalFileSystemUtils.getTempDir())) {
@Override
protected void profileAndUpload(AlertBreach alertBreach, Duration duration) {
profileInvoked.set(true);
Recording recording = Mockito.mock(Recording.class);
uploadNewRecording(alertBreach, Instant.now()).accept(recording);
}
@Override
protected File createJfrFile(Recording recording, Instant recordingStart, Instant recordingEnd) throws IOException {
return File.createTempFile("jfrFile", jfrExtension);
}
};
}
use of com.microsoft.jfr.Recording in project ApplicationInsights-Java by microsoft.
the class JfrProfiler method executeProfile.
/**
* Perform a profile and notify the handler.
*/
protected void executeProfile(AlertMetricType alertType, Duration duration, Consumer<Recording> handler) {
LOGGER.info("Starting profile");
if (flightRecorderConnection == null) {
LOGGER.error("Flight recorder not initialised");
return;
}
Recording newRecording = startRecording(alertType);
if (newRecording == null) {
return;
}
try {
newRecording.start();
// schedule closing the recording
scheduledExecutorService.schedule(() -> handler.accept(newRecording), duration.getSeconds(), TimeUnit.SECONDS);
} catch (IOException ioException) {
LOGGER.error("Failed to start JFR recording", ioException);
CompletableFuture<?> future = new CompletableFuture<>();
future.completeExceptionally(ioException);
} catch (JfrStreamingException internalError) {
LOGGER.error("Internal JFR Error", internalError);
CompletableFuture<?> future = new CompletableFuture<>();
future.completeExceptionally(internalError);
}
}
Aggregations