- System requirements
- Profiler architecture
- Running the profiler
- Profiler activation
- Start profiling
- Solving performance problems
- CPU profiling
- Threads
- Deadlock detector
- Memory profiling
- Garbage collection
- Monitor profiling
- Exception profiling
- 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()
- Callbacks onUncaughtException() and onUncaughtExceptionExt()
- Parameter annotation @Param
- Parameter annotation @Params
- Parameter annotation @This
- Parameter annotation @ClassRef
- Parameter annotation @MethodName
- Parameter annotation @MethodParameterTypes
- Parameter annotation @MethodSignature
- Parameter annotation @OnEnterResult
- Parameter annotation @ReturnValue
- Parameter annotation @ThrownException
- Probe application rules
- Data storage
- Performance Charts
- Inspections: automatic recognition of typical problems
- Automatically trigger actions on event
- Summary, snapshot annotation, automatic deobfuscation
- Time measurement (CPU time, wall time)
- Filters
- Snapshot directory customization
- Export of profiling results to HTML, CSV, XML, plain text
- Profiler Java API
- Profiler HTTP API
- Command line tool to control profiling
- Settings
- FAQ: How to profile in my scenario?
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.