]>
git.ipfire.org Git - thirdparty/squid.git/blob - scripts/trace-master.pl
3f754bcbd4d6ecd4a08e27dfdfa89737b3686f2a
3 ## Copyright (C) 1996-2014 The Squid Software Foundation and contributors
5 ## Squid software is distributed under GPLv2+ license and includes
6 ## contributions from numerous individuals and organizations.
7 ## Please see the COPYING and CONTRIBUTORS files for details.
10 # Reads cache.log and displays lines that correspond to the master transaction
11 # that has a given async job. Master transaction is all activities tied to a
12 # a single received HTTP request (client side, ACL, ICAP, server side, etc.).
14 # See trace-job.pl for tracing a single job instead of all jobs related to
15 # a master transaction.
17 # Currently, many master transaction activities are not tracked because they
18 # do not use AsyncJob API. Eventually, most activities should be identifiable.
20 # Currently, the script reads and remembers all master transactions because it
21 # does not know which one should be tracked in advance. Eventually, we may
22 # have a more efficient way of tying master transaction to a job.
29 my @InterestingJobs = @ARGV or die("usage: $0 <job id> ...\n");
37 $entering = $_ if !$inside && /[|:] entering\b/;
38 undef $entering if /[|:] leaving\b/;
40 if (!$inside && /\bstatus in\b.*\b(?:async|job|icapx)(\d+)\b/o) {
43 &updateJob
($inside, $entering) if defined $entering;
46 elsif (!$inside && /\b(?:async|job|icapx)(\d+)\b/o) {
47 updateJob
($1, "$_\n"); # isolated line
52 &updateJob
($inside, $_);
54 if (/AsyncJob constructed.*\[\S+?(\d+)\]/) {
55 &linkJobs
($inside, $1, $_);
58 if (/[|:] leaving\b/) {
63 foreach my $id (@InterestingJobs) {
64 # Squid uses asyncNNN, jobNNN, icapxNNN for the same job/transaction
65 $id =~ s/^(?:async|job|icapx)(\d+)$/$1/;
75 my $job = &getJob
($id);
81 my $job = &getJob
($id);
82 $job->{history
} .= $line;
84 if ($line =~ /\bFD (\d+)/) {
85 $job->{fds
}->{$1} = 1;
90 my ($parentId, $kidId, $line) = @_;
92 my $parent = $Jobs{$parentId} or die("missing linked job $parentId");
93 push @
{$parent->{kids
}}, $kidId;
95 my $kid = &getJob
($kidId);
96 die("two parents for $kidId: ". $kid->{parent
}. " and $parentId") if $kid->{parent
};
97 $kid->{parent
} = $parentId;
99 $kid->{history
} .= $line; # birth
105 my $job = $Jobs{$id};
126 my ($id, $recursive) = @_;
128 my $job = $Jobs{$id} or die("Did not see job$id\n");
130 # several kids may try to report their common parent
131 return if $job->{reported
};
132 $job->{reported
} = 1;
134 &reportJob
($job->{parent
}, 0) if $job->{parent
};
136 &reportJobParam
($id, 'parent');
137 &reportJobParam
($id, 'kids', join(', ', @
{$job->{kids
}}));
138 &reportJobParam
($id, 'FDs', join(', ', keys %{$job->{fds
}}));
139 &reportJobHistory
($id);
141 return unless $recursive;
143 foreach my $kidId (@
{$job->{kids
}}) {
144 &reportJob
($kidId, $recursive);
149 my ($id, $name, $value) = @_;
150 my $job = $Jobs{$id} or die;
152 $value = $job->{$name} if @_ < 3;
153 $value = '?' unless defined $value;
154 $value = "\n$value" if $value =~ /\n/m;
155 printf("job%d %s: %s\n", $id, $name, $value);
158 sub reportJobHistory
{
160 my $job = $Jobs{$id} or die;
162 my $history = $job->{history
};
163 my @lines = split(/\n/, $history);
164 &reportJobParam
($id, 'history', (scalar @lines) . " entries");
166 foreach my $line (@lines) {
168 print "\n" if $line =~ /[|:] leaving\b/;