How can I profile NetBeans?
There are many possibilities how to profile Java applications and that can be applied to NetBeans profiling. For different task it can be good to select different ways because each of them has its strengths and weaknesses.
See also: DevFaqMemoryLeaks
To be able to profile an application it is usually needed to start it with a modified command that typically adds some (JVMPI or JVMTI) libraries, some classes to (boot)classpath, specifies options for profiling and often initializes profiling support before the application starts to run its code.
NetBeans profiler
The NB module development support is integrated with the NB Profiler. Just select a module and click Profile to start.
Want to cover some typical activities like:
-
action execution (invoked from menu or by shortcut)
-
window/dialog opening/closing
-
use of editor including tracking what happens in background
-
startup
Analyzer
It is a sampling profiler working on Solaris and Linux (with limited functionality) that collects data during runtime. These data are later available for offline processing.
It provides some capabilities that are not available in other Java profilers namely timeline view. This view shows timeline for each thread visualizing if the thread actually executes some code or not.
Download and install Analyzer tool
Performance Analyzer that is part of Sun Studio tools and can be downloaded from the developers' site.
Run the Analyzer
-
Set the environment.
PATH
should containbin
directory of Analyzer installation.LD_LIBRARY_PATH
should similarly containlib
dir (and also/usr/lib/lwp
if you want to run it on Solaris 2.8). Optionally you can also setMAN_PATH
. Set the_NB_PROFILE_CMD
:
export _NB_PROFILE_CMD='collect -p 1 -j on -S off -g NetBeans.erg -y 38 -d /export/home/radim/analyzer
-p num stands for sampling period (on, hi, lo are also accepted), -j on turns on Java profiling, -y num determines the signal to trigger profiling on/off. -y num,r means that profiling will be resumed at the begining. Use man collect
to get detailed explanation of all options.
-
mkdir /export/home/radim/analyzer
(It is only need first time. Next experiments will be added.) -
Install & start the IDE
-
Send signal 38 to Java process to start data collecting (
kill -38 $pid
). Or use another signal like PROF (this works well on Linux). -
Perform the analyzed activity
-
Send the signal again to stop profiling (there can be more evaluated periods during one run).
-
Shut down the IDE.
-
Run the analyzer to evaluate the experiment in GUI environment:
analyzer /export/home/radim/analyzer/NetBeans.x.er
Other tools
Quite simple way how to measure time spent in some code is to wrap the code with
long t0 = System.nanoTime();
try {
... measured code
} finally {
long t1 = System.nanoTime();
System.out.println("action took "+(t1-t0)/1000000+"ms");
}
JVMTI is powerful interface that allows to write custom libraries that will track behavior of application.
DTrace is a comprehensive dynamic tracing framework for the Solaris™ Operating Environment.
It is one of the few tools that allows to track activities running deeply in the system and analyze the system.
Because there are also probes provided by Java VM and function like jstack
it is also possible to map
observed actions to parts of Java code in running application.
Tips and trick
Node pop-ups: interesting starting point is o.o.awt.MouseUtils$PopupMouseAdapter.mousePressed()
How to measure performance/responsiveness?
See What is UI responsiveness for overview.
Older Performance web page contains few links to documentation of one possible approach how to measure and profile responsiveness. This is based on use of modified event queue and patches classes from JDK.
Recently we changed the support a bit to avoid modifications of core JDK’s classes and and use small utility library available in Hg. This is used in current automated testing and can be used for manual checks too. To run such test:
-
Build
performance
project. -
Copy the JAR file to
netbeans/platform/core
-
Start the IDE with
-J-Dnetbeans.mainclass=org.netbeans.performance.test.guitracker.Main -J-Dguitracker.mainclass=org.netbeans.core.startup.Main
-
… watch process output when you perform an action
Applies to: NetBeans 6.5 and above