Exercise 1.4: Creating more advanced probes

Before you begin, you must complete Exercise 1.3: Deploying your probe.

Probekit can be used to solve many real-world debugging and runtime-analysis problems. You've now learned the basics of writing and deploying probes, so this and the following lesson will not walk you through the activities, but instead provide suggestions for probes that you might write to investigate your own application.

Investigating an exception

Assume that some method in a servlet occasionally throws an exception. The log message that comes out is not very helpful; it doesn't clearly indicate what the problem is. To get more information, you can write a probe that executes whenever the method throws an exception, and the Java code in the probe's fragment can log the exception message and also the arguments to the method. This will help you see why the exception is being thrown.

When you write and deploy this probe, note the following points:

Investigating a method's erratic performance

Here is a fairly intricate probe example. Let's say there is a method in your program that usually executes quickly but occasionally takes a long time (longer than 100ms, for example).

You can write a probe that takes note of the entry and exit times whenever the method executes. When the execution time is short, the probe does nothing. When the execution time is long, the probe reports the arguments to the method and other important information about program state at the time. This allows you to determine the circumstances that lead to the longer execution times.

When you write the probe, note the following points:

At method entry, this probe records the current time. At method exit, the probe compares the current time and the recorded entry time, and if more than a certain amount of time has elapsed (the amount you specified in "thresholdDuration"), it prints a report using System.out.

Investigating erratic performance in a recursive or multi-threaded method

The probe that we just discussed doesn't work for methods that are recursive (directly or indirectly), and it doesn't work for methods that might be running in multiple threads at the same time. To solve the recursive problem, you could record the entry times on a Stack; to solve the multi-threaded problem, you could store the stack in a ThreadLocal variable.

Here is what you need to create a recursion-safe, thread-safe version of the probe:

Continue the tutorial with Exercise 1.5: Using a runtime library for more complex probe logic.

Terms of use | Feedback
(C) Copyright IBM Corporation 2000, 2005. All Rights Reserved.