Sunday, May 30, 2010

Introduction to Program Tracing

I’m trying to understand more of program tracing.

First thing we have to agree on is what do I mean by program tracing. Program tracing is collecting the dynamic execution of a program. What this means is actually understand what methods were executed when.

The most common way that I have come across people doing this is by using Log4J trace logging level. The way that people do this is usually log.trace(“Method ENTER”); Then the method, but the last line of the method is: log.trace(“Method EXIT”);

This works fine sometimes, but what happens when an exception occurs, we will never reach the “Method EXIT” line. Also this has a problem in that it is a very manual process. We have to manually add these statements into the code and it just clutters it up.

There is a simple solution to these problems. The Java JPDI API. This API allows another program to be written that will receive event notifications when threads are started, and methods are entered and exited. This way we don’t have to clutter out source code with the tracing information.

So far I have found one application MuTT that handles multi-threaded tracing, but it does it by outputting each threads trace into a separate file. This shows what each thread does but not how they interacted.

I’m currently looking for a way to keep track of how the threads were interleaved for a specific trace. This way I can find out what really influenced the values of different fields in the code, and the specific path we followed to show an issue.

No comments: