How to setup Projects with existing Ant script for Profiling

Home

How to setup Projects with existing Ant script (Freeform 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


In a Freeform project, you have to write your own Ant target to be able to profile the project.

You should write two targets in your freeform project's build script, one for profiling a project and one for profiling individual files. When you use the "Profile Main Project" or "Profile File" actions in the IDE, for the first time for a given freeform project as the main project, you will be asked to specify which Ant target from the existing ones should be used.

The targets would typically look similar to your existing "run" target, with some additional parameters, so you may want to start with copying your "run" target into "profile" and modify it per instructions below.

You will need to make two changes in your profile target when you copy it from run:

  1. Add call to nbprofiledirect task at the beginning.
  2. Add extra JVM argument to the task that starts the VM to run your application. You would typically do that by adding subelement to the java task such as this one:
    <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:

  <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. Freeform Web Projects


Typically the server is started using a startup script, not the java command directly. Therefore you can't pass additional argument to it using the <jvmarg .../> element as described in ad. 2 of the Basics chapter. Instead, you have to modify the server startup script to configure it for profiling.

The recommended approach is to create new script for starting the server for profiling and use it in profile target. Modified startup script can be automatically created by the Profiler Attach Wizard. If automatic integration isn't supported for your server, create the script manually by following manual integration steps of the wizard. For both cases, you have to setup the integration for Local Direct attach.

All other steps to profile Freeform Web Project are identical with the steps for standard J2SE projects.



4. Advanced


The use of some of the parameters is optional, but they enhance your ability to control the profiler setup from the UI:

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

Here is an example of a full profile target that allows to control the working directory, JVM and 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


Properties that are set if the profiling is invoked from the Profile Project or Profile File actions:

  • profile.class - If Profile File was used 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 profiler application

Project Features

About this Project

Profiler was started in November 2009, is owned by Tomas Hurka, and has 62 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