I would like to profile a certain part of the execution of a small application. Is there a way to initiate data collection in VisualVM from an application that needs to be profiled? In other words, is it possible to add code to a profiled application so that profiling in VisualVM starts automatically after this code?
meaninglessCode(); // How to start data collection? com.sun.tools.visualvm.....startSampling(); // codeToBeProfiled(); // How to stop data collection? com.sun.tools.visualvm.....stopSampling(); // furtherMeaninglessCode();
My current workaround is to call Thread.sleep , which gives me time to press a button in the VisualVM GUI, but this is far from satisfactory. Several Google searches did not show any success. I appreciate any hint.
source share