]> git.ipfire.org Git - thirdparty/squid.git/blob - scripts/find-alive.pl
Added debugging scripts that work with detailed cache.log
[thirdparty/squid.git] / scripts / find-alive.pl
1 #!/usr/bin/perl -w
2
3 # Reads cache.log from STDIN, preferrably with full debugging enabled.
4 # Finds creation and destruction messages for a given class.
5 # At the end, reports log lines that correspond to still-alive objects.
6 # Also reports the number of objects found (total and still-alive).
7 #
8 # Many classes have unique creation/destruction line patterns so we
9 # have to hard-code those patterns in the %Pairs table below. That
10 # table usually contains a few outdated entries.
11
12 use strict;
13 use warnings;
14
15 my $Thing = $ARGV[0] or die("usage: $0 <Thing-to-look-for>\n");
16
17 # When creation and destriction messages are standardizes, we
18 # will be able to support any class without this hard-coded table.
19 # We try to do that now (see "guessing ..." below), but it does
20 # not always work.
21 my %Pairs = (
22 AsyncCall => [
23 'AsyncCall.* constructed, this=(\S+)',
24 'AsyncCall.* destruct.*, this=(\S+)',
25 ],
26 HttpReq => [
27 '\bHttpRequest.* constructed, this=(\S+)',
28 '\bHttpRequest.* destructed, this=(\S+)',
29 ],
30 ClientSocketContext => [
31 '\bClientSocketContext constructing, this=(\S+)',
32 '\bClientSocketContext destructed, this=(\S+)',
33 ],
34 ICAP => [
35 '(?:ICAP|Icap).* constructed, this=(\S+)',
36 '(?:ICAP|Icap).* destruct.*, this=(\S+)',
37 ],
38 IcapModXact => [
39 'Adaptation::Icap::ModXact.* constructed, this=(\S+)',
40 'Adaptation::Icap::ModXact.* destruct.*, this=(\S+)',
41 ],
42 ICAPClientReqmodPrecache => [
43 'ICAPClientReqmodPrecache constructed, this=(\S+)',
44 'ICAPClientReqmodPrecache destruct.*, this=(\S+)',
45 ],
46 HttpStateData => [
47 'HttpStateData (\S+) created',
48 'HttpStateData (\S+) destroyed',
49 ],
50 cbdata => [
51 'HttpStateData (\S+) created',
52 'cbdataFree: Freeing (\S+)',
53 ],
54 );
55
56 if (!$Pairs{$Thing}) {
57 warn("guessing construction/destruction pattern for $Thing\n");
58 $Pairs{$Thing} = [
59 "\\b$Thing construct.*, this=(\\S+)",
60 "\\b$Thing destruct.*, this=(\\S+)",
61 ];
62 }
63
64 die("unsupported Thing, stopped") unless $Pairs{$Thing};
65
66 my $reConstructor = $Pairs{$Thing}->[0];
67 my $reDestructor = $Pairs{$Thing}->[1];
68
69 my %Alive = ();
70 my $Count = 0;
71 while (<STDIN>) {
72 if (/$reConstructor/) {
73 #die($_) if $Alive{$1};
74 $Alive{$1} = $_;
75 ++$Count;
76 }
77 elsif (/$reDestructor/) {
78 #warn("unborn: $_") unless $Alive{$1};
79 $Alive{$1} = undef();
80 }
81 }
82
83 printf(STDERR "Found %d %s\n", $Count, $Thing);
84
85 my $AliveCount = 0;
86 foreach my $alive (sort grep { defined($_) } values %Alive) {
87 next unless defined $alive;
88 printf("Alive: %s", $alive);
89 ++$AliveCount;
90 }
91
92 printf(STDERR "found %d still-alive %s\n", $AliveCount, $Thing);
93
94 exit(0);