Share via


Working with Code Metrics Data

The Code Metrics Results window displays the data that is generated by the code metrics analysis. For more information about code metrics data values, see Code Metrics Values.

This topic contains the following sections:

Code Metrics Results Window

The Code Metrics Results window has a toolbar at the top and columns to display the calculated results.

Column

Description

Hierarchy

The Hierarchy column contains a tree view of the code hierarchy that you can expand or collapse to see the level of detail that you want. The remaining columns show the calculated results. You can hide or arrange the result columns as you want.

Maintainability

The Maintainability column contains an icon in addition to the numeric result. A green icon indicates a relatively high degree of maintainability. A yellow icon indicates a moderate degree of maintainability. A red icon indicates low maintainability and a potential trouble spot. These color indicators correspond to severity categories that are used by the FxCop rule AvoidUnmaintainableCode. This rule fires an error if the maintainability index is lower than 10, a warning if the index is between 10 and 20, and neither an error nor a warning if the index is higher than 20. The maintainability index is a synthesis of three metrics: cyclomatic complexity, lines of code, and computational complexity. Its values are not expressed in units.

Displaying Code Metrics Results

The Code Metrics Results window is displayed automatically when you generate code metrics results. You can also display the window at any time.

To display the Code Metrics Results window

  • On the Analyze menu, click Windows and then click Code Metrics Results.

    - or -

  • On the View menu, point to Other Windows and then click Code Metrics Results.

    The Code Metrics Results window is displayed even when it contains no results.

To view code metrics details

  • If code metrics results have been generated, expand the tree in the Hierarchy column.

Filtering Code Metrics Results

You can filter the results that are displayed in the Code Metrics Results window by using the toolbar at the top. For example, you might want to see only the results that have a maintainability index below 65.

The Filter drop-down box contains the names of the results columns. When a filter is defined, it is added to the bottom of the list together with an indentation. The list can contain the last ten filters that were defined.

To filter the code metrics results

  1. From the Filter list, select the column name.

  2. In Min, type the minimum value to be displayed.

  3. In Max, type the maximum value to be displayed.

  4. Click the Apply Filter button.

  5. To see the result details, expand the hierarchy tree.

Adding, Removing, and Rearranging Data Columns

You can add or remove results columns from the Code Metrics Results window . In addition, you can rearrange results columns so that they appear in the order that you want.

To remove a column

  1. Click the Add/Remove Columns button.

    - or -

    Right-click any column heading and then click Add/Remove Columns.

  2. In the Add/Remove Columns dialog box, clear the check box for the column that you want to remove and then click OK.

To add a previously removed column

  1. Click the Add/Remove Columns button.

    - or -

    Right-click any column heading and then click Add/Remove Columns.

  2. In the Add/Remove Columns dialog box, select the check box for the column that you want to add and then click OK.

To rearrange columns

  1. Click the Add/Remove Columns button.

    - or -

    Right-click any column heading and then click Add/Remove Columns.

  2. In the Add/Remove Columns dialog box, select the column that you want to move and then click either the up arrow or the down arrow.

  3. When the column is positioned where you want it, click OK.

Copying Data to the Clipboard or Excel

You can select and copy a selected row of code metrics data to the clipboard as a text string that contains one line for the name and value of each data column. You can also click Open List in Microsoft Excel to export all of the code metrics results to an Excel spreadsheet

Creating a Work Item Based on Code Metric Results

You can create a Team Foundation work item that is based on results in the Code Metric Results window. When the work item is created, Visual Studio automatically enters a title in the Title field and code metrics data under the History tab.

For more information about how to create work items, see Create a Work Item.

To create a work item based on a result

  1. Right-click the result.

  2. Point to Create Work Item, and then click the type of work item you want to create (Bug, Task, and so forth).

  3. Complete the work item form by filling in all required fields.

  4. On the File menu, click Save All to save the work item.

To create a bug based on a result

  1. Click the result to select it.

  2. Click the Create Work Item button.

  3. Complete the work item form by filling in all required fields.

  4. On the File menu, click Save All to save the work item.

See Also

Tasks

How to: Generate Code Metrics Data

Other Resources

Measuring Complexity and Maintainability of Managed Code