top-complexity: also output average complexity

Closes #17920
This commit is contained in:
Daniel Stenberg 2025-07-13 23:41:59 +02:00
parent b6c636256d
commit f5a44e1549
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2

View file

@ -87,12 +87,14 @@ my $show = 65;
my $error = 0;
my %where;
my %perm;
my $allscore = 0;
my $alllines = 0;
# each line starts with the complexity score
# 142 417 809 1677 1305 src/tool_getparam.c(1677): getparameter
for my $l (@output) {
chomp $l;
if($l =~/^(\d+)\t\d+\t\d+\t\d+\t\d+\t([^\(]+).*: ([^ ]*)/) {
my ($score, $path, $func)=($1, $2, $3);
if($l =~/^(\d+)\t\d+\t\d+\t\d+\t(\d+)\t([^\(]+).*: ([^ ]*)/) {
my ($score, $len, $path, $func)=($1, $2, $3, $4);
if($score > $show) {
my $allow = 0;
@ -106,6 +108,8 @@ for my $l (@output) {
$error++;
}
}
$alllines += $len;
$allscore += ($len * $score);
}
}
@ -121,4 +125,6 @@ for my $e (sort {$where{$b} <=> $where{$a}} keys %where) {
$perm{$e} ? " [ALLOWED]": "";
}
printf "\nAverage complexity: %.2f\n", $allscore / $alllines;
exit $error;