Reputation: 478
I have an abc.jar file and it has some Java classes in it. I don't have the source code of it. I want to get logs of the classes/methods that's been hit while debugging.How can I do that?
P.S - I could have used log4j for it but I don't have the source code.
Upvotes: 10
Views: 19360
Reputation: 3586
You need to use a profiling tools such as Java's hprof. It is a good introduction to profiling. While not powerful, it is a good start. There are plenty of other useful profiling tools. Just google them.
For hprof, the modes of CPU Usage Sampling Profiles (cpu=samples)
e.g. javac -J-agentlib:hprof=cpu=samples Hello.java
and CPU Usage Times Profile (cpu=times)
e.g. javac -J-agentlib:hprof=cpu=times Hello.java
sound like what you needs. They can tell you what is called and how often. What they won't tell you is the state of variables. This is what debugging is used for given that logging is not an option.
Upvotes: 5
Reputation: 51
Let's say if you have abc.jar and it doesn't use any framework for logging, and you don't have any source code as you have mentioned. No, you can't get logs this way.
Upvotes: 5
Reputation: 35477
You state in your comment that you know that abc.jar
doesn't use any logging framework.
In that case, it is impossible to get logs from it.
However, what you can do is use a debugger. All IDEs have debuggers. This can help you know the state of the classes being called when you use them.
Upvotes: 4