Hello all the gurus out there,

I'm working on a project that requires me to log method calls that occur in a running Java program, I did some research for the past two weeks and learnt that instrumentation might be the way to go but it's largely complicated for my level and I presume that my project wouldn't need this sledgehammer to crack a nut?

Instrumentation seems to log a lot of information but in this case I only need to know which method is called during the execution, maybe but not necessarily the time they are called. Somehow I'm feeling that there's a simple way in the instrumentation package that allows me to do that but after weeks of research, I just didn't nail it...

Anyone kind enough to shed some light or at least guide me to the right path?

Recommended Answers

All 4 Replies

... but if you can get that to work please please tell me how!

Member Avatar

I don't know if Java has any kind of functionality that you're looking for,
however, what I would do is...

Create a method which opens a log file and appends a string and time to the end of the file.
In EACH of your methods that you call, call the logging method.
You might also try calling when the method starts, AND when the method ends.
This would give you an execution time for each method.
This will also tell you which method that MAY require a little... "tweaking".

Thanks for the help and effort guys.

I looked into everything mentioned above and I learned that it's not difficult writing a method for that but how to make random Java program invoke the method I wrote to log?

As in how to perform modifications/transformation/instrumentation to methods of a random Java program so that it includes invocation of my method that performs logging?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.