Fully featured low overhead profiler for Java EE and Java SE platforms.
Monitoring and profiling solution for Gradle, Maven, Ant, JUnit and TestNG.
Easy to use performance and memory profiler for .NET framework.

Callback method parameter annotation @ClassRef

Callback parameter annotated with @ClassRef will be assigned with a reference to the class where the method being executed is defined.

Declaration type

Callback parameter annotated with @ClassRef should be declared as java.lang.Class.

In which callbacks can be used

Parameter annotated with @ClassRef can be used in any callback.

Notes on using @ClassRef vs @This

Use @ClassRef when applying probe to static methods, because @This is null in that case.

When applying probe to non-static methods, you can either use @ClassRef or call getClass() method of the object passed via @This.

However, please note the difference: the class returned by getClass() method will be the actual class of the object whose method is running, while @ClassRef will give the class where the method is defined. The result will be different if the method is defined in a base class and is not overridden in derived classes.

Example:

package com.foo;

class Base {
  void f() {...}
  void g() {...}
}

class Derived extends Base {
 // f() is overridden, g() is not overridden
 void f() {...}
}

...

@MethodPattern("foo.bar.*:*(*)")
public class MyProbe {
  public static void onEnter(@This Base _this, @ClassRef Class _class) {
    System.out.println(_this.getClass());
    System.out.println(_class);
  }
}

...

Derived obj = new Derived();

// Applying MyProbe to this call will print:
// class com.foo.Derived
// class com.foo.Derived
obj.f();

// Applying MyProbe to this call will print:
// class com.foo.Derived
// class com.foo.Base
obj.g();