Fully featured low overhead profiler for Java EE and Java SE platforms.
Easy-to-use performance and memory .NET profiler for Windows, Linux and macOS.
Secure and easy profiling in cloud, containers and clustered environments.
Performance monitoring and profiling of Jenkins, Bamboo, TeamCity, Gradle, Maven, Ant and JUnit.

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 ( parameter_types )

You can optionally specify that class or method must have particular annotations. Put @annotation before the class and/or the method pattern accordingly:

[@class_annotation] class_name : [@method_annotation] method_name ( parameter_types )

Part Description Examples
class_name Full qualified class name, dot-separated. Inner class part(s) are separated with "$" sign.

Particular class: com.foo.Bar

Class with name ending with 'Helper': *Helper

Any class in a package: java.io.*

Any class: *

class_annotation (optional) Specify that matching classes must have particular annotation. If not specified, class with any annotations or with no annotations at all will match.

All toString methods in classes in package com.bar annotated with @Foo:
@Foo com.bar.* : toString()

method_name Method name. To specify a constructor, use <init>.

Method with particular name: toString

Any getter: get*

Any method, including constructors: *

method_annotation (optional) Specify that matching methods must have particular annotation. If not specified, methods with any annotations or with no annotations at all will match.

All JUnit tests: *:@org.junit.Test *()

parameter_types

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 types should be named as 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 specifies 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 {
  //...
}

YourKit uses cookies and other tracking technologies to improve your browsing experience on our website, to show you personalized content and targeted ads, to analyze our website traffic, and to understand where our visitors are coming from.

By browsing our website, you consent to our use of cookies and other tracking technologies in accordance with the Privacy Policy.