]> git.ipfire.org Git - thirdparty/squid.git/blob - scripts/find-alive.pl
Initial Large Rock and Collapsed Forwarding support.
[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 HttpHeaderEntry => [
27 '\bHttpHeaderEntry.* created HttpHeaderEntry (\S+)',
28 '\bHttpHeaderEntry.* destroying entry (\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 'cbdataAlloc: (\S+)',
52 '(?:cbdataFree|cbdataUnlock): Freeing (\S+)',
53 ],
54 FD => [
55 'fd_open.*\sFD (\d+)',
56 'fd_close\s+FD (\d+)',
57 ],
58 IpcStoreMapEntry => [
59 'StoreMap.* opened .*entry (\d+) for \S+ (\S+)',
60 'StoreMap.* closed .*entry (\d+) for \S+ (\S+)',
61 ],
62 sh_page => [
63 'PageStack.* pop: (sh_page\S+) at',
64 'PageStack.* push: (sh_page\S+) at',
65 ],
66 );
67
68 if (!$Pairs{$Thing}) {
69 warn("guessing construction/destruction pattern for $Thing\n");
70 $Pairs{$Thing} = [
71 "\\b$Thing construct.*, this=(\\S+)",
72 "\\b$Thing destruct.*, this=(\\S+)",
73 ];
74 }
75
76 die("unsupported Thing, stopped") unless $Pairs{$Thing};
77
78 my $reConstructor = $Pairs{$Thing}->[0];
79 my $reDestructor = $Pairs{$Thing}->[1];
80
81 my %AliveCount = ();
82 my %AliveImage = ();
83 my $Count = 0;
84 while (<STDIN>) {
85 if (my @conIds = (/$reConstructor/)) {
86 my $id = join(':', @conIds);
87 #die($_) if $Alive{$id};
88 $AliveImage{$id} = $_;
89 ++$Count unless $AliveCount{$id}++;
90 }
91 elsif (my @deIds = (/$reDestructor/)) {
92 my $id = join(':', @deIds);
93 #warn("unborn: $_") unless $AliveCount{$id};
94 $AliveImage{$id} = undef() unless --$AliveCount{$id};
95 }
96 }
97
98 printf(STDERR "Found %d %s\n", $Count, $Thing);
99
100 my $aliveCount = 0;
101 foreach my $alive (sort grep { defined($_) } values %AliveImage) {
102 next unless defined $alive;
103 printf("Alive: %s", $alive);
104 ++$aliveCount;
105 }
106
107 printf(STDERR "found %d still-alive %s\n", $aliveCount, $Thing);
108
109 exit(0);