Profile The entire implementation of the Java program in VisualVM

In Java profiling, it seems that all the (free) roads currently lead to the VisualVM profiler included in JDK6. It looks like a great program, and everyone is touting how you can β€œattach it to a running process” as the main function. The problem is that this is the only way to use it in a local process. I want to be able to run my program in the profiler and track all its execution.

I tried using the -Xrunjdwp option described in how to profile launching an application using visualvm , but between the two transport methods (shared memory and server) none are useful to me. VisualVM does not seem to have integration with the former, and VisualVM refuses to connect to localhost or 127.0.0.1 , so the latter also does not work. I also tried to insert a simple read of System.in into my program to insert a pause in the execution, but in this case VisualVM is blocked until the reading is completed and it will not allow to start profiling until the execution is completed. I also tried looking into the Eclipse plugin , but the website is full of dead links and the launch only starts with a NullPointerException when I try to use it (this may be more inaccurate).

Coming from C, this does not seem to me a particularly difficult task. Am I just missing something or is it really an impossible request? I am open to any offers, including the use of another (also free) profiler, and I am not averse to the command line.

+31
java visualvm profile
Aug 17 '11 at 16:15
source share
4 answers

Consider using HPROF and opening a data file using the HPjmeter tool - or simply by reading the resulting text file in your favorite editor.

 Command used: javac -J-agentlib:hprof=heap=sites Hello.java SITES BEGIN (ordered by live bytes) Fri Oct 22 11:52:24 2004 percent live alloc'ed stack class rank self accum bytes objs bytes objs trace name 1 44.73% 44.73% 1161280 14516 1161280 14516 302032 java.util.zip.ZipEntry 2 8.95% 53.67% 232256 14516 232256 14516 302033 com.sun.tools.javac.util.List 3 5.06% 58.74% 131504 2 131504 2 301029 com.sun.tools.javac.util.Name[] 4 5.05% 63.79% 131088 1 131088 1 301030 byte[] 5 5.05% 68.84% 131072 1 131072 1 301710 byte[] 

HPROF is able to display CPU usage, heap allocation statistics, and track competition profiles. In addition, it can also report full heaps and states of all monitors and threads in the Java Virtual Machine.

+19
Aug 17 2018-11-21T00:
source share

The best way to solve this problem without changing your application is to not use VisualVM at all. As for the other free options, you can use Eclipse TPTP or Netbeans profiler or something else with your IDE.

If you can change your application to pause it when configuring the profiler in VisualVM, it is quite possible to do this using the VisualVM Eclipse plugin. I am not sure why you are getting a NullPointerException, as it works on my workstation. You need to configure the plugin by specifying the jvisualvm binary path and the JDK path; this is done by visiting the VisualVM configuration dialog in Windows β†’ Settings β†’ Run / Debug β†’ Start β†’ VisualVM Setup (as shown in the following screenshot).

Eclipse VisualVM plugin

You also need to configure the application to start using the VisualVM launcher instead of starting the default JDT.

All application launches from Eclipse now cause VisualVM to automatically track the new local JVM, provided that VisualVM is already running. If you do not have VisualVM running, the plugin will start VisualVM, but it will also continue to work with the application.

The conclusion from the previous sentence, it is obvious that using the application in the main() method before performing any processing is very useful. But this is not the main reason for the suspension of the application. Apparently, VisualVM or its Eclipse plug-in does not automatically run processor or memory profilers. This would mean that these profilers would need to be started manually, which would require the application to pause.

In addition, it is worth noting that adding the flags: -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=y to start the JVM will not help you, in the case of VisualVM, pause the application and configure the profilers. Flags are designed to help you with profilers who can actually connect to the open JVM port using the JDWP protocol. VisualVM does not use this protocol, so you will need to connect to the application using JDB or a remote debugger; but this will not solve the problem associated with the profiler configuration, since VisualVM (at least with updates for Java 6 26) does not allow you to configure profilers on a paused process, because it just does not display the Profiler tab.

+11
Aug 17 2018-11-11T00:
source share

The tip with -Xrunjdwp incorrect. It just allows the debugger, and with suspend=y it expects the debugger to connect. Since VisualVM is not a debugger, this will not help you. However, pasting System.in or Thread.sleep() pauses the launch and allows VisualVM to connect to your application. Be sure to read Profiling with VisualVM 1 and Profiling with VisualVM 2 to better understand the profiler settings. Please also note that instead of profiling, you can use the "Sampler" tab in VisualVM, which is more suitable for profiling the entire execution of a Java program. As mentioned above, you can also use Profiler NetBeans, which directly supports application launch profiling.

+3
Aug 18 2018-11-11T00:
source share

This is now possible with the VisualVM startup profile plugin .

+3
Feb 24 '14 at 2:37
source share



All Articles