Artifactspublic-v0

curl

master
ply4 git calls415 ms290 KiB2 cachedprotocol v2
446 lines13 KiBRaw
1#!/usr/bin/env perl
2#***************************************************************************
3# _ _ ____ _
4# Project ___| | | | _ \| |
5# / __| | | | |_) | |
6# | (__| |_| | _ <| |___
7# \___|\___/|_| \_\_____|
8#
9# Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
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.
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.
19# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20# KIND, either express or implied.
22# SPDX-License-Identifier: curl
24###########################################################################
26# Example input:
28# MEM mprintf.c:1094 malloc(32) = e5718
29# MEM mprintf.c:1103 realloc(e5718, 64) = e6118
30# MEM sendf.c:232 free(f6520)
32package memanalyzer;
34use strict;
35use warnings;
37BEGIN {
38 use base qw(Exporter);
40 our @EXPORT = qw(
41 memanalyze
42 );
45my $memsum;
46my $maxmem;
48sub newtotal {
49 my ($newtot) = @_;
50 # count a max here
52 if($newtot > $maxmem) {
53 $maxmem = $newtot;
54 }
57sub memanalyze {
58 my ($file, $verbose, $trace, $showlimit) = @_;
59 my @res;
61 my $mallocs = 0;
62 my $callocs = 0;
63 my $reallocs = 0;
64 my $strdups = 0;
65 my $wcsdups = 0;
66 my $sockets = 0;
68 $memsum = 0; # the total number of memory allocated over the lifetime
69 $maxmem = 0; # the high water mark
71 open(my $fileh, "<", $file) or return ();
73 if($showlimit) {
74 while(<$fileh>) {
75 if(/^LIMIT.*memlimit$/) {
76 push @res, $_;
77 last;
78 }
79 }
80 close($fileh);
81 return @res;
82 }
84 my %sizeataddr;
85 my %getmem;
87 my $totalmem = 0;
88 my $frees = 0;
90 my $dup;
91 my $size;
92 my $addr;
94 my %filedes;
95 my %getfile;
97 my %fopen;
98 my %fopenfile;
99 my $openfile = 0;
100 my $fopens = 0;
102 my %addrinfo;
103 my %addrinfofile;
104 my $addrinfos = 0;
106 my $source;
107 my $linenum;
108 my $function;
110 my $lnum = 0;
112 while(<$fileh>) {
113 chomp $_;
114 my $line = $_;
115 $lnum++;
116 if($line =~ /^BT/) {
117 # back-trace, ignore
118 }
119 elsif($line =~ /^LIMIT ([^ ]*):(\d*) (.*)/) {
120 # new memory limit test prefix
121 my $i = $3;
122 my ($source, $linenum) = ($1, $2);
123 if($trace && ($i =~ /([^ ]*) reached memlimit/)) {
124 push @res, "LIMIT: $1 returned error at $source:$linenum\n";
125 }
126 }
127 elsif($line =~ /^MEM ([^ ]*):(\d*) (.*)/) {
128 # generic match for the filename+linenumber
129 $source = $1;
130 $linenum = $2;
131 $function = $3;
133 if($function =~ /free\((\(nil\)|0x([0-9a-f]*))/) {
134 $addr = $2;
135 if($1 eq "(nil)") {
136 ; # do nothing when free(NULL)
137 }
138 elsif(!exists $sizeataddr{$addr}) {
139 push @res, "FREE ERROR: No memory allocated: $line\n";
140 }
141 elsif($sizeataddr{$addr} == -1) {
142 push @res, "FREE ERROR: Memory freed twice: $line\n";
143 push @res, "FREE ERROR: Previously freed at: $getmem{$addr}\n";
144 }
145 else {
146 $totalmem -= $sizeataddr{$addr};
147 if($trace) {
148 push @res, "FREE: malloc at $getmem{$addr} is freed again at $source:$linenum\n";
149 push @res, "FREE: $sizeataddr{$addr} bytes freed, left allocated: $totalmem bytes\n";
150 }
152 newtotal($totalmem);
153 $frees++;
155 $sizeataddr{$addr} = -1; # set -1 to mark as freed
156 $getmem{$addr} = "$source:$linenum";
157 }
158 }
159 elsif($function =~ /malloc\((\d*)\) = 0x([0-9a-f]*)/) {
160 $size = $1;
161 $addr = $2;
163 if($sizeataddr{$addr} && $sizeataddr{$addr}>0) {
164 # this means weeeeeirdo
165 push @res, "Mixed debug compile ($source:$linenum at line $lnum), rebuild curl now\n";
166 push @res, "We think $sizeataddr{$addr} bytes are already allocated at that memory address: $addr!\n";
167 }
169 $sizeataddr{$addr} = $size;
170 $totalmem += $size;
171 $memsum += $size;
173 if($trace) {
174 push @res, "MALLOC: malloc($size) at $source:$linenum makes totally $totalmem bytes\n";
175 }
177 newtotal($totalmem);
178 $mallocs++;
180 $getmem{$addr} = "$source:$linenum";
181 }
182 elsif($function =~ /calloc\((\d*),(\d*)\) = 0x([0-9a-f]*)/) {
183 $size = $1 * $2;
184 $addr = $3;
186 my $arg1 = $1;
187 my $arg2 = $2;
189 if($sizeataddr{$addr} && $sizeataddr{$addr}>0) {
190 # this means weeeeeirdo
191 push @res, "Mixed debug compile ($source:$linenum at line $lnum), rebuild curl now\n";
192 push @res, "We think $sizeataddr{$addr} bytes are already allocated at that memory address: $addr!\n";
193 }
195 $sizeataddr{$addr} = $size;
196 $totalmem += $size;
197 $memsum += $size;
199 if($trace) {
200 push @res, "CALLOC: calloc($arg1,$arg2) at $source:$linenum makes totally $totalmem bytes\n";
201 }
203 newtotal($totalmem);
204 $callocs++;
206 $getmem{$addr} = "$source:$linenum";
207 }
208 elsif($function =~ /realloc\((\(nil\)|0x([0-9a-f]*)), (\d*)\) = 0x([0-9a-f]*)/) {
209 my ($oldaddr, $newsize, $newaddr) = ($2, $3, $4);
210 my $oldsize = '-';
212 if($oldaddr) {
213 $oldsize = $sizeataddr{$oldaddr} ? $sizeataddr{$oldaddr} : 0;
215 $totalmem -= $oldsize;
216 if($trace) {
217 }
218 $sizeataddr{$oldaddr} = 0;
220 $getmem{$oldaddr} = "";
221 }
223 $totalmem += $newsize;
224 $memsum += $newsize;
225 $sizeataddr{$newaddr} = $newsize;
227 if($trace) {
228 push @res, "REALLOC: $oldsize less bytes and $newsize more bytes ($source:$linenum)\n";
229 }
231 newtotal($totalmem);
232 $reallocs++;
234 $getmem{$newaddr} = "$source:$linenum";
235 }
236 elsif($function =~ /strdup\(0x([0-9a-f]*)\) \((\d*)\) = 0x([0-9a-f]*)/) {
237 # strdup(a5b50) (8) = df7c0
239 $dup = $1;
240 $size = $2;
241 $addr = $3;
242 $getmem{$addr} = "$source:$linenum";
243 $sizeataddr{$addr} = $size;
245 $totalmem += $size;
246 $memsum += $size;
248 if($trace) {
249 push @res, "STRDUP: $size bytes at $getmem{$addr}, makes totally: $totalmem bytes\n";
250 }
252 newtotal($totalmem);
253 $strdups++;
254 }
255 elsif($function =~ /wcsdup\(0x([0-9a-f]*)\) \((\d*)\) = 0x([0-9a-f]*)/) {
256 # wcsdup(a5b50) (8) = df7c0
258 $dup = $1;
259 $size = $2;
260 $addr = $3;
261 $getmem{$addr} = "$source:$linenum";
262 $sizeataddr{$addr} = $size;
264 $totalmem += $size;
265 $memsum += $size;
267 if($trace) {
268 push @res, "WCSDUP: $size bytes at $getmem{$addr}, makes totally: $totalmem bytes\n";
269 }
271 newtotal($totalmem);
272 $wcsdups++;
273 }
274 else {
275 push @res, "Not recognized input line: $function\n";
276 }
277 }
278 # FD url.c:1282 socket() = 5
279 elsif($_ =~ /^FD ([^ ]*):(\d*) (.*)/) {
280 # generic match for the filename+linenumber
281 $source = $1;
282 $linenum = $2;
283 $function = $3;
285 if($function =~ /socket\(\) = (\d*)/) {
286 $filedes{$1} = 1;
287 $getfile{$1} = "$source:$linenum";
288 $openfile++;
289 $sockets++; # number of socket() calls
290 }
291 elsif($function =~ /socketpair\(\) = (\d*) (\d*)/) {
292 $filedes{$1} = 1;
293 $getfile{$1} = "$source:$linenum";
294 $openfile++;
295 $filedes{$2} = 1;
296 $getfile{$2} = "$source:$linenum";
297 $openfile++;
298 }
299 elsif($function =~ /accept\(\) = (\d*)/) {
300 $filedes{$1} = 1;
301 $getfile{$1} = "$source:$linenum";
302 $openfile++;
303 }
304 elsif($function =~ /sclose\((\d*)\)/) {
305 if($filedes{$1} != 1) {
306 push @res, "Close without open: $line\n";
307 }
308 else {
309 $filedes{$1} = 0; # closed now
310 $openfile--;
311 }
312 }
313 }
314 # FILE url.c:1282 fopen("blabla") = 0x5ddd
315 elsif($_ =~ /^FILE ([^ ]*):(\d*) (.*)/) {
316 # generic match for the filename+linenumber
317 $source = $1;
318 $linenum = $2;
319 $function = $3;
321 if($function =~ /f[d]*open\(\"(.*)\",\"([^\"]*)\"\) = (\(nil\)|0x([0-9a-f]*))/) {
322 if($3 eq "(nil)") {
323 ;
324 }
325 else {
326 $fopen{$4} = 1;
327 $fopenfile{$4} = "$source:$linenum";
328 $fopens++;
329 }
330 }
331 # fclose(0x1026c8)
332 elsif($function =~ /fclose\(0x([0-9a-f]*)\)/) {
333 if(!$fopen{$1}) {
334 push @res, "fclose() without fopen(): $line\n";
335 }
336 else {
337 $fopen{$1} = 0;
338 $fopens--;
339 }
340 }
341 }
342 # GETNAME url.c:1901 getnameinfo()
343 elsif($_ =~ /^GETNAME ([^ ]*):(\d*) (.*)/) {
344 # not much to do
345 }
347 # ADDR url.c:1282 getaddrinfo() = 0x5ddd
348 elsif($_ =~ /^ADDR ([^ ]*):(\d*) (.*)/) {
349 # generic match for the filename+linenumber
350 $source = $1;
351 $linenum = $2;
352 $function = $3;
354 if($function =~ /getaddrinfo\(\) = (\(nil\)|0x([0-9a-f]*))/) {
355 my $add = $1;
356 if($add eq "(nil)") {
357 ;
358 }
359 else {
360 $addrinfo{$add} = 1;
361 $addrinfofile{$add} = "$source:$linenum";
362 $addrinfos++;
363 }
364 if($trace) {
365 push @res, "GETADDRINFO ($source:$linenum)\n";
366 }
367 }
368 # fclose(0x1026c8)
369 elsif($function =~ /freeaddrinfo\((0x[0-9a-f]*)\)/) {
370 my $addr = $1;
371 if(!$addrinfo{$addr}) {
372 push @res, "freeaddrinfo() without getaddrinfo(): $line\n";
373 }
374 else {
375 $addrinfo{$addr} = 0;
376 $addrinfos--;
377 }
378 if($trace) {
379 push @res, "FREEADDRINFO ($source:$linenum)\n";
380 }
381 }
382 }
383 else {
384 push @res, "Not recognized prefix line: $line\n";
385 }
386 }
387 close($fileh);
389 if($totalmem) {
390 push @res, "Leak detected: memory still allocated: $totalmem bytes\n";
392 for(keys %sizeataddr) {
393 $addr = $_;
394 $size = $sizeataddr{$addr};
395 if($size > 0) {
396 push @res, "At $addr, there is $size bytes.\n";
397 push @res, " allocated by $getmem{$addr}\n";
398 }
399 }
400 }
402 if($openfile) {
403 for(keys %filedes) {
404 if($filedes{$_} == 1) {
405 push @res, "Open file descriptor created at $getfile{$_}.\n";
406 }
407 }
408 }
410 if($fopens) {
411 push @res, "Open FILE handles left at:\n";
412 for(keys %fopen) {
413 if($fopen{$_} == 1) {
414 push @res, "fopen() called at $fopenfile{$_}.\n";
415 }
416 }
417 }
419 if($addrinfos) {
420 push @res, "IPv6-style name resolve data left at:\n";
421 for(keys %addrinfofile) {
422 if($addrinfo{$_} == 1) {
423 push @res, "getaddrinfo() called at $addrinfofile{$_}.\n";
424 }
425 }
426 }
428 if($verbose) {
429 push @res,
430 "Mallocs: $mallocs\n",
431 "Reallocs: $reallocs\n",
432 "Callocs: $callocs\n",
433 "Strdups: $strdups\n",
434 "Wcsdups: $wcsdups\n",
435 "Frees: $frees\n",
436 "Sockets: $sockets\n",
437 "Allocations: " . ($mallocs + $callocs + $reallocs + $strdups + $wcsdups) . "\n",
438 "Operations: " . ($mallocs + $callocs + $reallocs + $strdups + $wcsdups + $sockets) . "\n",
439 "Maximum allocated: $maxmem\n",
440 "Total allocated: $memsum\n";
441 }
443 return @res;
4461;
Diagnostics4 git calls · 415 ms
CallStatusSizeTime0415 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 · hit2 ms
git.upload-pack ls-refs
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=2
git.response.bytes=149
git.response.cache=HIT
git.response.duration_ms=2
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 · hit2 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=2
git.response.bytes=293470
git.response.cache=HIT
git.response.duration_ms=2
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=86
Open pack map
fetch2003.3 KiB411 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=411
git.response.bytes=3364
git.response.cache=MISS
git.response.duration_ms=411
git.fetch.wants=925a2c6b0a9500558f2bf626d5b60a81f7feb238
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=3364
git.pkt.payload.max=3343
git.sideband.band1.bytes=3342
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
a5e1c36f986436cd
Request
bb01795a…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format