forked from btraceio/btrace
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathusersguide.html
More file actions
503 lines (453 loc) · 26.6 KB
/
usersguide.html
File metadata and controls
503 lines (453 loc) · 26.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
<html>
<head>
<title>
BTrace User's Guide
</title>
</head>
<body>
<h1>BTrace User's Guide</h1>
<p>
<b>BTrace</b> is a safe, dynamic tracing tool for Java. BTrace
works by dynamically (bytecode) instrumenting classes of a running
Java program. BTrace inserts tracing actions into the classes of a running
Java program and hotswaps the traced program classes.
</p>
<h3>BTrace Terminology</h3>
<dl>
<dt><b>Probe Point</b></dt>
<dd>"location" or "event" at which a set of tracing statements
are executed. Probe point is "place" or "event" of interest where
we want to execute some tracing statements.
</dd>
<dt><b>Trace Actions or Actions</b></dt>
<dd>
Trace statements that are executed whenever a probe "fires".
</dd>
<dt><b>Action Methods</b></dt>
<dd>
BTrace trace statements that are executed when a probe fires
are defined inside a static method a class. Such methods are called
"action" methods.
</dd>
</dl>
<h3>BTrace Program Structure</h3>
<p>
A BTrace program is a plain Java class that has one or more <code>public static void</code> methods that
are annotated with <a href="#btrace_anno">BTrace annotations</a>. The annotations are used to
specify traced program "locations" (also known as "probe points"). The tracing actions are
specified inside the static method bodies. These static methods are referred as "action" methods.
</p>
<h3>BTrace Restrictions</h3>
<p>
To guarantee that the tracing actions are "read-only" (i.e., the trace actions don't change the
state of the program traced) and bounded (i.e., trace actions terminate in bounded time),
a BTrace program is allowed to do only a restricted set of actions.
In particular, a BTrace class
<ul>
<li>can <b>not</b> create new objects.
<li>can <b>not</b> create new arrays.
<li>can <b>not</b> throw exceptions.
<li>can <b>not</b> catch exceptions.
<li>can <b>not</b> make arbitrary instance or static method calls - only the <b><code>public static</code></b> methods
of <code><b><a href="javadoc/com/sun/btrace/BTraceUtils.html">com.sun.btrace.BTraceUtils</a></b></code>
class may be called from a BTrace program.
<li>can <b>not</b> assign to static or instance fields of
target program's classes and objects. But, BTrace class can assign
to it's own static fields ("trace state" can be mutated).
<li>can <b>not</b> have instance fields and methods. Only <b><code>static
public void</code></b> returning methods are allowed for a BTrace class. And all
fields have to be static.
<li>can <b>not</b> have outer, inner, nested or local classes.
<li>can <b>not</b> have synchronized blocks or synchronized methods.
<li>can <b>not</b> have loops (<b><code>for, while, do..while</code></b>)
<li>can <b>not</b> extend arbitrary class (super class has to be java.lang.Object)
<li>can <b>not</b> implement interfaces.
<li>can <b>not</b> contains assert statements.
<li>can <b>not</b> use class literals.
</ul>
</p>
<h3>A simple BTrace program</h3>
<pre>
<code>
// import all BTrace annotations
import <b>com.sun.btrace.annotations.*;</b>
// import statics from BTraceUtils class
import <b>static com.sun.btrace.BTraceUtils.*;</b>
// @BTrace annotation tells that this is a BTrace program
<b>@BTrace</b>
public class HelloWorld {
// @OnMethod annotation tells where to probe.
// In this example, we are interested in entry
// into the Thread.start() method.
<b>@OnMethod</b>(
clazz="java.lang.Thread",
method="start"
)
public static void func() {
// println is defined in BTraceUtils
// you can only call the static methods of BTraceUtils
println("about to start a thread!");
}
}
</code>
</pre>
<p>
The above BTrace program can be run against a running Java process. This program
will print "about to start a thread!" at the BTrace client whenever the target program
is about to start a thread by <code>Thread.start()</code> method. There are other
interesting probe points possible. For example, we can insert trace action at
return from a method, exception return from a method, a field get or set within method(s),
object/array creation, line number(s), throwing an exception. Please refer to the
<a href="#btrace_anno">@OnMethod and other annotations</a> for details.
</p>
<h3>Steps to run BTrace</h3>
<ol>
<li>Find the process id of the target Java process that you want to trace.
You can use <b><a href="http://java.sun.com/javase/6/docs/technotes/tools/share/jps.html">jps</a></b> tool to find the pid.
<li>Write a BTrace program - you may want to start modifying one of the
<b><a href="#samples">samples</a></b>.
<li>Run <b>btrace</b> tool by the following command line:
<pre>
btrace <pid> <btrace-script>
</pre>
</ol>
<h3>BTrace Command Line</h3>
BTrace is run using the command line tool <b>btrace</b> as shown below:
<pre>
<code>
<b>btrace</b> [-I <include-path>] [-p <port>] [-cp <classpath>] <pid> <btrace-script> [<args>]
</code>
</pre>
where
<ul>
<li><code>include-path</code> is a set of include directories that are searched for header files.
BTrace includes a simple preprocess with support for #define, #include and conditional compilation.
It is <b>not</b> like a complete C/C++ preprocessor - but a useful subset. See the sample "ThreadBean.java".
If -I is not specified, BTrace skips the preprocessor invocation step.
<li><code>port</code> is the port in which BTrace agent listens. This is optional argument.
<li><code>classpath</code> is set of directories, jar files where BTrace searches for classes during compilation.
Default is ".".
<li><code>pid</code> is the process id of the traced Java program
<li><code>btrace-script</code> is the trace program. If it is a ".java", then it is compiled
before submission. Or else, it is assumed to be pre-compiled [i.e., it has to be a .class]
and submitted.
</ul>
<h4>optional</h4>
<ul>
<li><code>port</code> is the server socket port at which BTrace agent listens for clients. Default is 2020.
<li><code>path</code> is the classpath used for compiling BTrace program. Default is ".".
<li><code>args</code> is command line arguments passed to BTrace program. BTrace
program can access these using the built-in functions "$" and "$length".
</ul>
<a name="precompile"></a>
<h3>Pre-compiling BTrace scripts</h3>
<p>
It is possible to precompile BTrace program using <b>btracec</b> script. btracec
is a javac-like program that takes a BTrace program and produces a .class file.
<pre>
<code>
<b>btracec</b> [-I <include-path>] [-cp <classpath>] [-d <directory>] <one-or-more-BTrace-.java-files>
</code>
</pre>
where
<ul>
<li><code>include-path</code> is a set of include directories that are searched for header files.
BTrace includes a simple preprocess with support for #define, #include and conditional compilation.
It is <b>not</b> like a complete C/C++ preprocessor - but a useful subset. See the sample "ThreadBean.java".
If -I is not specified, BTrace skips the preprocessor invocation step.
<li><code>classpath</code> is the classpath used for compiling BTrace program(s). Default is "."
<li><code>directory</code> is the output directory where compiled .class files are stored. Default is ".".
</ul>
This script uses BTrace compiler class - rather than regular javac and therefore will validate
your BTrace program at compile time [so that you can avoid BTrace verify error at runtime].
</p>
<h3>Starting an application with BTrace agent</h3>
<p>
So far, we saw how to trace a running Java program. It is also possible to start an application with BTrace agent in it.
If you want to start tracing the application from the very "beginning", you may
want to start the app with BTrace agent and specify a trace script along with it
[i.e., BTrace agent is attach-on-demand loadable as well as pre-loadable agent]
You can use the following command to start an app and specify BTrace script file.
But, you need to <a href="#precompile">precompile your BTrace script</a> for this
kind of usage.
</p>
<pre>
<code>
java <b>-javaagent:btrace-agent.jar=script=<pre-compiled-btrace-script></b> <MainClass> <AppArguments>
</code>
</pre>
<p>
When starting the application this way, the trace output goes to a file named <btrace-class-file-name>.btrace
in the current directory. Also, you can avoid starting server for other remote BTrace clients by specifying <code>noServer=true</code>
as an argument to the BTrace agent.
</p>
There is a convenient script called <b>btracer</b> to do the above:
<pre>
<code>
<b>btracer</b> <pre-compiled-btrace.class> <application-main-class> <application-args>
</code>
</pre>
<a name="btrace_anno"></a>
<h3>BTrace Annotations</h3>
<h4>Method Annotations</h4>
<ul>
<li><b><a href="javadoc/com/sun/btrace/annotations/OnMethod.html">@com.sun.btrace.annotations.OnMethod</a></b>
annotation can be used to
specify target class(es), target method(s) and "location(s)" within the method(s).
An action method annotated by this annotation is called when the matching method(s) reaches
specified the location. In OnMethod annotation, traced class name is specified by
"clazz" property and traced method is specified by "method" property. "clazz" may be
a fully qualified class name (like <b><code>java.awt.Component</code></b> or a regular
expression specified within two forward slashes. Refer to the samples
<b><a href="../samples/NewComponent.java">NewComponent.java</a></b> and <b><a href="../samples/Classload.java">
Classload.java</a></b>. The regular expression can match zero or more
classes in which case all matching classes are instrumented. For example <b><code>/java\\.awt\\..+/</code></b>
matches all classes in java.awt package. Also, method name can be a regular expression as well - matching
zero or more methods. Refer to the sample <b><a href="../samples/MultiClass.java">MultiClass.java</a></b>.
There is another way to abstractly specify traced class(es) and method(s). Traced classes and methods may be
specified by annotation. For example, if the "clazz" attribute is specified as <b><code>@javax.jws.WebService</code></b>
BTrace will instrument all classes that are annotated by the WebService annotation. Similarly, method level annotations
may be used to specify methods abstractly. Refer to the sample
<b><a href="../samples/WebServiceTracker.java">WebServiceTracker.java</a></b>.
It is also possible to combine regular expressions with annotations - like
<b><code>@/com\\.acme\\..+/</code></b> matches any class that is annotated by any annotation that matches the given
regular expression. It is possible to match multiple classes by specifying super type. i.e., match all classes that are subtypes of
a given super type. <b><code>+java.lang.Runnable</code></b> matches all classes implementing java.lang.Runnable
interface. Refer to the sample <b><a href="../samples/SubtypeTracer.java">SubtypeTracer.java</a></b>.
<li><b><a href="javadoc/com/sun/btrace/annotations/OnTimer.html">@com.sun.btrace.annotations.OnTimer</a></b>
annotation can be used to specify tracing
actions that have to run periodically once every N milliseconds. Time period is specified as long
"value" property of this annotation. Refer to the sample
<b><a href="../samples/Histogram.java">Histogram.java</a></b>
<li><b><a href="javadoc/com/sun/btrace/annotations/OnError.html">@com.sun.btrace.annotations.OnError</a></b>
annotation can be used to specify
actions that are run whenever any exception is thrown by tracing actions of some other probe.
BTrace method annotated by this annotation is called when any exception is thrown by any of
the other BTrace action methods in the same BTrace class.
<li><b><a href="javadoc/com/sun/btrace/annotations/OnExit.html">@com.sun.btrace.annotations.OnExit</a></b>
annotation can be used to specify
actions that are run when BTrace code calls "exit(int)" built-in function to finish the tracing
"session". Refer to the sample <b><a href="../samples/ProbeExit.java">ProbeExit.java</a></b>.
<li><b><a href="javadoc/com/sun/btrace/annotations/OnEvent.html">@com.sun.btrace.annotations.OnEvent</a></b>
annotation is used to associate tracing
methods with "external" events send by BTrace client. BTrace methods annotated by this annotation are called when
BTrace client sends an "event". Client may send an event based on some form of user request to
send (like pressing Ctrl-C or a GUI menu). String value may used as the name of the event.
This way certain tracing actions can be executed whenever an external event "fires". As of now,
the command line BTrace client sends "events" whenever use presses Ctrl-C (SIGINT). On SIGINT,
a console menu is shown to send an event or exit the client [which is the default for SIGINT].
Refer to the sample
<b><a href="../samples/HistoOnEvent.java">HistoOnEvent.java</a></b>
<li><b><a href="javadoc/com/sun/btrace/annotations/OnLowMemory.html">@com.sun.btrace.annotations.OnLowMemory</a></b>
annotation can be used to trace memory threshold exceed event.
See sample <b><a href="../samples/MemAlerter.java">MemAlerter.java</a></b>
<li><b><a href="javadoc/com/sun/btrace/annotations/OnProbe.html">@com.sun.btrace.annotations.OnProbe</a></b>
annotation can be used to specify to avoid using implementation internal classes
in BTrace scripts. @OnProbe probe specifications are mapped to one or more @OnMethod
specifications by the BTrace VM agent. Currently, this mapping is done using a XML probe descriptor
file [accessed by the BTrace agent]. Refer to the sample <b><a href="../samples/SocketTracker1.java">SocketTracker1.java</a></b>
and associated probe descriptor file <b><a href="../samples/java.net.socket.xml">java.net.socket.xml</a></b>.
When running this sample, this xml file needs to be copied in the directory where
the target JVM runs (or fix probeDescPath option in btracer.bat to point to whereever
the .xml file is).
</ul>
<h4>Argument Annotations</h4>
<ul>
<li><b><a href="javadoc/com/sun/btrace/annotations/Self.html">@com.sun.btrace.annotations.Self</a></b>
annotation can be used to mark an argument to hold *this* (or *self*) value. Refer to the samples
<b><a href="../samples/AWTEventTracer.java">AWTEventTracer.java</a></b> or
<b><a href="../samples/AllCalls1.java">AllCalls1.java</a></b>
</li>
<li><b><a href="javadoc/com/sun/btrace/annotations/Return.html">@com.sun.btrace.annotations.Return</a></b>
annotation can be used to mark an argument to hold the return value. Refer to the sample
<b><a href="../samples/Classload.java">Classload.java</a></b>
</li>
<li><b><a href="javadoc/com/sun/btrace/annotations/CalledInstance.html">@com.sun.btrace.annotations.CalledInstance</a></b>
annotation can be used to mark an argument to hold the called instance value. Refer to the sample
<b><a href="../samples/AllCalls2.java">AllCalls2.java</a></b>
</li>
<li><b><a href="javadoc/com/sun/btrace/annotations/CalledMethod.html">@com.sun.btrace.annotations.CalledMethod</a></b>
can be used to mark an argument to hold the called method name. Refer to the samples
<b><a href="../samples/AllCalls1.java">AllCalls1.java</a></b> or
<b><a href="../samples/AllCalls2.java">AllCalls2.java</a></b>
</li>
</ul>
<h4>Field Annotations</h4>
<ul>
<li><b><code><a href="javadoc/com/sun/btrace/annotations/Export.html">@com.sun.btrace.annotations.Export</a></code></b> annotation can be used with BTrace fields
(static fields) to specify that the field has to be mapped to a jvmstat counter. Using this, a BTrace
program can expose tracing counters to external jvmstat clients (such as jstat). Refer to the sample
<b><a href="../samples/ThreadCounter.java">ThreadCounter.java</a></b>
<li><b><code><a href="javadoc/com/sun/btrace/annotations/Property.html">@com.sun.btrace.annotations.Property</a></code></b> annotation
can be used to flag a specific (static) field as a MBean attribute. If a BTrace class has atleast one static field with
@Property attribute, then a MBean is created and registered with platform MBean server. JMX clients such as VisualVM, jconsole can be
used to view such BTrace MBeans. After attaching BTrace to the target program, you can attach VisualVM or jconsole to the same
program and view the newly created BTrace MBean. With VisualVM and jconsole, you can use MBeans tab to view the BTrace domain and
check out it's attributes. Refer to the samples <b><a href="../samples/ThreadCounterBean.java">ThreadCounterBean</a></b> and
<b><a href="../samples/HistogramBean.java">HistogramBean.java</a></b>.
<li><b><code><a href="javadoc/com/sun/btrace/annotations/TLS.html">@com.sun.btrace.annotations.TLS</a></code></b> annotation can be used with BTrace fields (static
fields) to specify that the field is a thread local field. Each Java thread gets a separate "copy" of
the field. These thread local fields may be used by BTrace programs to identify whether we reached multiple
probe actions from the same thread or not. Refer to the samples
<b><a href="../samples/OnThrow.java">OnThrow.java</a></b> and
<b><a href="../samples/WebServiceTracker.java">WebServiceTracker.java</a></b>
</ul>
<h4>Class Annotations</h4>
<ul>
<li><b><code><a href="javadoc/com/sun/btrace/annotations/DTrace.html">@com.sun.btrace.annotations.DTrace</a></code></b> annotation can be used to associate a simple one-liner D-script (inlined in BTrace Java class) with
the BTrace program. Refer to the sample <b><a href="../samples/DTraceInline.java">DTraceInline.java</a></b>.
<li><b><code><a href="javadoc/com/sun/btrace/annotations/DTraceRef.html">@com.sun.btrace.annotations.DTraceRef</a></code></b> annotation can be used to associate a D-script (stored in a separate file) with the BTrace
program. Refer to the sample <b><a href="../samples/DTraceRefDemo.java">DTraceRefDemo.java</a></b>.
<li><b><code><a href="javadoc/com/sun/btrace/annotations/BTrace.html">@com.sun.btrace.annotations.BTrace</a></code></b> annotation must be used to designate a given Java class as a BTrace program. This annotation is
enforced by the BTrace compiler as well as by the BTrace agent.
</ul>
<h3>DTrace Integration</h3>
<p>
Solaris DTrace is a dynamic, safe tracing system for Solaris programs - both kernel and user land programs. Because of the obvious parallels b/w DTrace and
BTrace, it is natural to expect integration b/w BTrace and DTrace. There are
two ways in which BTrace is integrated with DTrace.
</p>
<ul>
<li>BTrace program can raise a DTrace probe - by calling <code>dtraceProbe</code> -- see BTraceUtils javadoc referred above.
For this feature to work, you need to be running on <b>Solaris 10 or beyond</b>. For other platforms (Solaris 9 or below
or any other OS), <code>dtraceProbe()</code> will be a no-op.
<li>BTrace program can associate a D-script with it-- by @DTrace annotation
(if the D-script is a simple one liner) or by @DTraceRef if the D-script is
longer and hence stored outside of the BTrace program. See DTrace integration
samples in the BTrace samples section below. This feature works using the <b><a href="http://www.opensolaris.org/os/project/dtrace-chime/java_dtrace_api/">DTrace Java API</a></b>.
For this DTrace feature to work (o.e., being able to run associated D-script),
you need to be running on <b>Solaris 11 build 35 or beyond</b>. You may want to check whether you have
<b>/usr/share/lib/java/dtrace.jar</b> on your machine or not. @DTrace and @DTraceRef annotations are ignored on other
platforms (Solaris 10 or below or any other OS).
</ul>
<a name="samples"></a>
<h3>BTrace Samples</h3>
<p>
<b><a href="../samples">BTrace samples</a></b>
</p>
<p>
One lines about samples:
<ul>
<li><a href="../samples/AWTEventTracer.java">AWTEventTracer.java</a> -
demonstates tracing of AWT events by instrumenting EventQueue.dispatchEvent()
method. Can filter events by instanceof check. This sample filters and prints
only focus events.
<li><a href="../samples/AllLines.java">AllLines.java</a> -
demonstates line number based BTrace probes. It is possible to probe
into any class (or classes) and line number(s). When the specified
line number(s) of specified class(es) is reached, the BTrace probe
fires and the corresponding action is executed.
<li><a href="../samples/ArgArray.java">ArgArray.java</a> -
prints all input arguments in every readXXX method of every class
in java.io package. Demonstrates argument array access and multiple
class/method matching in probe specifications.
<li><a href="../samples/Classload.java">Classload.java</a> - prints stack trace
on every successful classload (<code>defineClass</code> returns) by any userdefined
class loader.
<li><a href="../samples/CommandArg.java">CommandArg.java</a> - demonstrates
BTrace command line argument access.
<li><a href="../samples/Deadlock.java">Deadlock.java</a> - demonstrates
@OnTimer probe and <code>deadlock()</code> built-in function.
<li><a href="../samples/DTraceInline.java">DTraceInline.java</a> - demonstrates
@DTrace annotation to associate a simple one-line D-script with the BTrace
program.
<li><a href="../samples/DTraceRefDemo.java">DTraceRefDemo.java</a> - demonstrates @DTraceRef annotation to associate a D-script file with the BTrace
program. This sample associates <a href="../samples/classload.d">classload.d</a>with itself.
<li><a href="../samples/FileTracker.java">FileTracker.java</a> -
prints file open for read/write by probing into <code>File{Input/Output}Stream</code>
constructor entry points.
<li><a href="../samples/FinalizeTracker.java">FinalizeTracker.java</a>
- demonstrates that we can print all fields of an object and access
(private) fields (read-only) as well. This is useful in debugging
/ troubleshooting scenarios. This sample prints info on close()
/finalize() methods of java.io.FileInputStream class.
<li><a href="../samples/Histogram.java">Histogram.java</a> - demonstates
usage of BTrace maps for collecting histogram (of <code>javax.swing.JComponent</code>
objects created by an app - histogram by subclass name and count).
<li><a href="../samples/HistogramBean.java">HistogramBean.java</a> - demonstates
JMX integration. This sample exposes a Map as MBean attribute using <code>@Property</code>
annotation.
<li><a href="../samples/HistoOnEvent.java">HistoOnEvent.java</a> -
demonstrates getting trace output based on client side event. After
starting the script by BTrace client, press Ctrl-C to get menu to
send event or exit. On sending event, histogram is printed. This way
client can "pull" trace output whenever needed rather than BTrace
agent pushing the trace output always or based on timer.
<li><a href="../samples/JdbcQueries.java">JdbcQueries.java</a> - demonstrates
BTrace aggregation facility. This facility is similar to <b><a href="http://dlc.sun.com/osol/docs/content/DTRCUG/gcggh.html">
DTrace aggregation</a></b> facility.
<li><a href="../samples/JInfo.java">JInfo.java</a> - demonstrates
<code>printVmArguments()</code>, <code>printProperties()</code> and
<code>printEnv()</code> built-in functions.
<li><a href="../samples/JMap.java">JMap.java</a> - demonstrates
<code>dumpHeap()</code> built-in function to dump (hprof binary format)
heap dump of the target application.
<li><a href="../samples/JStack.java">JStack.java</a> - demonstrates
<code>jstackAll()</code> built-in function to print stack traces of
all the threads.
<li><a href="../samples/LogTracer.java">LogTracer.java</a> -
demonstrates trapping into an instance method (Logger.log) and
printing private field value (of LogRecord object) by <code>field()</code>
and <code>objectValue()</code> built-in functions.
<li><a href="../samples/MemAlerter.java">MemAlerter.java</a> -
demonstrates tracing low memory event by @OnLowMememory annotation.
<li><a href="../samples/Memory.java">Memory.java</a> - prints
memory stat once every 4 seconds by a timer probe. Demonstrates
memory stat built-in functions.
<li><a href="../samples/MultiClass.java">MultiClass.java</a>
- demonstrates inserting trace code into multiple methods of
multiple classes using regular expressions for <code>clazz</code>
and <code>method</code> fields of <code>@OnMethod</code> annotation.
<li><a href="../samples/NewComponent.java">NewComponent.java</a>
- tracks every <code>java.awt.Component</code> creation and increments
a counter and prints the counter based on a timer.
<li><a href="../samples/OnThrow.java">OnThrow.java</a> -
prints exception stack trace every time any exception instance is
created. In most scenarios, exceptions are thrown immediately after
creation. So, it we get stack trace of throw points.
<li><a href="../samples/ProbeExit.java">ProbeExit.java</a> -
demonstrates <code>@OnExit</code> probe and <code>exit(int)</code>
built-in function.
<li><a href="../samples/Sizeof.java">Sizeof.java</a>
- demonstates "sizeof" built-in function that can be used to
get (approx.) size of a given Java object. It is possible to get
size-wise histogram etc. using this built-in.
<li><a href="../samples/SocketTracker.java">SocketTracker.java</a>
- prints every server socker creation/bind and client socket accepts.
<li><a href="../samples/SocketTracker1.java">SocketTracker1.java</a>
- similar to SocketTracker.java sample, except that this sample uses
@OnProbe probes to avoid using Sun specific socket channel implementation
classes in BTrace program. Instead @OnProbe probes are mapped to @OnMethod probes
by BTrace agent.
<li><a href="../samples/SysProp.java">SysProp.java</a> -
demonstrates that it is okay to probe into System classes (like
java.lang.System) and call BTrace built-in functions in the action
method.
<li><a href="../samples/SubtypeTracer.java">SubtypeTracer.java</a> -
demonstrates that it is possible to match all subtypes of a given supertype.
<li><a href="../samples/ThreadCounter.java">ThreadCounter.java</a>
- demonstrates use of jvmstat counters from BTrace programs.
<li><a href="../samples/ThreadCounterBean.java">ThreadCounterBean.java</a>
- demonstrates exposing the BTrace program as a JMX bean with one
attribute (using @Property annotation).
<li><a href="../samples/ThreadBean.java">ThreadBean.java</a>
- demonstrates the use of preprocessor of BTrace [and JMX integratio].
<li><a href="../samples/ThreadStart.java">ThreadStart.java</a>
- demonstrates raising DTrace probes from BTrace programs. See also
<a href="../samples/jthread.d">jthread.d</a> - the associated D-script.
This sample raises a DTrace USDT probe whenever the traced program enters
java.lang.Thread.start() method. The BTrace program passes JavaThread's
name to DTrace.
<li><a href="../samples/Timers.java">Timers.java</a> - demonstrates
multiple timer probes (<code>@OnTimer</code>) in a BTrace program.
<li><a href="../samples/URLTracker.java">URLTracker.java</a> -
prints URL every time <code>URL.openConnection</code> returns
successfully. This program uses <a href="../samples/jurls.d">jurls.d</a>
D-script as well (to show histogram of URLs opened via DTrace).
<li><a href="../samples/WebServiceTracker.java">WebServiceTracker.java</a>
- demonstates tracing classes and methods by specifying class and
method level annotations rather than class and method names.
</ul>
</p>
</body>
</html>