GithubHelp home page GithubHelp logo

jfr-streaming's Introduction

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 [email protected] with any additional questions or comments.

License

Microsoft JFR Streaming Library is licensed under the MIT license.

jfr-streaming's People

Contributors

brunoborges avatar debjitms avatar dependabot[bot] avatar dsgrieve avatar jeanbisutti avatar johnoliver avatar karianna avatar lewurm avatar microsoft-github-operations[bot] avatar microsoftopensource avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jfr-streaming's Issues

Put src in a maven module so that other modules can be added later for other, related code that is not core

Is your feature request related to a problem? Please describe.
The problem is that there is some utility code that could be added to the project, but the classes for the utility should not be part of the core library.

Describe the solution you'd like
Make the project use maven modules. The core library (which is today 'src') can be kept separate for other code - utilities or frameworks - that might be built on top of or along side of the core library.

Describe alternatives you've considered
Putting all of the code in 'src' and either letting the utility code be shipped as runtime code, or rig the build to exclude the utility classes from the jfr-streaming jar. The problem with shipping with runtime is that the utility could create vulnerabilities. The problem with excluding the utility classes are many, but the biggest would be that the only way to get the utility would be to build from source. The preference is to be able to have a separate utility library that could be fetched from maven central which makes it a more natural way of using the utility in a build.

Additional context
Relevant to PR 16.

Use maven wrapper

Is your feature request related to a problem? Please describe.
Not related to a problem. Using maven wrapper is considered best practice as it avoids having to rely on what version the user may or may not have installed.

Describe the solution you'd like
Maven wrapper is described here

Describe alternatives you've considered

Additional context

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.