master
1#!/usr/bin/env perl
2#***************************************************************************
3# _ _ ____ _
4# Project ___| | | | _ \| |
5# / __| | | | |_) | |
6# | (__| |_| | _ <| |___
7# \___|\___/|_| \_\_____|
8#
9# Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
10#
11# This software is licensed as described in the file COPYING, which
12# you should have received as part of this distribution. The terms
13# are also available at https://curl.se/docs/copyright.html.
14#
15# You may opt to use, copy, modify, merge, publish, distribute and/or sell
16# copies of the Software, and permit persons to whom the Software is
17# furnished to do so, under the terms of the COPYING file.
18#
19# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20# KIND, either express or implied.
21#
22# SPDX-License-Identifier: curl
23#
24###########################################################################
26use strict;
27use warnings;
29#######################################################################
30# Check for a command in the PATH of the test server.
31#
32sub checkcmd {
33 my ($cmd) = @_;
34 my @paths;
35 if($^O eq 'MSWin32' || $^O eq 'dos' || $^O eq 'os2') {
36 # PATH separator is different
37 @paths = (split(';', $ENV{'PATH'}));
38 }
39 else {
40 @paths = (split(':', $ENV{'PATH'}), "/usr/sbin", "/usr/local/sbin",
41 "/sbin", "/usr/bin", "/usr/local/bin");
42 }
43 for(@paths) {
44 if(-x "$_/$cmd" && ! -d "$_/$cmd") {
45 # executable bit but not a directory!
46 return "$_/$cmd";
47 }
48 }
49 return "";
50}
52my $pmccabe = checkcmd("pmccabe");
53if(!$pmccabe) {
54 print "Make sure 'pmccabe' exists in your PATH\n";
55 exit 1;
56}
57if(! -r "lib/url.c" || ! -r "lib/urldata.h") {
58 print "Invoke this script in the curl source tree root\n";
59 exit 1;
60}
62my @files;
63open(my $git, "-|", "git", "ls-files", "*.c") or die "git ls-files failed: $!";
64while(<$git>) {
65 chomp $_;
66 my $file = $_;
67 # we cannot filter these with git so do it here
68 if($file =~ /^(lib|src)/) {
69 push @files, $file;
70 }
71}
72close($git);
74open(my $pmc, "-|", $pmccabe, @files) or die "pmccabe failed: $!";
75my @output = <$pmc>;
76close($pmc);
78# these functions can be this long, but not longer
79my %whitelist = (
80 );
82# function length above this level is treated as an error and contributes to
83# the script's exit code
84my $cutoff = 500;
86# show this many from the top
87my $top = $ARGV[0] ? $ARGV[0] : 25;
89my $error = 0;
90my %where;
91my %perm;
92my $funcs = 0;
93my $alllines = 0;
94# each line starts with the complexity score
95# 142 417 809 1677 1305 src/tool_getparam.c(1677): getparameter
96for my $l (@output) {
97 chomp $l;
98 if($l =~ /^(\d+)\t\d+\t\d+\t\d+\t(\d+)\t([^\(]+).*: ([^ ]*)/) {
99 my ($score, $length, $path, $func) = ($1, $2, $3, $4);
101 my $allow = 0;
102 if($whitelist{$func} &&
103 ($length <= $whitelist{$func})) {
104 $allow = 1;
105 }
106 $where{"$path:$func"} = $length;
107 $perm{"$path:$func"} = $allow;
108 if(($length > $cutoff) && !$allow) {
109 $error++;
110 }
112 $alllines += $length;
113 $funcs++;
114 }
115}
117my $showncutoff;
118for my $e (sort {$where{$b} <=> $where{$a}} keys %where) {
119 if(!$showncutoff &&
120 ($where{$e} <= $cutoff)) {
121 print "\n---- threshold: $cutoff ----\n\n";
122 $showncutoff = 1;
123 }
124 printf "%-5d %s%s\n", $where{$e}, $e,
125 $perm{$e} ? " [ALLOWED]" : "";
126 if(!--$top) {
127 last;
128 }
129}
131printf "\nAverage function length: %.2f lines\n", $alllines/$funcs;
133exit $error;
Diagnostics4 git calls · 26 ms
CallStatusSizeTime026 ms
discover200152 B3 ms
git.upload-pack discover http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=3 git.response.bytes=152 git.server.agent=gitty/1.0 git.server.object_format=sha1 git.server.caps=agent ls-refs fetch object-format git.server.fetch=shallow filter sideband-all git.protocol.version=2 git.pkt.frames=8 git.pkt.data=6 git.pkt.flush=2 git.pkt.delim=0 git.pkt.bytes=152 git.pkt.payload.max=34
ls-refs200149 B · hit3 ms
git.upload-pack ls-refs http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=3 git.response.bytes=149 git.response.cache=HIT git.response.duration_ms=3 git.protocol.version=2 git.pkt.frames=3 git.pkt.data=2 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=149 git.pkt.payload.max=78 git.ls_refs.count=2 git.ls_refs.head=refs/heads/master
fetchblob:none · deepen 10200287 KiB · hit4 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=4 git.response.bytes=293470 git.response.cache=HIT git.response.duration_ms=4 git.fetch.filter=blob:none git.fetch.filter.requested=tree:0 git.fetch.filter.fallback=blob:none git.fetch.filter.learned=false git.fetch.wants=31c911efe5652725e930f4d2e60c9060e5f6646d git.fetch.haves.count=0 git.fetch.deepen=10 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=10 git.pkt.data=8 git.pkt.flush=1 git.pkt.delim=1 git.pkt.bytes=293470 git.pkt.payload.max=65516 git.sideband.band1.bytes=293354 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=87 git.pack.bytes=293354 git.pack.ofs_delta=0 git.pack.ref_delta=1 git.pack.chain.max=1 git.pack.trailer=6a646bcda6740bab42e321b51998b52ea15146c0 git.pack.full=86Open pack map
fetch2001.7 KiB · hit19 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=19 git.response.bytes=1741 git.response.cache=HIT git.response.duration_ms=19 git.fetch.wants=7bed39b8db24741975fc353e5d27b164d4982f2e git.fetch.haves.count=0 git.fetch.deepen=0 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=3 git.pkt.data=2 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=1741 git.pkt.payload.max=1720 git.sideband.band1.bytes=1719 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0
Each row is one HTTP round trip ply made to the git server for this page, on one timeline. discover asks what the server speaks, ls-refs lists branch tips, fetch brings objects by id. A hit was served by Workers Cache. Tap a row for its wire details.
- Remote
- https://5ad2236b39de4c8bd8f6270ea63f3ea9.artifacts.cloudflare.net/git/public-v0/curl.git
- Ref
- refs/heads/master
- Commit
- 31c911efe5652725e930f4d2e60c9060e5f6646d
- cf-ray
- a5e1a9a51f292c38
- Request
- 357b8682…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format