Posted by & filed under Tips.

Several people have asked me lately about automating metrics with Understand 2.0. There are two quick ways to automate metrics, as a scheduled activity and via the command line:

Scheduled Activity

The quickest way to automatically get metrics is as a scheduled activity. For example I could setup Understand so that every Friday night it reparses my project and generates the current metrics. I can set it up to save the metrics as a comma delimited file and/or as an html report. This is all configured from Tools | Scheduled Activities.


Command Line

Another way to automate the metrics is using the command line tool und. For a list of the commands available from und, simply run und –help. For more advanced help on a specific command, run und –help command. For example run –help rescan will show the advanced help for the rescan command.

It most cases the first thing you’ll want to do is update your project by rescanning and analyzing. This can be done with:

und –db c:projectpixie.udb –rescan – analyzeAll

Und lets you dynamically specify the parameters for the metrics exports. Simply look at the commands that start –metrics_* for additional options.

For example metrics lets you specify which metrics you want to report on, so if you just wanted the cyclomatic complexity and the lines of code, first you would need to clear the current metrics and then you would set the option as:

und –db c:projectpixie.udb –metrics none AvgCyclomatic CountLineCode

Then to actually generate the metrics file, use the –metrics command, you can specify the filename for the csv export, or if none is specified it will default to the last used filed location. You can see the available metrics at /documents/metrics.php

und –db c:projectpixie.udb –metrics “c:tempPixie Metricsmetrics.csv”

You can set the parameters and generate the metrics with the same command, so:

und –db c:projectpixie.udb –metrics none AvgCyclomatic CountLineCode –metrics “c:tempPixie Metricsmetrics 10-13-2008.csv”

You now have a comma delimited text file that you can open in your favorite spreadsheet editor, or parse however you want:



If you would rather see your metrics as an html report, use the –metrics_htmlReport command instead of the –metrics command:

und –db c:projectpixie.udb –metrics_htmlReport current –dir “c:tempPixie Metricshtml metrics 10-13-2008”

The html reports let you browse by architecture, so you can look at the metrics by filesystem, staff, or whatever architectures you have setup:

image image