previous      content      next
Probe class annotation @MethodPattern

Probe class must be annotated with @MethodPattern annotation in order to specify which methods the callbacks will be applied to.

One or more method patterns can be specified in the following format ('*' wildcard is allowed):

class_name : method_name ( parameters )

Part
Description
Examples
class_name Full qualified class name, dot-separated. Inner classes are separated with dots too.

Particular class: com.foo.Bar

Class with name ending with 'Helper': *Helper

Any class in a package: java.io.*

Any class: *

method_name Method name. To specify a constructor, use its classes short name.

Method with particular name: toString

Any getter: get*

Any method, including constructors: *

parameters

Comma-separated list of parameter types. Space characters between type names and commas are allowed (but not required).

Class names should be full qualified, dot-separated, except for java.lang.Object, java.lang.Object[], java.lang.String, java.lang.String[] for which a short form is allowed: Object, Object[], String, String[].

Primitive classes are specified in format used in Java source code: int, char etc.

Arrays are specified as type[].

Use empty string to specify a method with no parameters.

No parameters: empty

Any number of parameters, including zero: *

3 parameters of particular types: String, int, int

First parameter is an array of class com.Foo: com.Foo[], *


The annotation is declared as...

package com.yourkit.probes;

import java.lang.annotation.ElementType;
import java.lang.annotation.Target;

@Target(ElementType.TYPE)
public @interface MethodPattern {
  String[] value();
}

...and allows to specify one or more patterns for a probe. For example:

import com.yourkit.probes.*;

// Instrument calls of method 'findPerson' in class 'com.foo.Person', which has 2 parameters of particular types
@MethodPattern("com.foo.Person:findPerson(String, int)")
public class MyProbe1 {
  //...
}

// Instrument all methods in classes 'com.Foo' and 'com.Bar'
@MethodPattern(
  {
    // should match at least one of them
    "com.Foo:*(*)",
    "com.Bar:*(*)"
  }
)
public class MyProbe2 {
  //...
}

// Instrument methods toString() in all classes in package com.foo
@MethodPattern("com.foo.*:toString()")
public class MyProbe3 {
  //...
}

// Instrument all methods in classes whose names end with 'Helper' and have int[][] as a first parameter
@MethodPattern("*Helper:(int[][],*)")
public class MyProbe4 {
  //...
}


previous      content      next