- System requirements
- Profiler architecture
- Profiler installation
- Uninstall profiler
- Running the profiler
- Profiler activation
- Welcome screen
- Start profiling
- Profiling overhead
- Snapshots
- Solving performance problems
- CPU profiling
- Thread profiling
- Virtual threads support
- Object allocation profiling
- Memory profiling
- Monitor profiling
- Exception profiling
- Telemetry
- Probes: monitor events of various kinds
- Events in user interface
- Event inspections
- Built-in probes
- Probe classes
- Monitoring method invocation events
- Probe class annotation @MethodPattern
- Callback onEnter()
- Callback onReturn()
- Callback onExit()
- Callbacks onUncaughtException() and onUncaughtExceptionExt()
- Parameter annotation @Param
- Parameter annotation @Params
- Parameter annotation @This
- Parameter annotation @ClassRef
- Parameter annotation @MethodName
- Parameter annotation @MethodTimeMs
- Parameter annotation @MethodTimeNs
- Parameter annotation @MethodParameterTypes
- Parameter annotation @MethodSignature
- Parameter annotation @OnEnterResult
- Parameter annotation @ReturnValue
- Parameter annotation @ThrownException
- Probe application rules
- Data storage
- Inspections: automatic recognition of typical problems
- Automatically trigger actions on event
- Automatic deobfuscation
- Summary
- Filters
- Profiler command line
- Export of profiling results to external formats
- Profiler Java API
- Profiler HTTP API
- Settings
- Troubleshooting and FAQ
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.
Parameters
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
@MethodPattern("com.foo.Person:findPerson(*)")
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.