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.

Callback onEnter()

To execute a code on method entry, define callback method onEnter() in probe class.

Only one method named onEnter() can exist in a probe class. You can omit onEnter() method if it is not needed for your probe.


The callback can have any number of parameters, including zero.

Each of the parameters must be annotated with one of the following annotations:

Return type

onEnter() can be void or return a value.

If onEnter() is not void, the returned value will be accessible in onReturn(), onUncaughtException() and onUncaughtExceptionExt() callbacks of the same probe class with the help of a parameter annotated with @OnEnterResult. This approach enables effective way of data transfer between method enter and exit callbacks (the value is passed via stack).

Example 1:

import com.yourkit.probes.*;

// Instrument calls of method 'findPerson' in class 'com.foo.Person', which has 2 parameters
@MethodPattern("com.foo.Person:findPerson(String, int)")
public class MyProbe {
  public static void onEnter(
    @Param(1) Object param1,
    @Param(2) int param2
  ) {

Example 2:

import com.yourkit.probes.*;

// Instrument calls of method(s) 'findPerson' in class 'com.foo.Person', with any signature,
// and print method execution times
public class MyProbe {
  public static long onEnter() {
    return System.currentTimeMillis();

  public static void onReturn(
    @OnEnterResult long enterTime
  ) {
    long exitTime = System.currentTimeMillis();
    System.out.println("method execution time: " + (exitTime - enterTime));

Special notes on instrumenting a constructor

Using callback parameter annotated with @This in a probe applied to a constructor affects the point where the call to onEnter() is injected. Please find detail here.

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.