1 /*
2  * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * This code is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 only, as
7  * published by the Free Software Foundation.  Oracle designates this
8  * particular file as subject to the "Classpath" exception as provided
9  * by Oracle in the LICENSE file that accompanied this code.
10  *
11  * This code is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14  * version 2 for more details (a copy is included in the LICENSE file that
15  * accompanied this code).
16  *
17  * You should have received a copy of the GNU General Public License version
18  * 2 along with this work; if not, write to the Free Software Foundation,
19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20  *
21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22  * or visit www.oracle.com if you need additional information or have any
23  * questions.
24  */
25 
26 package jdk.jfr;
27 
28 import java.lang.annotation.ElementType;
29 import java.lang.annotation.Inherited;
30 import java.lang.annotation.Retention;
31 import java.lang.annotation.RetentionPolicy;
32 import java.lang.annotation.Target;
33 
34 /**
35  * Event annotation, to associate the event type with a category, in the format
36  * of a human-readable path.
37  * <p>
38  * The category determines how an event is presented to the user. Events that
39  * are in the same category are typically displayed together in graphs and
40  * trees. To avoid the overlap of durational events in graphical
41  * representations, overlapping events must be in separate categories.
42  * <p>
43  * For example, to monitor image uploads to a web server with a separate thread
44  * for each upload, an event called File Upload starts when the user uploads a
45  * file and ends when the upload is complete. For advanced diagnostics about
46  * image uploads, more detailed events are created (for example, Image Read,
47  * Image Resize, and Image Write). During these detailed events. other low
48  * level-events could occur (for example, Socket Read and File Write).
49  * <p>
50  * The following example shows a visualization that avoids overlaps:
51  *
52  * <pre>
53  * -------------------------------------------------------------------
54  *   |                         File Upload                        |
55  * ------------------------------------------------------------------
56  *   |       Image Read          | Image Resize |   Image Write   |
57  * ------------------------------------------------------------------
58  *   | Socket Read | Socket Read |              |    File Write   |
59  * -------------------------------------------------------------------
60  * </pre>
61  *
62  * The example can be achieved by using the following categories:
63  *
64  * <table class="striped">
65  * <caption>Recording options and their purpose.</caption> <thead>
66  * <tr>
67  * <th scope="col">Event Name</th>
68  * <th scope="col">Annotation</th>
69  * </tr>
70  * </thead> <tbody>
71  * <tr>
72  * <th scope="row">File Upload</th>
73  * <td><code>@Category("Upload")</code></td>
74  * </tr>
75  * <tr>
76  * <th scope="row">Image Read</th>
77  * <td><code>@Category({"Upload", "Image Upload"})</code></td>
78  * </tr>
79  * <tr>
80  * <th scope="row">Image Resize</th>
81  * <td><code>@Category({"Upload", "Image Upload"})</code></td>
82  * </tr>
83  * <tr>
84  * <th scope="row">Image Write</th>
85  * <td><code>@Category({"Upload", "Image Upload"})</code></td>
86  * </tr>
87  * <tr>
88  * <th scope="row">Socket Read</th>
89  * <td><code>@Category("Java Application")</code></td>
90  * </tr>
91  * <tr>
92  * <th scope="row">File Write</th>
93  * <td><code>@Category("Java Application")</code></td>
94  * </tr>
95  * </tbody>
96  * </table>
97  * <p>
98  * The File Upload, Image Read, and Socket Read events happen concurrently (in
99  * the same thread), but the events are in different categories so they do not
100  * overlap in the visualization.
101  * <p>
102  * The following examples shows how the category is used to determine how events
103  * are visualized in a tree:
104  *
105  * <pre>
106  *  |- Java Application
107  *  |  |- Socket Read
108  *  |  |- File Write
109  *  |- Upload
110  *     |- File Upload
111  *     |- Image Upload
112  *        |- Image Read
113  *        |- Image Resize
114  *        |- File Write
115  * </pre>
116  *
117  * @since 9
118  */
119 @MetadataDefinition
120 @Target({ ElementType.TYPE })
121 @Inherited
122 @Retention(RetentionPolicy.RUNTIME)
123 public @interface Category {
124     /**
125      * Returns the category names for this annotation, starting with the root.
126      *
127      * @return the category names
128      */
value()129     String[] value();
130 }
131