Is there any Java profiler that allows profiling short-lived applications? The profilers I found so far seem to work with applications that keep running until user termination. However, I want to profile applications that work like command-line utilities, it runs and exits immediately. Tools like visualvm or NetBeans Profiler do not even recognize that the application was ran.
I am looking for something similar to Python’s cProfile, in that the profiler result is returned when the application exits.
You can profile your application using the JVM builtin HPROF.
It provides two methods:
Sampling
This method reveals how often methods were found on top of the stack.
Timing
This method counts the actual invocations of a method. The instrumenting code has been injected by the JVM beforehand.
Note: this method will slow down the execution time drastically.
For both methods, the default filename is
java.hprof.txtif thefile=option is not present.Full help can be obtained using
java -agentlib:hprof=helpor can be found on Oracles documentation