PerformanceTestHelper API
As before, the PerformanceTestHelper
helps by providing a seamless interface
into the yourkit profiler, for various options of sampling, tracing, monitoring threads
or timing in threads:
public static PerformanceTestCallableResult profileSample(int warmups, int reps, PerformanceTestCallable callable)
throws Exception {
public static PerformanceTestCallableResult profileTrace(int warmups, int reps, PerformanceTestCallable callable)
throws Exception {
public static PerformanceTestCallableResult monitor(int warmups, int reps, int numThreads,
PerformanceTestCallable callable) throws Exception {
public static PerformanceTestCallableResult timeInThreads(int warmups, int reps, int numThreads,
PerformanceTestCallable callable) throws Exception {
The PerformanceTestHelper
utility class uses reflection to know whether the
yourkit library is available or not. If it is not available (such as on the build
server), the behavior reverts to simple timing protocols of the corresponding callable
iterations. If it is available (such as on a developer's workstation, and they want to
profile a test), then the yourkit profiler is connected. This would require running the
test under a profile session, else an error is produced.
Profiling a callable is somewhat similar to the simple timing of a callable, except for some added steps:
- Performs some warmups.
- Forces garbage collection via the yourkit API.
- Starts the given profile type (sample vs trace)- the test should be run without automatically starting the profiler.
- Wrap the repetition loop in a timer.
- Capture a snapshot.
This design approach allows profile/performance tests to be checked into version control, for re-profiling at a later point, and for documentation examples of how to profile code, and so on.