Library for streaming Java Flight Recording (JFR) files from local or remote JVMs
Перейти к файлу
Bruno Borges f8a3427a09 New build matrix for JDKs 8, 11, and 15 2021-03-16 07:51:13 -07:00
.github New build matrix for JDKs 8, 11, and 15 2021-03-16 07:51:13 -07:00
src Address potential NPE in JfrStream#read 2021-03-04 13:56:22 -05:00
.gitignore Fix javadoc and pom for publish to maven 2021-02-23 17:14:55 -05:00
CODE_OF_CONDUCT.md Initial CODE_OF_CONDUCT.md commit 2021-01-28 13:16:06 -08:00
CONTRIBUTING.md address comments from PR#1 2021-01-30 11:27:15 -05:00
LICENSE Initial LICENSE commit 2021-01-28 13:16:08 -08:00
README.md New build matrix for JDKs 8, 11, and 15 2021-03-16 07:51:13 -07:00
SECURITY.md Initial SECURITY.md commit 2021-01-28 13:16:10 -08:00
SUPPORT.md Update SUPPORT.md 2021-01-29 10:22:39 -05:00
pom.xml New build matrix for JDKs 8, 11, and 15 2021-03-16 07:51:13 -07:00

README.md

Microsoft JFR Streaming

The jfr-streaming project provides a core library for configuring, starting, stopping, and reading Java Flight Recording files from a JVM. The code does not depend on the jdk.jfr module and will compile and run against JDK 8 or higher. It uses a connection to an MBean server, which can be the platform MBean server, or a remote MBean server connected by means of JMX.

The goal of this project is a low-level library. Solving higher level problems, such as managing JFR across multiple JVMs, is not a goal of this project.

Getting Started

Maven Coordinates

<dependency>
  <groupId>com.microsoft.jfr</groupId>
  <artifactId>jfr-streaming</artifactId>
  <version>1.0.0</version>
</dependency>

Example

This example illustrates some of the API.

    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 (IOException ioe) {
                ioe.printStackTrace();
            } catch (InterruptedException ie) {
                ie.printStackTrace();
            }
        } catch (InstanceNotFoundException|IOException e) {
            e.printStackTrace();
        }
    }

Note that for Oracle JDK 8, it may be necessary to unlock the Java Flight Recorder commercial feature with the JVM arg -XX:+UnlockCommercialFeatures -XX:+FlightRecorder. Starting with JDK 8u262, Java Flight Recorder is available for all OpenJDK distributions.

Build and Test

The build is vanilla Maven.


mvn clean - remove build artifacts
mvn compile - compile the source code
mvn test - run unit tests (this project uses TestNG)
mvn package - build the .jar file

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, view Microsoft's CLA.

When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repositories using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.

License

Microsoft JFR Streaming Library is licensed under the MIT license.