views:

33

answers:

2

Hi folks! I'm profiling application with btrace (https://btrace.dev.java.net) 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 String from char[].

The original task is check if name of thread contains sub-string and only then log out tracing info (reducing output).

thanks, Max.

+1  A: 

Some info that may be helpful to others:

https://btrace.dev.java.net/source/browse/btrace/docs/usersguide.html?rev=1.7

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 may be called from a BTrace program.
  • 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 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 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.

http://btrace.kenai.com/javadoc/1.1/com/sun/btrace/BTraceUtils.html

polygenelubricants
A: 

Hi Max, just use the "built-in" function name(thread) from BTraceUtils. One of the types it takes as its argument is Thread and it returns the thread's name. Also, there is threadId(thread) function which returns the thread's ID.

You can find many useful function in the BTraceUtils class - check out the online javadoc.

Cheers,

JB

JB
Thanks JB! This is really help me.
Max