Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/com/sun/tracing/package-info.java
38831 views
/*1* Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425/**26* This package provides a mechanism for defining and27* inserting tracepoints into Java-technology based applications, which28* can then be monitored by the tracing tools available on the system.29* <p>30* To add tracepoints to a program, you must first decide where to place the31* tracepoints, what the logical names are for these points, what information32* will be available to the tracing mechanisms at each point, and decide upon33* any logical grouping.34* <p>35* You add instrumentation to a program in three steps:36* <ul>37* <li>First, declare tracepoints by creating interfaces to define38* them, and include these interfaces in the program definition.39* The declared interfaces are standard Java technology-based40* interfaces and are compiled with the program.</li>41* <li>Second, add code in the application to create an instance of the42* interface at some point during the initialization of the application,43* using a factory class provided by the system. The reference to the44* instance can be stored as a global static, or passed as context to all45* the places where it is needed.</li>46* <li>Finally, add the actual tracepoints to the desired locations in the47* application by inserting a call to one of the methods defined in the48* interface, via the factory-created reference.</li>49* </ul>50* <p>51* The method calls representing the tracepoints have no logical52* impact on the program. The side effect of the call is that any53* activated tracing mechanisms will be notified that the tracepoint has54* been hit, and will take whatever actions are appropriate (for example,55* logging the tracepoint, or triggering a DTrace probe, etc.). In most56* cases, the impact on performance of adding tracepoints to the application57* will be minimal.58* <p>59* Each logical grouping of tracepoints should be defined in a common60* interface, called a <i>provider</i>. An application can have one or many61* providers. Each provider is independent and can be created whenever62* it is appropriate for that provider, for example, when a subsytem is63* initialized. Providers should be disposed of when they are no longer64* needed, to free up any associated system resources. Each tracepoint65* in a provider is represented by a method in that interface. These methods66* are referred to as <i>probes</i>. The method signature determines the probe67* parameters. A call to the method with the specified parameters triggers68* the probe and makes its parameter values visible to any associated tracing69* mechanism.70* <p>71* User-defined interfaces which represent providers must extend the72* {@code Provider} interface. To activate the system-defined73* tracing mechanisms, you must obtain an instance of the74* {@code ProviderFactory} class, and pass the class of the provider to75* the {@code createProvider()} method. The returned instance is then used to76* trigger the probes later in the application.77* <p>78* In addition to triggering the probes, the provider instance can be used79* to obtain direct references to the {@code Probe} objects, which can be used80* directly for triggering, or can be queried to determine whether the probe is81* currently being traced. The {@code Provider} interface also defines a82* {@code Provider.dispose()} method which is used to free up any resources83* that might be associated with that provider.84* <p>85* When a probe is triggered, any activated tracing system will be given86* the provider name, the probe name, and the values of the probe arguments.87* The tracing system is free to consume this data is whatever way is88* appropriate.89* By default, the provider name is the same as the class name of the interface90* that defines the provider. Similarly, the probe name is91* the name of the method that defines the probe. These default values92* can be over-ridden by annotations. The provider definition can be93* annotated with the {@code @ProviderName} annotation, whose value will94* indicate the provider name that the tracing system will use. Similarly,95* the {@code @ProbeName} annotation annotates a declared method and96* indicates the probe name that should be used in the place of the97* method name. These annotations can be used to define providers and98* probes with the same name, in cases where the semantics of the Java language99* may prevent this.100* <p>101* Here is a very small and simple usage example:102* <p>103*104<PRE>105import com.sun.tracing.Provider;106import com.sun.tracing.ProviderFactory;107108interface MyProvider extends Provider {109void startProbe();110void finishProbe(int value);111}112113public class MyApplication {114public static void main(String argv[]) {115ProviderFactory factory = ProviderFactory.getDefaultFactory();116MyProvider trace = factory.createProvider(MyProvider.class);117118trace.startProbe();119int result = foo();120trace.finishProbe(result);121122trace.dispose();123}124}125</PRE>126* <p>127* The Java Development Kit (JDK) currently only includes one system-defined128* tracing framework: DTrace. DTrace is enabled automatically whenever an129* application is run on a system and a JDK release that supports it. When130* DTrace is enabled, probes are made available for listing and matching by131* DTrace scripts as soon as the provider is created. At the tracepoint, an132* associated DTrace script is informed of the creation of the provider, and133* it takes whatever action it is designed to take. Tracepoints in the134* program have the following DTrace probe names:<br>135* {@code <provider><pid>:<module>:<function>:<probe>}136* Where:137* <ul>138* <li>{@code <provider>} the provider name as specified by the application</li>139* <li>{@code <pid>} the operating system process ID</li>140* <li>{@code <module>} undefined, unless specified by the application</li>141* <li>{@code <function>} undefined, unless specified by the application</li>142* <li>{@code <probe>} the probe name as specified by the application</li>143* </ul>144* <p>145* The {@code com.sun.tracing.dtrace} package contains additional146* annotations that can be used to control the names used for the147* <code>module</code> and <code>function</code> fields, as well as annotations148* that can be added to the provider to control probe stability and dependency149* attributes.150* <p>151* Integer, float and string probe parameters are made available to DTrace152* using153* the built-in argument variables, {@code arg0 ... arg_n}. Integer-types154* are passed by value (boxed values are unboxed), floating-point types are155* passed as encoded integer156* arguments, and {@code java.lang.String} objects are converted157* to UTF8 strings, so they can be read into the DTrace script using the158* {@code copyinstr()} intrinsic. Non-string and non-boxed primitive159* reference arguments are only160* placeholders and have no value.161* <p>162* Using the example above, with a theoretical process ID of 123, these are163* the probes that can be traced from DTrace:164<PRE>165MyProvider123:::startProbe166MyProvider123:::finishProbe167</PRE>168* When {@code finishProbe} executes, {@code arg0} will contain the169* value of {@code result}.170* <p>171* The DTrace tracing mechanism is enabled for all providers, apart from in the172* following circumstances:173* <ul>174* <li>DTrace is not supported on the underlying system.</li>175* <li>The property {@code com.sun.tracing.dtrace} is set to "disable".</li>176* <li>The RuntimePermission {@code com.sun.tracing.dtrace.createProvider}177* is denied to the process.</li>178* </ul>179* <p>180*/181182package com.sun.tracing;183184185