Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
artifacts-asiaccs20
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Andrea Gussoni
artifacts-asiaccs20
Commits
25900ca2
Commit
25900ca2
authored
4 years ago
by
Andrea Gussoni
Browse files
Options
Downloads
Patches
Plain Diff
Add scripts to compute the cyclomatic increase
parent
774f0ec8
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
config.sh
+1
-0
1 addition, 0 deletions
config.sh
scripting/computation/compute-cyclomatic-total.py
+88
-0
88 additions, 0 deletions
scripting/computation/compute-cyclomatic-total.py
scripting/computation/compute-cyclomatic-total.sh
+13
-0
13 additions, 0 deletions
scripting/computation/compute-cyclomatic-total.sh
with
102 additions
and
0 deletions
config.sh
+
1
−
0
View file @
25900ca2
...
...
@@ -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
This diff is collapsed.
Click to expand it.
scripting/computation/compute-cyclomatic-total.py
0 → 100755
+
88
−
0
View file @
25900ca2
#!/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
()
This diff is collapsed.
Click to expand it.
scripting/computation/compute-cyclomatic-total.sh
0 → 100755
+
13
−
0
View file @
25900ca2
#!/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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment