tags:

views:

104

answers:

4

Hi

I'd like to trace a java application at runtime to log and later analyze every its behaviour.

Is there a possibility to hook into a java application to get runtime information like method calls (with parameters and return values) and the status of an object (i.e. its attributes and whose values)?

My goal is to get a complete understanding of the applications behaviour and how it deals with the data.

+1  A: 

Use a profiler. For example JProfiler or one from this overview of opensource java profilers. Whenever I had to find deadlocks for example, these tools were priceless...

raoulsson
A: 

In Netbeans the profiler exist and work properly for use it see http://profiler.netbeans.org/

SjB
+1  A: 

If you need highly customized logging and runtime processing, one alternative to profilers is to use aspects and load-time weaving.

We use AspectJ in this way to capture and log the authentication information for users who call a number of low-level methods for debugging purposes and to undo mistaken changes.

ZoogieZork
Okay, just to clarify: Using AspectJ and load-time weaving. Would it be possible to get informed, when a method is called and get every parameters with their actual values. And, additionally, all attributes with their actual values of the object whose method just was called?
Phil
Yes, all of that information should be available via the `thisJoinPoint` and `thisJoinPointStaticPart` special objects; the second example here should get you started: http://www.eclipse.org/aspectj/doc/released/progguide/examples-development.html#tracing-using-aspects and also http://dev.eclipse.org/viewcvs/indextech.cgi/aspectj-home/doc/api/org/aspectj/lang/JoinPoint.html
ZoogieZork
A: 

Maybe have a look at Glassbox a troubleshooting agent for Java applications that automatically diagnoses common problems. From Glassbox - Automated monitoring and troubleshooting using AOP:

Glassbox deploys as a war file to your appserver and then uses AspectJ load time weaving to monitor application components and other artifacts, in order to identify problems like excess or failed remote calls, slow queries, too many database queries, thread contention, even what request parameters caused failures. All this without changing the code or the build process. (...)

Glassbox monitors applications non-invasively by using aspects to track component interactions. We also monitor built-in JMX data, notably on a Java 5 VM we sample thread data (every 100 ms by default). As a request is processed, we summarize noteworthy events such as where time was spent and what parameters were involved in making things slow or fail. We also detect higher-level operations (such as Struts actions or Spring controllers) that we use to report on. Our AJAX Web client then provides summaries of status by operation on the machines being monitored and we generate a more detailed analysis on request. Glassbox allows monitoring clusters of servers: the Web app uses JMX Remote or direct RMI to access data from remote servers. We also provide JMX remote access to the lower-level summary statistics.

It's a nice application, give it a try.

Pascal Thivent