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###########################################################################
25#
26# This script is aimed to help scan for and detect globally declared functions
27# that are not used from other source files.
28#
29# Use it like this:
30#
31# $ ./scripts/singleuse.pl [--unit] lib/.libs/libcurl.a
32#
33# --unit : built to support unit tests
34#
36use strict;
37use warnings;
39my @unittests;
40if(@ARGV && $ARGV[0] eq "--unit") {
41 push @unittests, 'tests/unit';
42 shift @ARGV;
43}
45my $file = $ARGV[0] || '';
47my %wl = (
48 'Curl_xfer_write_resp' => 'internal api',
49 'Curl_creader_def_init' => 'internal api',
50 'Curl_creader_def_close' => 'internal api',
51 'Curl_creader_def_read' => 'internal api',
52 'Curl_creader_def_total_length' => 'internal api',
53 'Curl_meta_reset' => 'internal api',
54 'Curl_thread_destroy' => 'internal api',
55 'Curl_trc_dns' => 'internal api',
56 'curlx_base64_decode' => 'internal api',
57 'curlx_base64_encode' => 'internal api',
58 'curlx_base64url_encode' => 'internal api',
59 'Curl_multi_clear_dirty' => 'internal api',
60);
62my %api = (
63 'curl_easy_cleanup' => 'API',
64 'curl_easy_duphandle' => 'API',
65 'curl_easy_escape' => 'API',
66 'curl_easy_getinfo' => 'API',
67 'curl_easy_init' => 'API',
68 'curl_easy_pause' => 'API',
69 'curl_easy_perform' => 'API',
70 'curl_easy_recv' => 'API',
71 'curl_easy_reset' => 'API',
72 'curl_easy_send' => 'API',
73 'curl_easy_setopt' => 'API',
74 'curl_easy_ssls_export' => 'API',
75 'curl_easy_ssls_import' => 'API',
76 'curl_easy_strerror' => 'API',
77 'curl_easy_unescape' => 'API',
78 'curl_easy_upkeep' => 'API',
79 'curl_easy_option_by_id' => 'API',
80 'curl_easy_option_by_name' => 'API',
81 'curl_easy_option_next' => 'API',
82 'curl_escape' => 'API',
83 'curl_formadd' => 'API',
84 'curl_formfree' => 'API',
85 'curl_formget' => 'API',
86 'curl_free' => 'API',
87 'curl_getdate' => 'API',
88 'curl_getenv' => 'API',
89 'curl_global_cleanup' => 'API',
90 'curl_global_init' => 'API',
91 'curl_global_init_mem' => 'API',
92 'curl_global_sslset' => 'API',
93 'curl_global_trace' => 'API',
94 'curl_maprintf' => 'API',
95 'curl_mfprintf' => 'API',
96 'curl_mime_addpart' => 'API',
97 'curl_mime_data' => 'API',
98 'curl_mime_data_cb' => 'API',
99 'curl_mime_encoder' => 'API',
100 'curl_mime_filedata' => 'API',
101 'curl_mime_filename' => 'API',
102 'curl_mime_free' => 'API',
103 'curl_mime_headers' => 'API',
104 'curl_mime_init' => 'API',
105 'curl_mime_name' => 'API',
106 'curl_mime_subparts' => 'API',
107 'curl_mime_type' => 'API',
108 'curl_mprintf' => 'API',
109 'curl_msnprintf' => 'API',
110 'curl_msprintf' => 'API',
111 'curl_multi_add_handle' => 'API',
112 'curl_multi_assign' => 'API',
113 'curl_multi_cleanup' => 'API',
114 'curl_multi_fdset' => 'API',
115 'curl_multi_get_handles' => 'API',
116 'curl_multi_get_offt' => 'API',
117 'curl_multi_info_read' => 'API',
118 'curl_multi_init' => 'API',
119 'curl_multi_notify_disable' => 'API',
120 'curl_multi_notify_enable' => 'API',
121 'curl_multi_perform' => 'API',
122 'curl_multi_remove_handle' => 'API',
123 'curl_multi_setopt' => 'API',
124 'curl_multi_socket' => 'API',
125 'curl_multi_socket_action' => 'API',
126 'curl_multi_socket_all' => 'API',
127 'curl_multi_poll' => 'API',
128 'curl_multi_strerror' => 'API',
129 'curl_multi_timeout' => 'API',
130 'curl_multi_wait' => 'API',
131 'curl_multi_waitfds' => 'API',
132 'curl_multi_wakeup' => 'API',
133 'curl_mvaprintf' => 'API',
134 'curl_mvfprintf' => 'API',
135 'curl_mvprintf' => 'API',
136 'curl_mvsnprintf' => 'API',
137 'curl_mvsprintf' => 'API',
138 'curl_pushheader_byname' => 'API',
139 'curl_pushheader_bynum' => 'API',
140 'curl_share_cleanup' => 'API',
141 'curl_share_init' => 'API',
142 'curl_share_setopt' => 'API',
143 'curl_share_strerror' => 'API',
144 'curl_slist_append' => 'API',
145 'curl_slist_free_all' => 'API',
146 'curl_strequal' => 'API',
147 'curl_strnequal' => 'API',
148 'curl_unescape' => 'API',
149 'curl_url' => 'API',
150 'curl_url_cleanup' => 'API',
151 'curl_url_dup' => 'API',
152 'curl_url_get' => 'API',
153 'curl_url_set' => 'API',
154 'curl_url_strerror' => 'API',
155 'curl_version' => 'API',
156 'curl_version_info' => 'API',
157 'curl_easy_header' => 'API',
158 'curl_easy_nextheader' => 'API',
159 'curl_ws_meta' => 'API',
160 'curl_ws_recv' => 'API',
161 'curl_ws_send' => 'API',
162 'curl_ws_start_frame' => 'API',
164 # the following functions are provided globally in debug builds
165 'curl_easy_perform_ev' => 'debug-build',
166 );
168sub doublecheck {
169 my ($f, $used) = @_;
170 open(F, '-|', 'git', 'grep', '-Fwl', '--end-of-options', $f, '--', 'lib', @unittests, 'projects');
171 my @also;
172 while(<F>) {
173 my $e = $_;
174 chomp $e;
175 if($e =~ /\.[c]$/) {
176 if($e !~ /^lib\/${used}\.c/) {
177 push @also, $e;
178 }
179 }
180 }
181 close(F);
182 return @also;
183}
185open(N, '-|', 'nm', $file) or die;
187my %exist;
188my %uses;
189my $anyinput = 0;
190while(<N>) {
191 my $l = $_;
192 chomp $l;
193 $anyinput = 1;
195 if($l =~ /^([0-9a-z_-]+)(\.c)?\.o:/) {
196 $file = $1;
197 }
198 # libcurl.a(unity_0_c.c.o):
199 elsif($l =~ /\(([0-9a-z_.-]+)(\.c)?\.o\):/) { # Apple nm
200 $file = $1;
201 }
202 if($l =~ /^([0-9a-f]+) T _?(.*)/) {
203 my ($name) = ($2);
204 #print "Define $name in $file\n";
205 $file =~ s/^libcurl_la-//;
206 $exist{$name} = $file;
207 }
208 elsif($l =~ /^ U _?(.*)/) {
209 my ($name) = ($1);
210 #print "Uses $name in $file\n";
211 $uses{$name} .= "$file, ";
212 }
213}
214close(N);
216if(!$anyinput) {
217 print STDERR "Bad command or input file missing: $file\n";
218 exit 1;
219}
221my $err = 0;
222for(sort keys %exist) {
223 #printf "%s is defined in %s, used by: %s\n", $_, $exist{$_}, $uses{$_};
224 if(!$uses{$_}) {
225 # this is a symbol with no "global" user
226 if($_ =~ /^curl_dbg_/) {
227 # we ignore the memdebug symbols
228 }
229 elsif($_ =~ /^curl_/) {
230 if(!$api{$_}) {
231 # not present in the API, or for debug-builds
232 print STDERR "Bad curl-prefix: $_\n";
233 $err++;
234 }
235 }
236 elsif($wl{$_}) {
237 #print "$_ is WL\n";
238 }
239 else {
240 my $c = $_;
241 my @also = doublecheck($c, $exist{$c});
242 if(!scalar(@also)) {
243 printf "%s in %s\n", $c, $exist{$c};
244 $err++;
245 }
246 # foreach my $a (@also) {
247 # print " $a\n";
248 # }
249 }
250 }
251 elsif($_ =~ /^curl_/) {
252 # global prefix, make sure it is "blessed"
253 if(!$api{$_}) {
254 # not present in the API, or for debug-builds
255 if($_ !~ /^curl_dbg_/) {
256 # ignore the memdebug symbols
257 print STDERR "Bad curl-prefix $_\n";
258 $err++;
259 }
260 }
261 }
262}
264exit $err;
Diagnostics4 git calls · 40 ms
CallStatusSizeTime040 ms
discover200152 B2 ms
git.upload-pack discover http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=2 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 · hit3 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=3 git.response.bytes=293470 git.response.cache=HIT git.response.duration_ms=3 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
fetch2002.4 KiB · hit34 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=34 git.response.bytes=2461 git.response.cache=HIT git.response.duration_ms=34 git.fetch.wants=253098f426e859fc24c138402e018ee1da5280e8 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=2461 git.pkt.payload.max=2440 git.sideband.band1.bytes=2439 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
- a5e13930b9fe18aa
- Request
- 2d803efa…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format