Reputation: 2195
I have a big java application, with source code, it already up and running on my dev server. I want to know which java-methods executed on server on some my actions. I can connect to it with debugger.
I don't work on this app, unfamiliar with it.
It is very big, I try to set breakpoints, and "miss" every time. Is there generic approach how to quickly find (or log) all methods that was executed in app?
Upvotes: 1
Views: 881
Reputation: 7079
You can try JFR, either start it from command line:
$ java -XX:StartFlightRecording:filename=recording.jfr
or from the shell, against an already running JVM:
$ jcmd <pid> JFR.start filename=recording.jfr
If you like, you can get a recording before the application exits by doing:
$ jcmd <pid> JFR.dump
You can then open the recording in JDK Mission Control, which can be downloaded here:
and look at the page where the most executed methods are shown.
Upvotes: 1
Reputation: 340230
Profiling tools expose what is happening within your app and JVM at runtime.
Your IDE likely offers some profiling features.
Also, you can use tools such as Flight Recorder and Mission Control.
See intro article How Java Profilers Work.
Upvotes: 0
Reputation: 22005
Profiling is a way to find out what methods are called inside of the JVM by a specific thread or multiple ones.
There are two types of profiling
Proactive
This requires you to connect to the JVM through JMX using an external tool, like JProfiler
Reactive
On the other hand, you have what I'll call reactive profilers, they'll be constantly connected to the JVM, but won't intercept all events sent by the JVM, just samples of it. This is the case for Java Flight Recorder which has been open-sourced since java-11
The JDK Flight Recorder was designed to minimize the Observer Effect in the profiled system, and is meant to be always on in production systems.
While profiling is fine, I find it a bit cumbersome for what you're trying to achieve, so I'd probably tend to choose the logging solution if I were you.
In spring (which makes use of aspectj), you can leverage AOP for this purpose. It will wrap your methods and intercept its invocations, and do something with it.
See the following example taken from this answer
@Aspect
public class MyLogger {
private Logger log = Logger.getLogger(getClass());
@After("execution(* com.example.web.HomeController.*(..))")
public void log(JoinPoint point) {
log.info(point.getSignature().getName() + " called...");
}
}
Upvotes: 1