Compute common software complexity metrics. Right now, the Halstead metric (see here and here) and McCabe's cyclomatic complexity metric are available.
Option | Arguments | Description |
---|---|---|
--Transform | SoftwareMetrics | Compute software complexity metrics for a function. |
--SoftwareMetricKind | raw, halstead, mccabe | What metric to compute. Default=halstead,mccabe.
|
--SoftwareMetricFileName | string | On which file to print the metrics. If not set, print to standard output. From version 3.3. Default=Stdout. |
--SoftwareMetricJsonFileName | string | On which file to print the metrics in Json format. From version 3.3. Default=Stdout. |
Here is an example where we print out the McCabe metric for three functions: the original fib
,
fib
after flattning, and
fib
after virtualization. Here is the tigress
command:
tigress \
--Transform=SoftwareMetrics \
--Functions=fib \
--SoftwareMetricsFileName=original.txt \
--SoftwareMetricsKind=mccabe \
--Transform=Copy \
--Functions=fib \
--CopyName=fib2 \
--Transform=Flatten \
--Functions=fib \
--Transform=SoftwareMetrics \
--Functions=fib \
--SoftwareMetricsFileName=flatten.txt \
--SoftwareMetricsKind=mccabe \
--Transform=Virtualize \
--Functions=fib2 \
--Transform=SoftwareMetrics \
--Functions=fib2 \
--SoftwareMetricsFileName=virtualize.txt \
--SoftwareMetricsKind=mccabe \
test1.c --out=obf.c
> cat original.txt
McCabe.fib.E = 10
McCabe.fib.N = 10
McCabe.fib.P = 1
McCabe.fib.value = 2
> cat flatten.txt
McCabe.fib.E = 28
McCabe.fib.N = 22
McCabe.fib.P = 1
McCabe.fib.value = 8
> cat virtualize.txt
McCabe.fib2.E = 85
McCabe.fib2.N = 68
McCabe.fib2.P = 1
McCabe.fib2.value = 19
These metrics can be used to see how much change each transformation incurs.
You can also generate the output into a Json file which is useful if you want to process them with some other program:
tigress \
--Transform=SoftwareMetrics \
--Functions=wikipedia,sort,main \
--SoftwareMetricsJsonFileName=metrics.json \
--SoftwareMetricsKind=raw,halstead,mccabe \
test1.c --out=obf.c
> cat metrics.json
...
{
"metric": "McCabe",
"name": "sort",
"E": 24,
"N": 21,
"P": 1,
"value": 5
}
...
Don't expect the values computed by this transform to be identical to that produced by other tools. It only makes sense to compare the metrics computed by Tigress with other metrics computed by Tigress: