]> git.ipfire.org Git - thirdparty/squid.git/blob - scripts/find-alive.pl
Merged from trunk
[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 'cbdataAlloc: (\S+)',
52 'cbdataFree: Freeing (\S+)',
53 ],
54 FD => [
55 'fd_open.*\sFD (\d+)',
56 'fd_close\s+FD (\d+)',
57 ],
58 );
59
60 if (!$Pairs{$Thing}) {
61 warn("guessing construction/destruction pattern for $Thing\n");
62 $Pairs{$Thing} = [
63 "\\b$Thing construct.*, this=(\\S+)",
64 "\\b$Thing destruct.*, this=(\\S+)",
65 ];
66 }
67
68 die("unsupported Thing, stopped") unless $Pairs{$Thing};
69
70 my $reConstructor = $Pairs{$Thing}->[0];
71 my $reDestructor = $Pairs{$Thing}->[1];
72
73 my %Alive = ();
74 my $Count = 0;
75 while (<STDIN>) {
76 if (/$reConstructor/) {
77 #die($_) if $Alive{$1};
78 $Alive{$1} = $_;
79 ++$Count;
80 }
81 elsif (/$reDestructor/) {
82 #warn("unborn: $_") unless $Alive{$1};
83 $Alive{$1} = undef();
84 }
85 }
86
87 printf(STDERR "Found %d %s\n", $Count, $Thing);
88
89 my $AliveCount = 0;
90 foreach my $alive (sort grep { defined($_) } values %Alive) {
91 next unless defined $alive;
92 printf("Alive: %s", $alive);
93 ++$AliveCount;
94 }
95
96 printf(STDERR "found %d still-alive %s\n", $AliveCount, $Thing);
97
98 exit(0);