Questions tagged [btrace]

BTrace 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.

BTrace 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.

BTrace Terminology

Probe Point

"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. Trace Actions or Actions

Trace statements that are executed whenever a probe "fires".

Action Methods

BTrace trace statements that are executed when a probe fires are defined inside a static method a class. Such methods are called "action" methods.

BTrace Program Structure

A BTrace program is a plain Java class that has one or more

public static void

methods that are annotated with BTrace annotations. 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.

BTrace Restrictions

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

  • can not create new objects.
  • can not create new arrays.
  • can not throw exceptions.
  • can not catch exceptions.
  • can not make arbitrary instance or static method calls - only the public static methods of com.sun.btrace.BTraceUtils class or methods declared in the same program may be called from a BTrace program.
  • (pre 1.2) can not have instance fields and methods. Only static public void returning methods are allowed for a BTrace class. And all fields have to be static.
  • can not 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).
  • can not have outer, inner, nested or local classes.
  • can not have synchronized blocks or synchronized methods.
  • can not have loops (for, while, do..while)
  • can not extend arbitrary class (super class has to be java.lang.Object)
  • can not implement interfaces.
  • can not contains assert statements.
  • can not use class literals.

Reference : https://github.com/btraceio/btrace/wiki

46 questions
0
votes
1 answer

strange things with btrace and java.lang.NoSuchMethodError

the main class: package com.xxx.yyy; public class Hello{ public static void main(String[] args){ A a = new A(); while(true){ try { a.execute(1000); Thread.sleep(1000); …
anzhilin
  • 3
  • 2
0
votes
1 answer

Passing the class name dynamically to clazz parameter in BTrace script

I need to pass application's package name to btrace script to clazz parameter dynamically when I attach the agent to the jvm .How can i achieve this ?
Ranga
  • 11
  • 1
0
votes
1 answer

NullPointerException when Starting an application with BTrace agent

I am using BTrace 1.2 and followed user guide from BTrace website. I have no problems using BTrace on running programs with command: btrace AllMethods.class but when I try to start application with BTrace agent using either: java…
Artur
  • 3,284
  • 2
  • 29
  • 35
0
votes
1 answer

In btrace, How can I compare and check the value of an Enum object?

I have the callback set up correctly in btrace. My argument list contains a custom Enum object. I want to print something if the Enum object equals to a specific value. I am OK with either comparing the Enum object directly, or comparing the string…
Erben Mo
  • 3,528
  • 3
  • 19
  • 32
0
votes
2 answers

btrace Invalid path 9116 specified: 2/No such file or directory

i use btrace in linux,Remind me: Invalid path 9116 specified: 2/No such file or directory my exec command:btrace 9116 AllMethods.java my home path is ok, i got Pid by jps, btrace version is 1.3.8.3
jsondream
  • 1
  • 1
0
votes
1 answer

btrace visualvm interfaces require ASM 5

When I run this simple Java8 program package test; public class TraceInt { public static void main(String args[]) throws InterruptedException{ TraceInt ti = new TraceInt(); while(true){ …
Dan
  • 9,681
  • 14
  • 55
  • 70
0
votes
0 answers

How to fixed it, 'Agent JAR not found or no Agent-Class attribute' when i use BTrace?

When I use BTrace, I got this problem. But I don't know how to fix it. The Linux command is: btrace 16625 LiveServiceMethods.class The problem is: Agent JAR not found or no Agent-Class attribute.
liu shuai
  • 53
  • 1
  • 1
  • 6
0
votes
1 answer

JAVA method for Class/Object creation destruction

I want to make a btrace script to profile object creation and destruction. For that I need to know Which Java methods are called when creating or deleting an Object or a Class? Thanks in advance.
neo
  • 111
  • 12
0
votes
1 answer

Running btrace on a short running program from NetBeans

I wanted to run btrace on a short running program from NetBeans so I started jvisualvm from a Window command prompt then started the program in debug mode from NetBeans and set a breakpoint on the first statement in the "main" class.. I then…
scvblwxq
  • 41
  • 5
0
votes
2 answers

how to use btrace probe static method?

i need to probe a static method. but the method invocation could not be probed. can anybody offer some help? my java code: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // CaseObject.java package test; public…
Brian HU
  • 187
  • 2
  • 10
0
votes
1 answer

How BTrace's -classpath param support many jar files?

Sometimes we need to depend third part jar file when using BTrace. Maybe i need import a.jar and b.jar to support BTrace script.How could i spell the -classpath param?
liuxiaori
  • 317
  • 2
  • 10
0
votes
1 answer

com.sun.btrace.VerifierException: Unsafe mode, requested by the script, not allowed

ubuntu 13.10 btrace 1.2.4 i have edit -Dcom.sun.btrace.unsafe=true param and assigned @BTrace( unsafe = true ) but when i run btrace script, it throw a exception: btrace 1625 ProductRPCNewBtrace.java DEBUG: btrace debug mode is set DEBUG: btrace…
liuxiaori
  • 317
  • 2
  • 10
0
votes
1 answer

why I can not create new object in Btrace unsafe mode?

In Btrace UserGuide(https://kenai.com/projects/btrace/pages/UserGuide ) it refers 'BTrace Restrictions' , and also refers in unsafe mode no ‘BTrace Restrictions’ BTrace Restrictions can not create new objects. can not create new arrays. …
0
votes
1 answer

what's the mean of the code about btrace

In the following code: import static com.sun.btrace.BTraceUtils.*; import com.sun.btrace.annotations.*; import org.jboss.deployment.DeploymentInfo; @BTrace public class Trace{ @OnMethod( clazz="org.jboss.deployment.SARDeployer", …
fuyou001
  • 1,594
  • 4
  • 16
  • 27
0
votes
1 answer

btrace test the memory used by calling a function

Using btrace, I want to test how much heap my function used, so I write: Above the code is samples of btrace I used. And operating my function twice I got two different results: As the pic shows, the heaps cost differs:one is as much as twice as…
fleture
  • 91
  • 1
  • 7