This discussion is archived
3 Replies Latest reply: Apr 13, 2009 12:41 AM by 843810 RSS

How to monitor method calls to/by an object?

843810 Newbie
Currently Being Moderated
Hello,

I don't whether this question fits in this category. If not, I am sorry. But if you can help me, that would be great.

I am doing a project where I need to monitor the communication between two objects during runtime. I mean I should log the method calls to/by an object during runtime. The constrain is that I should not change the code of either objects. So, if you guys know any articles/papers/projects where I can find some information, please let me know.

Thanks,
Uday
  • 1. Re: How to monitor method calls to/by an object?
    843810 Newbie
    Currently Being Moderated
    You can monitor the method entry and exit using jvmti.

    http://java.sun.com/javase/6/docs/platform/jvmti/jvmti.html#MethodEntry

    This will degrade the performance. Other option would be to use btrace which is based on byte code instrumentation.

    https://btrace.dev.java.net/
  • 2. Re: How to monitor method calls to/by an object?
    843810 Newbie
    Currently Being Moderated
    Thanks for your reply. I am already looking into JVMTI. I will try the other one too. But I want to make my question clear. I don't need to monitor the entry and exit to a method. I want to know which methods of an object [say objA] are being called and the methods called by this object[objA]. I just need to log these method calls.

    Thanks,
    Uday.
  • 3. Re: How to monitor method calls to/by an object?
    843810 Newbie
    Currently Being Moderated
    Hi,

    None of them are easy alternatives. Sure, JVMTI will solve your purpose, but if speed is not an issue, I would suggest an "all java" alternative using spring interceptors. They will use byte code instrumentation at runtime (invisible to you) but what you want to do will literally be a piece of cake with spring interceptors. Ofcourse, your objects will all have to be spring beans.

    Look into some spring / AOP tutorials on how to do this. A simple google search and you will have what you need.

    Regards,
    Parth Mehta.