FeaturesPluginsDocs & SupportCommunityPartners

Using the Metrics Module

Creating a metrics report

The metrics module has two modes of operation: metrics reports and threshold monitoring. To create a metrics report, select some classes (or directories which have classes in them) in the NetBeans Explorer, then select the "Tools->Metrics..." menu item to get something like the following:

metrics report

To sort the report different ways, click on any of the column headers.

Threshold monitoring

In the Options panel ("Tools->Options...") the metrics module has warning and error threshold values for each of its metrics. These thresholds are used to provide visual feedback when browsing with the Explorer.

Whenever a compiled Java class or method is displayed in the Explorer, the metrics module has already gathered its metrics. If the class or method has crossed one or more metric error thresholds (as set in the Options panel), then a red light icon is added to that class or method's icon. If it has crossed one or more metric warning thresholds but no warning thresholds, then a yellow light is added to that class or method:

explorer view

Approving metric values

Not all classes or methods with high metric values will benefit from refactoring. For example, a method with 100 code paths may seem extreme, but not if it is a lexical analyzer for a language with 100 tokens. In that case, the method is designed well but the metric error icon is not appropriate. To fix this, the existing metric value(s) can be "approved" and the icon will disappear.

To approve one or more metrics, select the class(es) and/or method(s) to be approved and select the "Tools->Approve Metric..." menu item. A dialog will come up with a list of the metrics which exceed their warning or error thresholds:

approval dialog

Select which metrics you want to approve, enter a comment and click Okay. The approval information will be stored in a per-directory file called MetricApprovals.xml. This file can be checked into the project's source control system and then shared with other team members. This procedure avoids duplicate code reviews.


Companion
Projects:
MySQL Database Server   Open JDK: an Open SourceJDK   GlassFish Community: an Open Source Application Server    Mobile & Embedded Community    Open Solaris   java.net - The Source for Java Technology Collaboration   Virtual Box - full virtualizer  Open ESB - The Open Enterprise Service Bus Powered by