]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
top-complexity: also output average complexity
authorDaniel Stenberg <daniel@haxx.se>
Sun, 13 Jul 2025 21:41:59 +0000 (23:41 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Mon, 14 Jul 2025 06:38:45 +0000 (08:38 +0200)
Closes #17920

scripts/top-complexity

index 59629d960335b85cf396bc8e92898704b4b4e5b5..a5e3bc13b881692741bc1fec042b4949074b7c8f 100755 (executable)
@@ -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;