2 Event Metadata
The example SetMetadataSample.java
defines an event named
com.oracle.Hello
and sets the annotations @Name, @Description, @Label, and @Category. (Note that this sample
is in the package frexamples
.)
package frexamples;
import jdk.jfr.Category;
import jdk.jfr.Description;
import jdk.jfr.Event;
import jdk.jfr.Label;
import jdk.jfr.Name;
public class SetMetadataSample {
@Name("com.oracle.Hello")
@Label("Set Metadata Example")
@Description("Demonstrates how to set the annotations "
+ "@Name, @Description, @Label, and @Category")
@Category({ "Demonstration", "Tutorial" })
static class Hello extends Event {
@Label("Message")
String message;
}
public static void main(String... args) {
Hello event = new Hello();
event.begin();
event.message = "Hello Event!";
event.commit();
}
}
Ensure that the example is in a directory named frexamples
,
then run SetMetadataSample
from this directory with the following
commands:
java -XX:StartFlightRecording:filename=sm.jfr SetMetadataSample.java
jfr print --events Hello sm.jfr
The last command prints output similar to the following:
com.oracle.Hello {
startTime = 23:43:48.444
duration = 0.0177 ms
message = "Hello Event!"
...
}
You can also use the jfr print
command to filter events that belong to
one or more categories:
jfr print --categories Demonstration sm.jfr
The @Name annotation overrides the default
name for an event type. For example, the default name for the event created in this
example would have been frexamples.SetMetadataSample$Hello
if the
@Name annotation hadn't been set. See Guidelines for Naming Events.
The @Description and @Label annotations enable to you add additional information about an event type. Note that you shouldn't use @Label as an identifier; use the @Name annotation instead. See Guidelines for Labeling Events
The @Category annotation enables you to
associate one or more categories with an event type. To specify one category, use a
string. To specify more than one category, use a comma-separated list of strings
surrounded by braces ({}
). See Categories.