站内搜索: 请输入搜索关键词

当前页面: 开发资料首页Netbeans 专题Profiling NetBeans Plug-In Modules

Profiling NetBeans Plug-In Modules

摘要: This document applies to NetBeans 5.0 and NetBeans Profiler 5.0.

In this tutorial you are guided through the process of setting up a NetBeans plug-in module project in the IDE so that you can use Profiler to analyze the plug-in performance. This tutorial touches on some aspects of profiling that are specific to profiling the performance and memory of NetBeans plug-in modules. It is assumed that you understand what profiling is and the purpose it serves, and also that you are familiar with NetBeans IDE and its support for plug-in development.

This tutorial covers the following topics.

If you are looking for a general tutorial on profiling with NetBeans Profiler, click here. To learn about plug-in development, see the NetBeans IDE 5.0 Plug-in Module Quick Start Guide.

Setting Up the Project

To profile your NetBeans plug-in module, you first have to make sure you have all of the necessary software and that your project is set up correctly.

Installing the Software

Before you can start profiling a NetBeans module, you need to do the following.

Setting Up the Plug-in Module Project

Basic setup.
If the version of the IDE you are using to develop your plug-in module is the same as the version you are developing your plug-in module for, set the module as Main Project. You can set the module as Main Project by opening your module project and then right-clicking the module node in the Projects window and choosing Set Main Project.

Advanced setup.
If you are developing your plug-in module for a version of the IDE that is incompatible with the version you are using to develop the plug-in (for example, you work in a stable release of the IDE and develop and deploy plug-ins to the lastest trunk build), follow the following steps:

  1. Create a second installation of NetBeans <dev_IDE>. If you are developing your plug-in for a different version of the IDE, you probably already have a second installation of NetBeans. If you do not, you can create one by installing a copy of NetBeans in a different location, specifying a different user directory. When creating the second installation, be sure that a different user directory is specified. You can do this by using the -userdir command line switch when launching the IDE, or by modifying the user directory specified in the NetBeans conf file.
  2. Choose Tools > NetBeans Platform Manager from the Main menu and add <dev_IDE> to the available platforms.
  3. Open your Module project and set it as Main Project.
  4. Right-click the module project in the Projects window and select Properties from the pop-up menu to open the Project Properties dialog box.
  5. Select the Libraries category and choose <dev_IDE> from the NetBeans Platform drop-down menu. If <dev_IDE> is not available, use the NetBeans Platform Manager to add it to the available platforms.
    Note. If you are profiling a module included in NetBeans (such as the Editor module), you cannot configure the platform. The target IDE should be set to nbbuild/netbeans.

If you do not have a NetBeans module project but would like to try profiling a NetBeans module, you can use the New Project wizard to create a sample plug-in module project. The Module Development Environment 5.0 Update 1, available from the NetBeans Update Center Beta, contains the Paint Application sample plug-in module.

Profiling the Plug-in Module

Once you have configured your plug-in project, you can use Profiler to launch the platform and plug-in.

Tips for Profiling NetBeans Plug-in Modules

Profiling a NetBeans plug-in is a special case because you are running and profiling a large application. In order to minimize the profiling overhead, you will usually want to limit the scope of the code that is profiled.

Profiling Performance

When you choose the Analyze Performance task, there are various options that enable you to modify the instrumentation of the plug-ins module on the platform. The following is a rough guide on which mode to choose when profiling performance.

  • Entire Application - Choose this mode if you want to get an overview of the performance of your code. When you choose this mode, your entire module is profiled (instrumented). Profiler starts measuring your code when program execution enters your module and stops when the process leaves your code. The code in all runnable objects that your project creates is also measured. If you just want to try Profiler, this is a good starting point.
  • Profile Entire IDE - Choose this option if you want to look for performance problems in the platform. You can select this as an option when you are profiling the Entire Application. When this option is selected, instrumentation is not limited to the code for your module and basically all executed code is measured. Using this mode involves the biggest overhead.
  • Part of Application - Use this mode if you want to tune the performance of specific parts of your code. This mode involves the lowest overhead because only the specified parts of your module are profiled (instrumented). Profiler starts measuring when program execution enters the selected method and stops when it leaves. Runnable objects that you create are NOT measured.
  • Class Filters - You can further limit the specific classes that are profiled by using filters to filter out specific classes, and in this way reducing the profiling overhead. For example, if you apply a filter to filter out java.* classes and your code calls a method in, for example, java.util.HashMap, this time will be included in the Self Time of your method as if spent directly in your method and not in java.util.HashMap. When looking at the results it will look like you never called any classes from java.*. Filters are especially useful when you know you are not interested in certain areas of code, such as Swing or NetBeans code.

    As an example, you can create a custom filter to filter out all NetBeans and Java core classes from the performance profiling results by doing the following:

    • Invoke Profile Main Project to open the Select Profiling Task dialog box.
    • Select the Analyze Performance task.
    • Choose Part of Application mode.
    • Click Customize Filter.
    • In the Customize Filter Sets dialog box, create a new filter set by clicking Add.
    • Supply a name for your filter, for example "Exclude Java and NetBeans".
    • Under Global Filters, select "Java Core Classes" and "NetBeans Classes" to include them in your filter set.
    • Click OK to close the dialog box and create the filter.

    The filter you created is now available in the Filter drop-down list when analyzing application performance.

Profiling Memory

When profiling memory usage of a plug-in module in NetBeans, you cannot limit the scope of memory profiling as you can when profiling performance (such as by profiling only root methods or only the code for your module). However, there are some ways you can minimize the profiling overhead and still get the results you need.

  • Record Stack Trace for Allocations - Do not enable this option if you do not need to record stack traces. Recording stack traces requires a lot of memory and makes profiling significantly slower. If unselected, you can track all allocations and garbage collection and still have acceptable performance overhead.
  • Track every N object allocations - If you only need an overview of memory usage and not precise results, you can experiment with this setting. This option is especially useful if you choose to track stack traces for allocations, as it significantly reduces memory and performance overhead. Be aware that all results are then actually divided by N (not precisely true for small numbers, as some heuristics are involved).

Increase the maximum java heap size. It is strongly recommended that you increase the maximum java heap size when you do memory profiling. You can do this by editing the conf/netbeans.conf file in your netbeans installation directory and changing the -J-Xmx parameter to -J-Xmx512m.

Further Reading, Links

For more information on using Profiler to profile NetBeans projects, please see the following links:


↑返回目录
前一篇: Packaging and Deploying Desktop Java Applications
后一篇: Recognizing a File Type Tutorial