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
6
votes
1 answer

what is the overhead of BTrace

It is mentioned in BTrace docs that BTrace has almost no overhead when idle. Does that mean BTrace has overhead only and only when some probe is met and it is being processed? Also, when the Probe is being processed, it would take some CPU to do the…
Sandeep Jindal
  • 14,510
  • 18
  • 83
  • 121
4
votes
1 answer

btrace with JDK5

Can we use bTrace with JDK5 or lesser versions? If not, what is that things which is provided in JDK6 that makes bTrace work? My understanding is that btrace working on Java Byte Code Instrumentation which was there for JDK5 as well. is there some…
Sandeep Jindal
  • 14,510
  • 18
  • 83
  • 121
4
votes
3 answers

How can write logs to a file in btrace?

I have following btrace script. I would like to record entry and exit of functions in a specific class. .. package com.sun.btrace.samples; import com.sun.btrace.BTraceUtils; import com.sun.btrace.Profiler; import…
Jayan
  • 18,003
  • 15
  • 89
  • 143
3
votes
1 answer

What time units are provided by BTrace when using @Duration annotation? Millis, micros or maybe nanos? Cannot find it in the documentation

Look at method 'methodExit'. What units of time are held in parameter "@Duration long time"? package com.sun.btrace.samples; import com.sun.btrace.Profiler; import com.sun.btrace.annotations.*; import static com.sun.btrace.BTraceUtils.*; import…
Wojciech Wirzbicki
  • 3,887
  • 6
  • 36
  • 59
3
votes
1 answer

Btrace not returning Anything

So I am introducing myself to btrace but currently I am getting no output out of it. With this script : package com.sun.btrace.samples; import com.sun.btrace.annotations.*; import static com.sun.btrace.BTraceUtils.*; @BTrace public class AllLines…
3
votes
2 answers

Convert char[] to String in BTrace

I'm profiling application with btrace and faced with limitation. I try to get a name of current java.lang.Thread. Normaly you can call getName() but it's forbidden in btrace-scripts (any calls exception BTraceUtils). Is there any idea how to get…
Max
  • 53
  • 4
3
votes
2 answers

JMH tests with a javaagent

I'm trying to measure the impact of a JVM agent on performance, to make sure it won't invalidate the tests we're trying to run (and maybe make a case for taking some samples from prod). This case is a set of BTrace scripts which will run during…
ssube
  • 47,010
  • 7
  • 103
  • 140
3
votes
1 answer

Using BTrace to find when a class is created for the first time

I'm trying to use BTrace to find when a certain type is first instantiated in my program (Eclipse debugger isn't able to find it) as I'm seeing some strange behaviour (the Javolution XMLStreamWriterImpl is somehow adding elements to my XML before it…
MeanwhileInHell
  • 6,780
  • 17
  • 57
  • 106
3
votes
3 answers

How to track java basic type array?

I have a memory issue. And I found a huge char[] in heap dump. But I don't know where it come from. It is a weak/soft reference. Is there any tool/approach to track this kind of basic type array allocation?
crabhit
  • 139
  • 1
  • 2
  • 7
3
votes
2 answers

Unable to open socket file: target process not responding or HotSpot VM not loaded

I need to execute the following command from a web application deployed on cloudfoundry. String javaHome = System.getenv("JAVA_HOME"); String javaLocation = javaHome+"/bin/java"; String command = javaLocation+" -Xms256m -Xmx512m…
user821075
  • 61
  • 2
  • 5
2
votes
1 answer

btrace equivalent of String replaceAll

I want to prefix each line of a stack trace with a string. Is there a way to replace all patterns in a String with something else in btrace?
billc.cn
  • 7,187
  • 3
  • 39
  • 79
2
votes
1 answer

Execute shell script from spring web application deployed on cloudfoundry

I am trying to call Btrace script from Spring web application deployed on cloudfoundry. The execution command is /var/vcap/data/dea/apps/petclinic-0-fef4b0e052097a0cd2bedb8018c28dcd/tomcat/webapps/ROOT/WEB-INF/classes/bin/btrace.sh 532…
user821075
  • 61
  • 2
  • 5
1
vote
1 answer

How can I log BTrace into file Using VisualVM

I found the method of logging BTrace output into file by using command with Btraceagent. Are there anything else methods to do this via VisualVM without using command line? Thank you
jane
  • 11
  • 2
1
vote
1 answer

In btrace, how can I print a byte array in a readable format?

I want to use btrace to inspect the byte[] value of a method return use the @Return annotation. The byte array is actually a normal string encoded using utf8. The class is like below: Class A { byte[] method1() { ... } } I have tried…
cainanyang
  • 179
  • 1
  • 1
  • 6
1
vote
0 answers

How to match multiple packages in btrace

Assuming I want to trace method calls in all the classes in packages com.abc and com.def I put the following in my tracing script: @OnMethod(clazz = "/com\\.(abc|def)\\..*/", method = "/.*/") ran the script, but the output only contained method…
ka3ak
  • 2,435
  • 2
  • 30
  • 57
1
2 3 4