Library for streaming Java Flight Recording (JFR) files from local or remote JVMs
Перейти к файлу
Martijn Verburg 5586f7cec5
Merge pull request #24 from microsoft/dependabot/maven/org.testng-testng-7.5.1
Bump testng from 7.5 to 7.5.1
2023-05-11 11:57:49 +12:00
.github Update Deps 10 Jan 2023 Edition (#22) 2023-01-10 11:00:43 -05:00
.mvn/wrapper Update Deps 10 Jan 2023 Edition (#22) 2023-01-10 11:00:43 -05:00
core update deps 04 Dec 2022 (#21) 2022-12-06 16:13:39 -05:00
samples update deps 04 Dec 2022 (#21) 2022-12-06 16:13:39 -05:00
.gitattributes Create .gitattributes 2021-10-08 15:38:01 -07:00
.gitignore Update Deps 10 Jan 2023 Edition (#22) 2023-01-10 11:00:43 -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 Update README.md 2021-11-24 14:59:53 -08: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
mvnw update deps 04 Dec 2022 (#21) 2022-12-06 16:13:39 -05:00
mvnw.cmd update deps 04 Dec 2022 (#21) 2022-12-06 16:13:39 -05:00
pom.xml Bump testng from 7.5 to 7.5.1 2023-05-09 18:59:35 +00: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

Maven Central

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

Example

This example illustrates some of the API.

///usr/bin/env jbang "$0" "$@" ; exit $?
//DEPS com.microsoft.jfr:jfr-streaming:1.2.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());
                System.out.println("JFR recording ready: recording.jfr");
            }
        } catch (InstanceNotFoundException | IOException | JfrStreamingException | InterruptedException e) {
            e.printStackTrace();
        }
    }
}

You can run the code above with jbang:

  1. Install jbang.
  2. Save the code above in a local Sample.java file, or download directly.
  3. Run the code: jbang Sample.java

Note on Oracle JDK 8

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.