-
Notifications
You must be signed in to change notification settings - Fork 960
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BTrace support for custom JFR events #429
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Added @JfrPeriodicEventHandler and @JfrBlock annotations to allow emitting JFR events in safe mode (eg. passing both compilation and runtime verifier).
Use JFR classifier
# Conflicts: # btrace-compiler/src/test/resources/JfrEventsProbe.java # btrace-core/src/main/java/org/openjdk/btrace/core/BTraceUtils.java # btrace-core/src/main/java/org/openjdk/btrace/core/jfr/JfrEvent.java # btrace-instr/src/main/java/org/openjdk/btrace/instr/Preprocessor.java # btrace-instr/src/test/btrace/JfrTest.java # btrace-instr/src/test/java/org/openjdk/btrace/BTraceFunctionalTests.java # btrace-runtime/src/main/java/org/openjdk/btrace/runtime/BTraceRuntimeImpl_7.java # btrace-runtime/src/main/java11/org/openjdk/btrace/runtime/BTraceRuntimeImpl_11.java # btrace-runtime/src/main/java11/org/openjdk/btrace/runtime/JfrEventFactoryImpl.java # btrace-runtime/src/main/java9/org/openjdk/btrace/runtime/BTraceRuntimeImpl_9.java
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
With the (almost) ubiquitous availability of JFR APIs in the current JDKs it makes sense to have the means to produce JFR events directly from BTrace probes.
The JFR API provides a convenient way to create and register custom event types via its
EventFactory
and BTrace will utilise this. Both requestable and periodical event types are supported.Usage
Requestable events
Working with requestable events is mimicking the workflow typical for the JFR API.
1. Register custom event factory by annotating a filed of type
JfrEvent.Factory
name
,label
,description
andstacktrace
attributes are self descriptive and of them onlyname
is required, the rest is optional.The
fields
attribute is an array of event field definitions - each field must have its name and type defined (where the type is restricted to the subset of primitive, class, thread and string). A field can have an optional kind associated with it with the supported kinds being enumerated in FieldKind enumeration.2. Create a new event instance
3. Check whether the event instance is committable
4. Set event fields
5. Commit event
Periodical events
1. Register periodical event handler by annotating a method taking exactly one argument of type
JfrEvent
. The event argument will get automatically injected by BTrace to contain a valid instance of the defined event type.The attributes of
@PeriodicEvent
annotation are the same as for@Event
annotation with the additional attribute ofperiod
which defines the periodicity of the event. Allowed values arebeforeChunk
,afterChunk
,eachChunk
and time period specification in formnumber unit
(eg.10 s
or150 ms
etc.). The meaning of those values as well as the allowed time units are taken directly from the JFR API so they are not going to be explained here.Also, it is not possible to request stacktrace for periodical events since it would make not much sense, all the periodical events being emitted by internal JFR threads.
2. Write the event handling code
The periodic event handling is 100% equivalent to emitting a requestable event.
Compatibility
JFR support requires (of course) the JFR APIs being available in JDK. Currently this means JDK 11 and newer (although JFR support is already in JDK 8u272 this implementation is not supporting that yet) and all the JFR related BTrace code will be silently ignored for non-compatible Java versions.