Sample code with jbang support

This commit is contained in:
Bruno Borges 2021-03-16 08:13:47 -07:00
Родитель f8a3427a09
Коммит e5f21cf239
1 изменённых файлов: 34 добавлений и 0 удалений

34
src/test/java/Sample.java Normal file
Просмотреть файл

@ -0,0 +1,34 @@
///usr/bin/env jbang "$0" "$@" ; exit $?
//DEPS com.microsoft.jfr:jfr-streaming:1.0.0
import java.io.IOException;
import java.nio.file.Paths;
import java.util.concurrent.TimeUnit;
import java.lang.management.ManagementFactory;
import javax.management.*;
import com.microsoft.jfr.*;
public class Sample {
public static void main(String[] args) {
MBeanServerConnection mBeanServer = ManagementFactory.getPlatformMBeanServer();
try {
FlightRecorderConnection flightRecorderConnection = FlightRecorderConnection.connect(mBeanServer);
RecordingOptions recordingOptions = new RecordingOptions.Builder().disk("true").build();
RecordingConfiguration recordingConfiguration = RecordingConfiguration.PROFILE_CONFIGURATION;
try (Recording recording = flightRecorderConnection.newRecording(recordingOptions, recordingConfiguration)) {
recording.start();
TimeUnit.SECONDS.sleep(10);
recording.stop();
recording.dump(Paths.get(System.getProperty("user.dir"), "recording.jfr").toString());
}
} catch (InstanceNotFoundException | IOException | JfrStreamingException | InterruptedException e) {
e.printStackTrace();
}
}
}