InfoQ

InfoQ

News

My Bookmarks

Login or Register to enable bookmarks for unlimited time.

The content has been bookmarked!

There was an error bookmarking this content! Please retry.

Discussing 5+ Ways to Trace Java Execution

Posted by R.J. Lorimer on Dec 07, 2007

Sections
Development,
Architecture & Design
Topics
Debugging ,
Java ,
Performance & Scalability
Tags
Java SE
Zviki Cohen has published Five ways for tracing Java execution, based on his experience exploring and having to understand code he didn't write. He's found that simply reading source code (and in some cases decompiling), can be a very tedious and error prone process. Instead, he recommends five different runtime tracing methods to observe Java code while it is executing, eliminating many of the disadvantages of trying to learn someone else's code. Here is a condensed list of his five suggestions:

 

  1. The Basic: Breakpoints and Step-by-Step Execution "Start with the simplest way: set up breakpoints and start tracing your execution. It is best when: You need a quick and simple solution, you have all the code and you know where you want to stop. You need elaborate information in a given point (arguments, local variables, etc.)."
  2. The Primal: Debug Messages "We continue by setting up debug messages. The simplest way is to use System.out.println statements to print out messages to the console. It is best when: You own the code and you have a good idea of what you're looking for. Very good solution for event handlers. It's high performance makes it practical for understanding which event is fired when throughout the execution of complex flows."
  3. The Hot Shot: Dynamic Proxy "An improvement over simple debug messages. Dynamic Proxy is a special Java feature which enables the developer to introduce a proxy class, sitting in front of a given class and intercepting all the calls through a given interface. It is best when: It's a great solution for event handlers. You can set up a dummy event handler with a generic proxy in seconds and see the sequence of events. This is simplest and quickest method when it comes to understanding event handlers."
  4. The Brute Force: Run-time Profiler "Profilers are powerful tools that trace all the calls in the system through special JVM hooks. However, it's like using a 10 pound hammer on a half inch nail. It is best when: You want a complete picture for a very specific operation (i.e. very short execution flow)."
  5. The New Age: Aspects "Aspect Oriented Programming (AOP) is a non-trivial idea. Without going into the concept of Aspects, I'm just looking at the bottom line: it's a quick and easy way of intercepting the execution of your code. You can selectively set hooks around methods, constructors, field access, etc., without modifying the original code. In these hooks you can print debug messages. It is best when: You want to trace the execution of a code you can rebuild."

Until February 2007, Zviki Cohen was an architect and senior consultant for Amdocs, and is now a private entrepreneur in the software space.

Does it qualify as anything? by Shay Banon Posted
Re: Does it qualify as anything? by Michael Krumlauf Posted
Re: Does it qualify as anything? by Shay Banon Posted
Re: Does it qualify as anything? by Scott Delap Posted
Where's DTrace? by Ralph Poellath Posted
Re: Where's DTrace? by Alex Popescu Posted
MaintainJ for Java execution trace by Choudary Kothapalli Posted
Aspects by Andrew Sutherland Posted
Another tool for that by Rejeev Divakaran Posted
  1. Back to top

    Does it qualify as anything?

    by Shay Banon

    This type of blog posts always make me laugh. It is right up there with: If you want to perform a repeating operation N times, use a for loop.

  2. Back to top

    Re: Does it qualify as anything?

    by Michael Krumlauf

    While the contents of the post may seem obvious to an experienced developer, those with less experience may find it timely and helpful. I know that for me it never hurts to review the basics from time to time.

  3. Back to top

    Re: Does it qualify as anything?

    by Shay Banon

    Start a debugger and do a step by step execution? Add debug messages? Common, there is a limit for "less experienced". Again, my "for loop example" stands.

  4. Back to top

    Re: Does it qualify as anything?

    by Scott Delap

    While it does seem trivial on one hand, I can't tell you how many programmers I've seen that don't know how to effectively use a debugger.

  5. Back to top

    Where's DTrace?

    by Ralph Poellath

    Shouldn't DTrace at least be mentioned in tis list?

  6. Back to top

    Re: Where's DTrace?

    by Alex Popescu

    Shouldn't DTrace at least be mentioned in tis list?


    I guess it should, but before that DTrace should be supported on multiple OSes, isn't it? (I've heard it was added to Mac OS Leopard, but I don't know if it runs on Linux or Win boxes).

    ./alex
    --
    .w( the_mindstorm )p.
    Alexandru Popescu
    Senior Software Eng.
    InfoQ Techlead/Co-founder

  7. Back to top

    MaintainJ for Java execution trace

    by Choudary Kothapalli

    MaintainJ uses AspectJ to capture the execution trace. It then generates runtime sequence and class diagrams from that trace. MaintainJ has a simple UI that works and shows what a developer needs to quickly understand complex applications.And it is very easy to get started with MaintainJ.

    Check the video demos at maintainj.com/userGuide.jsp?param=demos . Check the testimonials at www.maintainj.com/smf/index.php?board=6.0

    Regards,
    Choudary Kothapalli.

  8. Back to top

    Aspects

    by Andrew Sutherland

    Aspects can actually be used to trace the execution of code without having to rebuild it if you use load-time weaving.

  9. Back to top

    Another tool for that

    by Rejeev Divakaran

    I have written a small tool for tracing method calls.
    Please see rejeev.blogspot.com/2009/04/method-tracing.html

Educational Content

Jesper Boeg on Priming Kanban

In this interview, Jesper Boeg, author of the new InfoQ book – Priming Kanban, discusses the keys to using Kanban effectively, and how to get started if you are currently using other approaches.

New-age Transactional Systems - Not Your Grandpa's OLTP

John Hugg discusses high volume transaction processing applications with high and low frequency profiles, and how VoltDB can be used for that purpose.

Cool Code

Kevlin Henney examines code samples to see what can be learned from them starting from the premise that one won’t write great code unless he knows how to read it.

Collaboration: At the Extremities of Extreme

Jason Ayers share the observations he made watching a team of developers collaborating in real time on the same code base, pushing XP, pair programming and continuous integration to their extremes.

Yesod Web Framework

Michael Snoyman presents Yesod, a web framework written in Haskell and containing a web server, templating, ORM, libraries (templating, gravatar, etc.).

Transactions without Transactions

Richard Kreuter and Kyle Banker on how to avoid classical RDBMS transactional systems by using compensation mechanisms, transactional messaging or transactional procedures.

Attila Szegedi on JVM and GC Performance Tuning at Twitter

Attila Szegedi talks about performance tuning Java and Scala programs at Twitter: how to approach GC problems, the importance of asynchronous I/O, when to use MySQL/Cassandra/Redis, and much more.

10 tips on how to prevent business value risk

One category of risk that project teams need to ensure they address is business value failure – delivering a product that fails to provide value for the business investor.