Search in sources :

Example 1 with Recording

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);
        }
    };
}
Also used : ServiceProfilerServiceConfig(com.microsoft.applicationinsights.profiler.config.ServiceProfilerServiceConfig) AlertBreach(com.microsoft.applicationinsights.alerting.alert.AlertBreach) Instant(java.time.Instant) JfrProfiler(com.microsoft.applicationinsights.serviceprofilerapi.profiler.JfrProfiler) Duration(java.time.Duration) Recording(com.microsoft.jfr.Recording) URL(java.net.URL)

Example 2 with Recording

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);
    }
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) Recording(com.microsoft.jfr.Recording) IOException(java.io.IOException) JfrStreamingException(com.microsoft.jfr.JfrStreamingException)

Aggregations

Recording (com.microsoft.jfr.Recording)2 AlertBreach (com.microsoft.applicationinsights.alerting.alert.AlertBreach)1 ServiceProfilerServiceConfig (com.microsoft.applicationinsights.profiler.config.ServiceProfilerServiceConfig)1 JfrProfiler (com.microsoft.applicationinsights.serviceprofilerapi.profiler.JfrProfiler)1 JfrStreamingException (com.microsoft.jfr.JfrStreamingException)1 IOException (java.io.IOException)1 URL (java.net.URL)1 Duration (java.time.Duration)1 Instant (java.time.Instant)1 CompletableFuture (java.util.concurrent.CompletableFuture)1