Setting Up Projects with an Existing Ant Script for Profiling

Setting Up Projects with an Existing Ant Script (Free-form Projects) for Profiling

Contents:

  1. Basics
  2. Example of basic "profile" and "profile-single" targets (JDK 5.0 or later)
  3. Freeform Web Projects
  4. Advanced
  5. Reference

1. Basics

If you have a free-form project, you have to write your own Ant target to be able to profile the project. In the build script of your free-form project you should write the following two targets:

  • a target for profiling the project
  • a target for profiling individual files

If your free-form project is set as the main project, the first time you invoke "Profile Main Project" or "Profile File" you are asked to specify which of the existing Ant targets to use.

The targets would typically look similar to your existing "run" target, with some additional parameters. One way to create your Ant targets is to copy your "run" target, then rename the copy "profile" and modify it according to the following instructions.

If you copy the run target to make your new profile target, you need to make two changes to the profile target:

  1. Add a call to nbprofiledirect task at the beginning.
  2. Add an extra JVM argument to the task that starts the VM to run your application. You typically do this by adding a sub-element similar to the following to the java task:
    <jvmarg value="${profiler.info.jvmargs.agent}"/>

2. Example of basic "profile" and "profile-single" targets (JDK 5.0 or later)

                    <target name="profile" depends="jar" description="Profile Project">
                    <fail unless="netbeans.home">This target can only run inside the NetBeans IDE.</fail>
                    
                    <nbprofiledirect>
                    <classpath> <pathelement location="... specify ..."/> </classpath>
                    </nbprofiledirect>
                    
                    <java ... use same attributes as with run ...>
                    <jvmarg value="${profiler.info.jvmargs.agent}"/>
                    </java>
                    </target>
                

To start the profiler with a class selected in the explorer, you can add the same target, and use classname="${profile.class}", such as the following:

                    <target name="profile" depends="jar" description="Profile File">
                    <fail unless="netbeans.home">This target can only run inside the NetBeans IDE.</fail>
                    
                    <nbprofiledirect>
                    <classpath> <pathelement location="... specify ..."/> </classpath>
                    </nbprofiledirect>
                    
                    <java classname="${profile.class}" ... use same attributes as with run ...>
                    <jvmarg value="${profiler.info.jvmargs.agent}"/>
                    </java>
                    </target>
                

3. Free-form Enterprise Application Projects

When you have a free-form enterprise application project, the server is typically started using a startup script, not the java command directly. Therefore you cannot pass additional arguments to it using the <jvmarg .../> element as described above. Instead, you have to modify the server startup script to configure it for profiling.

The recommended approach is to create a new script for starting the server for profiling and use the new script in the profile target. The Profiler Attach Wizard can create the modified startup script for you. If your server does not support automatic integration, you can create the script manually by following the manual integration steps provided in the wizard. In both cases, you have to setup the integration for Local Direct attach.

The remaining steps for profiling a free-form enterprise application project are identical to the steps for standard J2SE projects.

4. Advanced

The use of some of the following parameters is optional, but they can enhance your ability to control the Profiler setup from the IDE:

  • Add jvm="${profiler.info.jvm}" attribute to start profiling with the JDK selected in the IDE Options window (Tools > Options > Profiler).
  • Add dir="${profiler.info.dir}" attribute to be able to start the profiled application with the working directory specified in the NetBeans Profiler dialog box.
  • Add <jvmarg line="${profiler.session.jvm.args}"/> if you want to specify custom JVM arguments and a working directory in a NetBeans Profiler configuration. This can be particularly useful if you are tuning the VM with extra arguments and want to observe the differences in the NetBeans Profiler.

Here is an example of a full profile target that allows you to control the working directory, the JVM and the JVM arguments from the Profiler UI:

                    <target name="profile" depends="jar" description="Profile Project">
                    <fail unless="netbeans.home">This target can only run inside the NetBeans IDE.</fail>
                    
                    <nbprofiledirect>
                    <classpath> <pathelement location=" ... specify ... "/> </classpath>
                    </nbprofiledirect>
                    
                    <java fork="true" classname="... specify ..." dir="${profiler.session.working.dir}" jvm="${profiler.info.jvm}">
                    <jvmarg value="${profiler.info.jvmargs.agent}"/>
                    <jvmarg line="${profiler.info.jvmargs}"/>
                    <classpath> <pathelement location="... specify ..."/> </classpath>
                    </java>
                    </target>
                

5. Reference

The following properties that are set if you invoke profiling from the Profile Project or Profile File menu items:

  • profile.class - If Profile File was invoked, contains name of the class to profile (Java style)
  • profiler.info.single.file - If Profile File was used contains file name of the class to profile
  • profiler.info.jvm - Path to Java executable of JVM selected for profiling
  • profiler.info.jvmargs - JVM arguments selected in IDE - selected in Project customizer or overriden in Custom profiling configuration
  • profiler.info.jvmargs.agent - JVM argument to be used for starting the Profiler agent in the VM
  • profiler.info.agentpath - Path to the Profiler agent
  • profiler.info.project.dir - Project directory of project that is being profiled
  • profiler.info.dir - Working directory of the NetBeans Profiler application

 

 

Project Features

About this Project

Profiler was started in November 2009, is owned by Tomas Hurka, and has 58 members.
By use of this website, you agree to the NetBeans Policies and Terms of Use (revision 20160708.bf2ac18). © 2014, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo
 
 
Close
loading
Please Confirm
Close