]>
git.ipfire.org Git - thirdparty/squid.git/blob - scripts/trace-master.pl
3 ## Copyright (C) 1996-2023 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/;
74 my $job = &getJob
($id);
80 my $job = &getJob
($id);
81 $job->{history
} .= $line;
83 if ($line =~ /\bFD (\d+)/) {
84 $job->{fds
}->{$1} = 1;
89 my ($parentId, $kidId, $line) = @_;
91 my $parent = $Jobs{$parentId} or die("missing linked job $parentId");
92 push @
{$parent->{kids
}}, $kidId;
94 my $kid = &getJob
($kidId);
95 die("two parents for $kidId: ". $kid->{parent
}. " and $parentId") if $kid->{parent
};
96 $kid->{parent
} = $parentId;
98 $kid->{history
} .= $line; # birth
104 my $job = $Jobs{$id};
123 my ($id, $recursive) = @_;
125 my $job = $Jobs{$id} or die("Did not see job$id\n");
127 # several kids may try to report their common parent
128 return if $job->{reported
};
129 $job->{reported
} = 1;
131 &reportJob
($job->{parent
}, 0) if $job->{parent
};
133 &reportJobParam
($id, 'parent');
134 &reportJobParam
($id, 'kids', join(', ', @
{$job->{kids
}}));
135 &reportJobParam
($id, 'FDs', join(', ', keys %{$job->{fds
}}));
136 &reportJobHistory
($id);
138 return unless $recursive;
140 foreach my $kidId (@
{$job->{kids
}}) {
141 &reportJob
($kidId, $recursive);
146 my ($id, $name, $value) = @_;
147 my $job = $Jobs{$id} or die;
149 $value = $job->{$name} if @_ < 3;
150 $value = '?' unless defined $value;
151 $value = "\n$value" if $value =~ /\n/m;
152 printf("job%d %s: %s\n", $id, $name, $value);
155 sub reportJobHistory
{
157 my $job = $Jobs{$id} or die;
159 my $history = $job->{history
};
160 my @lines = split(/\n/, $history);
161 &reportJobParam
($id, 'history', (scalar @lines) . " entries");
163 foreach my $line (@lines) {
165 print "\n" if $line =~ /[|:] leaving\b/;