Skip to content
Snippets Groups Projects
Commit 25900ca2 authored by Andrea Gussoni's avatar Andrea Gussoni
Browse files

Add scripts to compute the cyclomatic increase

parent 774f0ec8
No related branches found
No related tags found
No related merge requests found
......@@ -9,3 +9,4 @@ function_idx_dir=$workdir/deduplicated-functions-idx-no-goto
revng_json_dir=$workdir/revng-json
ida_json_dir=$workdir/ida-json-normalized
revng_metrics_dir=$workdir/revng-metrics
cyclomatic_metrics_dir=$workdir/cyclomatic-metrics
#!/usr/bin/env python3
import argparse
import csv
import json
import numpy
import os
import pandas
import sys
from scipy.stats.mstats import gmean
def main():
parser = argparse.ArgumentParser(description='My nice tool.')
parser.add_argument('binaries', metavar='BINARIESFILE', help='File containing the names of the binaries')
parser.add_argument('arch', metavar='ARCH', help='Architecture')
parser.add_argument('cyclomatic_metrics_dir', metavar='CYCLOMATICMETRICSDIR', help='Architecture')
args = parser.parse_args()
arch = args.arch
binaries_file = args.binaries
cyclomatic_metrics_dir = args.cyclomatic_metrics_dir
source_cyclomatic_total = 0
revng_cyclomatic_total = 0
ida_cyclomatic_total = 0
ghidra_cyclomatic_total = 0
with open(binaries_file, 'r') as binaries:
binaries_list = [line.rstrip('\n') for line in binaries]
for binary_name in binaries_list:
# Open the files containing the metrics.
metrics_csv_file = cyclomatic_metrics_dir + '/' + binary_name + '.csv'
if os.path.isfile(metrics_csv_file):
with open(metrics_csv_file, 'r') as metrics_csv:
df = pandas.read_csv(metrics_csv_file)
for index, row in df.iterrows():
# Load the metrics.
source_current_cyclomatic = int(row['source_cyclomatic'])
revng_current_cyclomatic = int(row['revng_cyclomatic'])
ida_current_cyclomatic = int(row['ida_cyclomatic'])
ghidra_current_cyclomatic = int(row['ghidra_cyclomatic'])
# For some functions, we couldn't get the original cyclomatic
# complexity for the source.
if source_current_cyclomatic != -1:
# Unfortunately, due to the `-2` term in the cyclomatic complexity
# computation, some terms goes to 0. A 0 at the denominator is not
# good, round it to 1.
if source_current_cyclomatic == 0:
source_current_cyclomatic = 1
if revng_current_cyclomatic == 0:
revng_current_cyclomatic = 1
if ida_current_cyclomatic == 0:
ida_current_cyclomatic = 1
if ghidra_current_cyclomatic == 0:
ghidra_current_cyclomatic = 1
# Total.
source_cyclomatic_total += source_current_cyclomatic
revng_cyclomatic_total += revng_current_cyclomatic
ida_cyclomatic_total += ida_current_cyclomatic
ghidra_cyclomatic_total += ghidra_current_cyclomatic
# Print some final information about the cyclomatic complexity.
print("Total source cyclomatic")
print(source_cyclomatic_total)
print("Total revng cyclomatic")
print(revng_cyclomatic_total)
print("Total ida cyclomatic")
print(ida_cyclomatic_total)
print("Total ghidra cyclomatic")
print(ghidra_cyclomatic_total)
print("revng/source")
print(revng_cyclomatic_total/source_cyclomatic_total)
print("ida/source")
print(ida_cyclomatic_total/source_cyclomatic_total)
print("ghidra/source")
print(ghidra_cyclomatic_total/source_cyclomatic_total)
if __name__ == "__main__":
main()
#!/bin/bash
if [ $# -eq 0 ]; then
echo "No arguments supplied"
exit 1
fi
arch=$1
# Import the config
. ./config.sh
$computation_script_dir/compute-cyclomatic-total.py $binaries_file $arch $cyclomatic_metrics_dir
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment