在自由格式的项目中,您必须编写自己的 Ant 目标才能分析项目。通常,需要在自由格式项目的生成脚本中编写两个目标,一个目标用于分析项目,另一个目标用于分析各个文件。在 IDE 中第一次对给定的自由格式项目(指定为主项目)执行“分析主项目”或“分析文件”操作时,系统将要求您指定要使用的 Ant 目标。
通常,这些目标类似于现有 "run" 目标,并且包含一些额外的参数,因此,您可能需要先将 "run" 目标复制到 "profile",然后按照下面的说明对其进行修改。
从 "run" 中复制后,您需要在 profile 目标中进行两处更改。
<jvmarg value="${profiler.info.jvmargs.agent}"/>
下面是在 J2SE 项目中使用的基本 "profile" 和 "profile-single" 目标(JDK 5.0 或更高版本)的示例。
<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>
要启动 Profiler 并在资源管理器中选择一个类,您可以添加相同的目标并使用 classname="${profile.class}"。例如:
<target name="profile-single" 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>
通常,服务器是使用启动脚本启动的,而不是使用 java 命令直接启动的。因此,不能使用 <jvmarg .../>
元素为其传递额外的参数。要进行性能分析,您必须修改服务器的启动脚本以对其进行配置。
建议的方法是,创建新的脚本以启动服务器来进行性能分析,并在 profile
目标中使用它。连接向导可以生成所需的修改的启动脚本。如果目标服务器不支持自动集成,则可以按照向导中描述的手动集成步骤手动创建脚本。您必须始终为“本地直接”连接设置集成。
自由格式 Web 项目性能分析的其他步骤与标准 J2SE 项目性能分析的上述步骤相同。
有关如何分析自由格式项目和可以使用的参数的详细信息,请参见下面的 NetBeans 常见问题解答: