Skip to content

Commit 17c8613

Browse files
authored
Update BTraceTutorial.md
1 parent ab115e7 commit 17c8613

1 file changed

Lines changed: 25 additions & 25 deletions

File tree

docs/BTraceTutorial.md

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Demonstrates the BTrace ability to instrument a class.
99

1010
#### HelloWorld Class
1111

12-
```
12+
``` java
1313
package extra;
1414

1515
abstract public class HelloWorld extends HelloWorldBase {
@@ -143,7 +143,7 @@ Rather than regular *javac* the BTrace compiler is used - causing the script to
143143
This is the main purpose of BTrace - inject a custom code to custom locations to give the insights about the internal state and dynamics of the application.
144144

145145
1. Getting just the information that any method is being executed
146-
```
146+
``` java
147147
package helloworld;
148148
import ...;
149149

@@ -157,7 +157,7 @@ public class HelloWorldTrace {
157157
```
158158

159159
2. Get the method names
160-
```
160+
``` java
161161
package helloworld;
162162
import ...;
163163

@@ -171,7 +171,7 @@ public class HelloWorldTrace {
171171
```
172172

173173
3. Intercept only a particular method
174-
```
174+
``` java
175175
package helloworld;
176176
import ...;
177177

@@ -185,7 +185,7 @@ public class HelloWorldTrace {
185185
```
186186

187187
4. Intercept only a particular method with name matching the handler name
188-
```
188+
``` java
189189
package helloworld;
190190
import ...;
191191

@@ -201,7 +201,7 @@ public class HelloWorldTrace {
201201
5. Intercept methods with names matching certain patterns
202202
__Note:__ you can use pattern matching for the class names, too
203203

204-
```
204+
``` java
205205
package helloworld;
206206
import ...;
207207

@@ -216,7 +216,7 @@ public class HelloWorldTrace {
216216

217217
6. Intercept methods with names matching certain patterns and inspect their parameters
218218

219-
```
219+
``` java
220220
package helloworld;
221221
import ...;
222222

@@ -232,7 +232,7 @@ public class HelloWorldTrace {
232232
```
233233

234234
7. Intercept method with names matching certain patterns and discover their signatures
235-
```
235+
``` java
236236
package helloworld;
237237
import ...;
238238

@@ -249,7 +249,7 @@ public class HelloWorldTrace {
249249

250250
__Note:__ 'extra.HelloWorldBase.callD()' doesn't show up - it is defined in the superclass of 'extra.HelloWorld' and therefore not intercepted.
251251

252-
```
252+
``` java
253253
package helloworld;
254254
import ...;
255255

@@ -266,7 +266,7 @@ public class HelloWorldTrace {
266266

267267
__Note:__ The order of the un-annotated parameters must correspond to the order of the traced method parameters. Annotated parameters may be placed anywhere.
268268

269-
```
269+
``` java
270270
package helloworld;
271271
import ...;
272272

@@ -286,7 +286,7 @@ Eg. having the VM method signature in form of (Ljava/lang/String;I)V will transl
286286

287287
__Note:__ We are using overloaded method here and specifying the signature helps BTrace determine which method should be instrumented
288288

289-
```
289+
``` java
290290
package helloworld;
291291
import ...;
292292

@@ -302,7 +302,7 @@ public class HelloWorldTrace {
302302
11. Intercept method with a particular name and capture its return value
303303
`location=@Location(Kind.RETURN)` sets up the instrumentation to be inserted just before the method exits
304304

305-
```
305+
``` java
306306
package helloworld;
307307
import ...;
308308

@@ -317,7 +317,7 @@ public class HelloWorldTrace {
317317

318318
12. Inspect the content of an instance variable in the method declaring class
319319

320-
```
320+
``` java
321321
package helloworld;
322322
import ...;
323323

@@ -333,7 +333,7 @@ public class HelloWorldTrace {
333333

334334
Or retrieve the `java.lang.Field` instance first and perform a check before trying to retrieve the field value.
335335

336-
```
336+
``` java
337337
package helloworld;
338338
import java.lang.Class;
339339
import java.lang.reflect.Field;
@@ -357,7 +357,7 @@ public class HelloWorldTrace {
357357

358358
__Note:__ Need to use @Location(Kind.RETURN) to be able to capture the execution duration
359359

360-
```
360+
``` java
361361
package helloworld;
362362
import ...;
363363

@@ -377,7 +377,7 @@ __Note:__ 'class', 'method' etc. directly in the @OnMethod annotation will deter
377377
__Note:__ @ProbeMethodName and @ProbeClassName refer to the context method and class; @TargetMethodOrField refers to the traced method invocation
378378
__Note:__ You can use the 'type' annotation parameter in @OnMethod annotation to restrict the context methods and in @Location to restrict the traced method invocations
379379

380-
```
380+
``` java
381381
package helloworld;
382382
import ...;
383383

@@ -399,7 +399,7 @@ public class HelloWorldTrace {
399399

400400
15. Measuring the duration of methods invoked from inside a particular method
401401

402-
```
402+
``` java
403403
package helloworld;
404404
import ...;
405405

@@ -424,7 +424,7 @@ public class HelloWorldTrace {
424424
__Note:__ The captured parameters pertain to the invoked method rather than the context method
425425
__Note:__ The @Self annotated parameter captures the context instance and @TargetInstance annotated parameter captures the instance the method is invoked on
426426

427-
```
427+
``` java
428428
package helloworld;
429429
import ...;
430430

@@ -457,7 +457,7 @@ Called when the traced application is about to exit. Allows to capture the exit
457457

458458
__Note:__ The signature of the handler method __MUST__ be 'void (int)'
459459

460-
```
460+
``` java
461461
package helloworld;
462462
import ...;
463463

@@ -476,7 +476,7 @@ Called whenever an exception is thrown from anywhere in the BTrace handlers.
476476

477477
__Note:__ The signature of the handler method __MUST__ be 'void (java.lang.Throwable)'
478478

479-
```
479+
``` java
480480
package helloworld;
481481
import ...;
482482

@@ -496,7 +496,7 @@ Allows to register a handler to be invoked periodically at defined intervals.
496496
__Note:__ The annotation parameter takes the interval value in milliseconds
497497
__Note:__ The signature of the handler method __MUST__ be 'void ()'
498498

499-
```
499+
``` java
500500
package helloworld;
501501
import ...;
502502

@@ -513,7 +513,7 @@ public class HelloWorldTrace {
513513

514514
Used to raise events from external clients (eg. the command line client). The annotation takes a String parameter which is the event name. When not provided the event is considered to be 'unnamed'.
515515

516-
```
516+
``` java
517517
package helloworld;
518518
import ...;
519519

@@ -527,7 +527,7 @@ public class HelloWorldTrace {
527527
```
528528
or
529529

530-
```
530+
``` java
531531
package helloworld;
532532
import ...;
533533

@@ -552,7 +552,7 @@ The sampling implementation in BTrace guarantees that at least one invocation of
552552

553553
__Note:__ Even though the 'callD' method is executed 100 times we will get only ~10 hits - as dictated by the 'mean' parameter.
554554

555-
```
555+
``` java
556556
package helloworld;
557557
import ...;
558558

@@ -573,7 +573,7 @@ __Note:__ In this case the 'mean' parameter actually specify the lowest number o
573573
__Note:__ Because the adaptive sampling needs to collect timestamps in order to maintain the overhead target the lowest value for the 'mean' parameter is 180 (cca. 60ns for gettint start/stop timestamp pair multiplied by the safety margin of 3)
574574
__Note:__ The 'callD' method is very short and the number of iteration is rather limited - we will most probably get only one hit here
575575

576-
```
576+
``` java
577577
package helloworld;
578578
import ...;
579579

0 commit comments

Comments
 (0)